- #1
24forChromium
- 155
- 7
Behold this array of numbers:
3, 5, 11, 4
Sometimes, the programming limits the number of things that can be recorded in one location to a single number, such as 93240, but sometimes I also need to record an array of numbers such as the one shown above. An example of such platforms include the ti-84 calculator.
You may already know how to do this, but here is how I did it (with limited success) in case you are interested:
-----------------------------------------------------------------------------------------
I got around storing a combination of any number of numbers by using this trick:
1. raise 2 to the power of the input number
2. assign the exponentiation's output to k
3. raise 2 to the power of the second input
4. add the second power to k and reassign
5. rinse and repeat until the user stops inputting numbers, now we have a number k.
The example shown above would turn into:
8+32+2048+16=2104
when we are trying to get the stuff the user put in there, we just need to find the biggest power of 2 in k:
1. biggest power in k is 2048 (=2^11)
2. subtract this power from k and reassign:
k-2048 = 56 sto>k
3. look for the next biggest power in k:
biggest power in k is 32 (=2^5)
so on and so forth until k goes to 0.
By now we have all of the initial inputs extracted from k. The problem with this method include:
-Combination (not permutation) of positive whole numbers only
-input must not repeat
--------------------------------------------------------------------------------------------
Now, would there be a way to do something similar (storing an array of numbers in one number) and include the order of the array and allow repetition, and maybe allow non-whole numbers?
3, 5, 11, 4
Sometimes, the programming limits the number of things that can be recorded in one location to a single number, such as 93240, but sometimes I also need to record an array of numbers such as the one shown above. An example of such platforms include the ti-84 calculator.
You may already know how to do this, but here is how I did it (with limited success) in case you are interested:
-----------------------------------------------------------------------------------------
I got around storing a combination of any number of numbers by using this trick:
1. raise 2 to the power of the input number
2. assign the exponentiation's output to k
3. raise 2 to the power of the second input
4. add the second power to k and reassign
5. rinse and repeat until the user stops inputting numbers, now we have a number k.
The example shown above would turn into:
8+32+2048+16=2104
when we are trying to get the stuff the user put in there, we just need to find the biggest power of 2 in k:
1. biggest power in k is 2048 (=2^11)
2. subtract this power from k and reassign:
k-2048 = 56 sto>k
3. look for the next biggest power in k:
biggest power in k is 32 (=2^5)
so on and so forth until k goes to 0.
By now we have all of the initial inputs extracted from k. The problem with this method include:
-Combination (not permutation) of positive whole numbers only
-input must not repeat
--------------------------------------------------------------------------------------------
Now, would there be a way to do something similar (storing an array of numbers in one number) and include the order of the array and allow repetition, and maybe allow non-whole numbers?