Consider the digits of any integral base above one, listed in order. Subdivide them exactly in half repeatedly until every chunk of digits has odd length:
Base Digits Subdivided Digit Chunks
2 01 0 1
3 012 012
4 0123 0 1 2 3
5 01234 01234
6 012345 012 345
7 0123456 0123456
8 01234567 0 1 2 3 4 5 6 7
9 012345678 012345678
10 0123456789 01234 56789
11 0123456789A 0123456789A
12 0123456789AB 012 345 678 9AB
...
16 0123456789ABCDEF 0 1 2 3 4 5 6 7 8 9 A B C D E F
...
Now, for any row in this table, read the subdivided digit chunks as numbers in that row's base, and sum them. Give the result in base 10 for convenience.
For example...
- for base 3 there is only one number to sum: 0123 = 123 = 510
- for base 4 there are 4 numbers to sum: 04 + 14 + 24 + 34 = 124 = 610
- base 6: 0126 + 3456 = 4016 = 14510
- base 11: 0123456789A11 = 285311670510
Challenge
Write a program that takes in an integer greater than one as a base and performs this subdivide sum procedure, outputting the final sum in base 10. (So if the input is 3
the output is 5
, if the input is 6
the output is 145
, etc.)
Either write a function that takes and returns an integer (or string since the numbers can get pretty big) or use stdin/stdout to input and output the values.
The shortest code in bytes wins.
Notes
- You may use any built in or imported base conversion functions.
- There is no upper limit to the input value (besides a reasonable
Int.Max
). The input values don't stop at 36 just because "Z" stops there.
p.s. this is my fiftieth question :)