# The Professor's base building number converter

The nutty maths professor wants to encode all of their research using a system sure to fox even the wiliest of their competitors!

To this end the professor has decided to change the base of not just the number that they're writing but every single digit in that number, according to which place the digit finds itself in (counting from the right, starting with 1). For example:

The number 0 has one digit, so it is represented in base 1: 0

The number 1 would have one digit in base ten, but in our professor's system that isn't valid. The first place is reserved for base 1 digits only! This means it must be bumped to the second place where base 2 is allowed: 10

The number 2 requires at least base 3 to be written: 100

But now the number 3 can be written by changing the digit in the second place: 110

and 4 as so: 200

5:210

6:1000

7:1010

8:1100

9:1110

10:1200

11:1210

12:2000

13:2010

14:2100

15:2110

16:2200

17:2210

18:3000

Using this system the professor's notes will make no sense to anyone but them, and they can finally take over the world!!!! sleep well at night.

Of course the encoding method must be as obscure as possible.

Your task is to write 10 code snippets, each representing one of the base 10 digits

0 1 2 3 4 5 6 7 8 9

which when combined in the order of the number to be converted will produce a number written in the professor's diabolical numbering system (the output method may be of your choice but must be a human readable number using only the digits 0-9)

For example if my snippets are:

0=MONKEY 1=EXAMPLE, 2=CODE, 3=GOLF and 9=TEST

then

19 = EXAMPLETEST -> 3010

20 = CODEMONKEY -> 3100

21 = CODEEXAMPLE -> 3110

22 = CODECODE -> 3200

23 = CODEGOLF -> 3210

No input numbers with more than 10 digits or negative numbers need to be considered, though if you want to write the code for additional digits you will get extra kudos. This is code golf, so shortest answer (using the combined byte totals of all snippets) wins and the standard loopholes aren't allowed.

ADDENDUM: Before anyone gets started on whether 0 is the correct representation of 0 in base 1 I would like to remind you that this professor is nutty. Live with it.

• Note: The professor's system is also known as the factorial number system. Dec 21, 2016 at 14:57
• It's also OEIS A124252 Dec 21, 2016 at 15:02
• @ETHproductions I never said the Professor's encoding was good. Dec 21, 2016 at 15:06
• @KritixiLithos Thank you for that! I was looking for that to use as confirmation. Dec 21, 2016 at 15:07
• Welcome to PPCG, by the way :-) Dec 21, 2016 at 15:10

# Mathematica (REPL environment), 858 total bytes

Here is the 86-byte code snippet for the digit 9:

1;ValueQ@a||(a=0;b=3);a=10a+9;b++;FromDigits[a~IntegerDigits~MixedRadix@Range[b,1,-1]]


The code snippets for the digits 1 through 8 are identical, except that the 9 is replaced by the appropriate digit. The code snippet for the digit 0 is identical, except that +9 is simply deleted.

a~IntegerDigits~MixedRadix@Range[b,1,-1] computes the list of the factorial-number-system digits of a, as long as b is at least as large as the number of digits; FromDigits converts that list of digits to a regular base-10 integer for the purposes of output. (If any of the list elements exceeds 9, something funny happens.)

In Mathematica's REPL environment, computations can be terminated with semicolons to suppress the output; so only the last output in a semicolon-separated chain will be displayed. We recursively define the integer a designated by the snippets, and also a bound b on the number of factorial-system digits needed. The command ValueQ@a||(a=0;b=3) initializes these variables if they're uninitialized (i.e., in the first snippet) and leaves them alone otherwise; then a=10a+9;b++ carries out the recursion. Finally, the initial 1; is for gluing the snippets together: it multiplies intermediate computations by 1 (which we never see anyway).

• I enjoy the semicolon abuse. Feb 12, 2017 at 21:21

# Goruby, 790 810980

Here's a second attempt, relying on the fact that, in basically any shell, printing a carriage return ("\r") without a newline ("\n") will overwrite the previously printed line, ultimately ensuring that only the last bit printed (that is, the final result) is shown.

This must be run in a shell, e.g. ruby name_of_file.rb.

It works for positive numbers of unrestricted length.

The code is ten copies of the snippet below, with X (at the top) replaced with the digits from 0-9, one per snippet.

->*t{n,d,o="X#{t}".toi,0,''
dw{n,r=n.dm d+=1;o.pr r.ts;n>0}
$>.fu pr"\r",o o}  That is, the snippet representing (for example) 8 would look like: ->*t{n,d,o="8#{t}".toi,0,'' dw{n,r=n.dm d+=1;o.pr r.ts;n>0}$>.fu
pr"\r",o
o}


The challenge states that the snippets need to be "combined" to create represent a multiple-digit number, so, to append a digit to a number, simply place it in the square brackets at the number's end. Thus, the number 103 (in decimal) would be:

->*t{n,d,o="1#{t}".toi,0,''
dw{n,r=n.dm d+=1;o.pr r.ts;n>0}
$>.fu pr"\r",o o}[->*t{n,d,o="0#{t}".toi,0,'' dw{n,r=n.dm d+=1;o.pr r.ts;n>0}$>.fu
pr"\r",o
o}[->*t{n,d,o="8#{t}".toi,0,''
dw{n,r=n.dm d+=1;o.pr r.ts;n>0}
\$>.fu
pr"\r",o
o}[]]]

• You mean the number 108. Jan 3, 2018 at 18:07