Sunday, 18 August 2013

word problem - Half and Double Value


A 3 year old child tried to input or copy a number (written on the paper) to a calculator but he messed up with the digit places. All the digits are there but the value of the number he inputed becomes double. He tried to redo it. Unfortunately the digits are not on the right places again. But this time the value of the number he input is only half of the number he is trying to copy. When he grew older and learned about that early numeral experience the child wondered and asked: What is the smallest positive integer N where its value becomes half or double when its digits are rearranged?



Answer




285714­­­­­­­­­­­­­­­­­­­­­­­­




I used the following k program to compute it:


2*{~1=#?{x@


{...}(1+)/1 means start from 1 and increment (1+) while the condition in curly braces is true


1 2 4*x is a list of 1, 2, and 4 times the current value


$ convert to string


{x@ sort each


? unique


# count


1= equal to 1


~ not



2* multiply by 2


No comments:

Post a Comment

Understanding Stagnation point in pitot fluid

What is stagnation point in fluid mechanics. At the open end of the pitot tube the velocity of the fluid becomes zero.But that should result...