This first one is easy (in my opinion).
What to accomplish:
You must be able to join a 3 char number into a 5 char number
And later be able to retrieve this 3 char number from the 5 one with OUT knowing how big the 3 char number is (that is the point of the entire challenge).
Rules:
You can't use string operations
You can't make the 5 char number bigger than 5 chars
You can't use floats (as final output)
You can't use longs (as final output)
As for a starting point:
The big number is as big as a word goes
The small number is as big as a byte goes
The numbers (both) would be random and your "algorithm" should return the correct numbers after processed. Its easy obviously if you use 2 fixed numbers.. However the point of the challenge is to make an algo that works with any number within the said limits.
So, in process number 1 we join our small number which let's say is 240 to let's say 43200. We get 43440 as an obvious output if we just add the 240 to the big number..
Now on process number 2 you should be able to take the small number out of the big one with OUT knowing the small number. thats the point.
You can't make the 5 char number bigger than it is, so this for example is not a good idea:
Code: Select all
num = 32767 ; original number
Debug num
shifted = (num << 8) | 235 ; the small number to add
Debug shifted
thenum = shifted & $FF ; shifted with the number
Debug thenum
retrieved = (shifted >> 8) ; we get the original number now
Debug retrievedAnother stupid useless method you shouldnt try:
sqrt(65280 +256 )
obviously it WILL return 256 (the small number you first put), but sure you shouldnt forget that both numbers would be random and the output should be the correct, so SQRT busted I'm afraid
Curious note:
4 programmers tried this with out any good results, they all failed
And 1 provided a string solution (hence I had to add that you cant perform string operations to accomplish this)
I will let this challenge run for long, if no one could accomplish it, I might post a solution. I have other challenges as well, however they are harder so let's start with something easy!.
Notice: You CAN add the number as you want and retrieve it as you want as well, there are no rules for this. The only rules were stated above.
The resulting codes will be benchmarked later to see not only if it does the job but also which one is the fastest method!.
I would say that Arithmetic and Bitwise operations are a must-know for this little challenge.
Whos up to the task?, I could send you a beer as price
Please post your questions, don't start if you didnt get one of the points yet (I don't want you to waste your time, that's why).
Have fun!!


