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

Printable View

- 06-29-2002fero45Not decimal
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 - 06-29-2002Hunter2
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 :D - 06-29-2002Dual-Catfish
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 :)

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));

}

- 06-29-2002Boksha
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 ;) )