The Professor's base building number converter

12

1

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:

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.

Joe Bloggs

Posted 2016-12-21T14:51:00.777

Reputation: 221

1

Note: The professor's system is also known as the factorial number system.

– ETHproductions – 2016-12-21T14:57:46.853

It's also OEIS A124252

– user41805 – 2016-12-21T15:02:52.887

@ETHproductions I never said the Professor's encoding was good. – Joe Bloggs – 2016-12-21T15:06:32.350

@KritixiLithos Thank you for that! I was looking for that to use as confirmation. – Joe Bloggs – 2016-12-21T15:07:41.973

4Welcome to PPCG, by the way :-) – ETHproductions – 2016-12-21T15:10:28.603

@ETHproductions: Thanks. I must confess to being a long time lurker... – Joe Bloggs – 2016-12-21T15:12:26.750

You state: "Your task is to write 10 code snippets, each representing one of the base 10 digits". Later, it seems that you want a conversion of a decimal number into a factorial base system. Do you want "snippets" in English, or simply the conversion? – DavidC – 2016-12-21T16:00:32.587

@DavidC: The code snippets are combined in order to act as the input to be converted, as shown in the example. There is already a factorial conversion challenge, but this is mostly about the novel input format. – Joe Bloggs – 2016-12-21T16:02:27.543

Is including code outside of the snippets permitted as well? Or does all code used have to be in a snippet? – Tutleman – 2017-01-30T20:42:32.110

@Turtleman: All code should be in the snippet. – Joe Bloggs – 2017-01-30T20:44:50.237

There is a lot of gender bias in mathematics. Assuming that a maths professor is male (as you do in the first sentence) not only is a symptom of our implicit bias, but also reinforces that harmful bias. I encourage you not to assign genders to hypothetical STEM people. – Greg Martin – 2017-02-12T19:02:04.833

What do you want the output to be if the snippets indicate the number 36288000, which is 10 times 10! and thus has a two-digit "digit"? – Greg Martin – 2017-02-12T19:28:13.880

@GregMartin: Feel free to edit to a gender neutral or fluid pronoun if you really want to. I was just going to assign the gender of the next hypothetical professor based on a coin flip. – Joe Bloggs – 2017-02-12T21:00:42.150

0 is the correct representation of 0 in base 1, if you don't use 0s in unary. And the 0 is empty so yes. – user75200 – 2018-01-03T18:08:01.333

Answers

1

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

Greg Martin

Posted 2016-12-21T14:51:00.777

Reputation: 13 940

I enjoy the semicolon abuse. – Joe Bloggs – 2017-02-12T21:21:27.970

0

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.

->*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}[]]]

Tutleman

Posted 2016-12-21T14:51:00.777

Reputation: 571

You mean the number 108. – user75200 – 2018-01-03T18:07:26.700