Hello!
Can I work with less numbers than ten? For example 5 numbers (2, 4, 6, 7, 8) where the lowest five-digit number, using all the selected numbers, would be 24678. If I increased this number, then the next value would be 24682.
Thanks
Fero
Hello!
Can I work with less numbers than ten? For example 5 numbers (2, 4, 6, 7, 8) where the lowest five-digit number, using all the selected numbers, would be 24678. If I increased this number, then the next value would be 24682.
Thanks
Fero
try using an array:
int numbers[6] = {0, 2, 4, 6, 7, 8};
then instead of working with the actual values (2,4,6,7,8), use normal numbers but in base 5 - and then when you have the answer (e.g. 2314 in base 5), just use each digit as an index in the array. so:
2314
=
numbers[2]numbers[3]numbers[1]numbers[4]
=
4628
Now you just have to figure out how to do math in base 5
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
I'm having trouble understanding what you're asking.. but I guess I can give it a shot. If this is nothing like what you wanted, please ignore me
I didn't test this... but it should give you a long representation of 24678;Code:int numbers[] = { 2, 4, 6, 7, 8}; long sum = 0; for (int i = 0; i < 6; i++) { sum += (numbers[4 - i] * pow(10, i)); }
Last edited by Dual-Catfish; 06-29-2002 at 04:15 PM.
Ugh... That's one helluva problem.
It isn't hard to work with different radixes, but it can be horribly slow.
One thing you could try is to check after every addition whether any of your digits is above 8, then add one to the next and substract 5 from the original, like this:
24678
20234
--------+
447AC
Then, C is more than 8. So, you substract 5, so you get 7, and add one to A, making it B. B is higher than 8, so substract 5 and get 6, add one to 7 making it 8, which is alright. No other number get above 8. The final number is 44878. However, if you have to do all that for every number, stuff gets slow very fast. (I did that once with a radix of 100 to get very large numbers. The result... Ugh. It did get Pi in 13 decimals though )
Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.