26
3
I noticed a certain game had a peculiar life counter, which instead of stopping at 999
, gained a new digit – the next number was crown hundred or 00
. After 99
came crown hundred crownty (0
) and the last number, after 9
, was crown hundred crownty crown or , which would be 1110 in decimal.
Your task is to write a program or a function that outputs this counter.
Given an integer from the range [0,1110]
(inclusive on both ends), output a three character string where
- every character is from the list
0123456789
- the crown () can only appear as the leftmost character or when there's a crown to the left of it
- when this number is read as a decimal number but with the crown counting as
10
, you get back the original number
Test cases
0 → "000"
15 → "015"
179 → "179"
999 → "999"
1000 → "00"
1097 → "97"
1100 → "0"
1108 → "8"
1110 → ""
You may use any non-decimal character instead of the crown. To encourage pretty printing, the crown character (UTF8 byte sequence "\240\159\145\145") counts as one byte instead of four. Your program doesn't have to work for numbers outside the valid range.
This is code-golf, so the shortest answer, measured in bytes, wins!
4Oh, Super Mario 3D Land! – Deusovi – 2018-09-08T09:38:20.577
2@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed! – Angs – 2018-09-08T10:00:32.820
3This should be the IMO number for Boaty McBoatFace. – Mr Lister – 2018-09-08T11:19:21.530
The bonus is multiplied by the number of crowns in the code, right? – Erik the Outgolfer – 2018-09-08T14:13:03.080
@EriktheOutgolfer As I understand it, if the output contains the crown, you may subtract 3 from the byte count. – Mr. Xcoder – 2018-09-08T15:34:56.467
@Mr.Xcoder I mean, a crown is 4 bytes, so, if the bonus is only applied once, but you need to use many crowns, you need to use a variable (if that's possible). – Erik the Outgolfer – 2018-09-08T15:36:10.027
@EriktheOutgolfer I changed the wording so the crown counts as one byte, no matter how many there are. – Angs – 2018-09-08T15:39:24.870
The "numbering" system here appears to be internally inconsistent - why is 999 followed by C00 (C is the crown), but C99 is followed by CC0, but 99 is not followed by C0, but… this looks like it's trying to look like base 11, with the crown being the ten-value digit. – Jeff Zeitlin – 2018-09-08T19:42:18.813
3@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed. – Angs – 2018-09-08T20:32:26.203
@JeffZeitlin It's a reference to SMB. That would make a more complex version of this challenge...
– Bob – 2018-09-10T04:41:24.063