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

Here are some more examples to help you get the idea:















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:



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.

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

Mathematica (REPL environment), 858 total bytes

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


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

  • \$\begingroup\$ I enjoy the semicolon abuse. \$\endgroup\$ – Joe Bloggs Feb 12 '17 at 21:21

Goruby, 790 810 980

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.

dw{n,r=n.dm d+=1;o.pr r.ts;n>0}

That is, the snippet representing (for example) 8 would look like:


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:

  • \$\begingroup\$ You mean the number 108. \$\endgroup\$ – user75200 Jan 3 '18 at 18:07

Your Answer

