SimpleTemplate 0.84, 76 bytes
Yeah, it is ... big ...
One of the longest answers here, but it works!
It uses a simple lookup variable, to know which digit to show.
Then, a simple regular expression separates the first digit and the rest.
A loop just writes out all the zeroes needed.
{@setX"1122255555"}{@ifargv.0 matches"@(\d)(.*)@"M}{@echoX.[M.1]}{@eachM.2}0
Notice that the input can be a number or a string: it will be handled as a string anyway. But be aware of PHP's integer precision.
Ungolfed:
To make it a bit more readable, here's an ungolfed version:
{@set initial_digit 1, 1, 2, 2, 2, 5, 5, 5, 5, 5}
{@if argv.0 matches "@(\d)(.*)@" match}
{@echo initial_digit.[match.1]}
{@each match.2 as digit}
{@echo 0}
{@/}
{@/}
Consideration points:
initial_digit
can be a string or an array, as both can have their elements indexed the same way.
match.0
isn't used because it has the whole matched input, while match.1
and match.2
have the content of their respective groups.
{@echo 0}
and 0
have the exact same function: output 0
.
Any non-whitespace and all characters that arent in a valid instructions are outputted directly.
{@each match.2 as digit}
and {@eachM.2}
loop over all characters in match.2
or M.2
, being a lot shorter than a repeat
.
- To convert to a function, just wrap it in an
{@fn ...}[...]{@/}
.
For the golfed version, all missing {@/}
must be added for the code to work properly.
You can try this on: http://sandbox.onlinephpfunctions.com/code/a45b85003e2d495c796046b000326fb1b5e50423
10^19
It looks like you're assuming the languages support 64-bit unsigned integers or higher, given that2^63 < 10^19 < 2^64
. It has the effect of unnecessarily penalizing languages that do not natively support such large integers. Note that, on this site, we usually allow solutions to use whatever native number type is available to the language of choice, as long as it does not fall into the category of abuse. \$\endgroup\$