# Introduction

Every number can be represented as ASCII. For example, $$\0\$$ comes in ASCII is $$\48\$$, $$\1\$$ is $$\49\$$, and so on. Using this method of translating numbers to other numbers, it is possible to infinitely expand a number, by replacing all its digits with their ASCII values and doing the same for the result. For example, if you started with $$\0\$$, you would expand to $$\48\$$, then to $$\5256\$$, and so on.

# Challenge

• You will be given a single digit and a number as input. You can assume the digit will be in the range $$\0-9\$$, or $$\48-57\$$ in ASCII. You can assume the digit will always be of length 1, and will be a string. The number will always be a positive integer, greater than -1. If it is 0, you do not expand at all. Other than that, there are no guarantees about its value. If, and only if your language has no method of input, you may store the input in two variables or in a list.
• You must output the ASCII expansion of the digit if you expand it $$\n\$$ times, n being the number that was the input. If your language has no method of output, you may store it in a variable.

# Example I/O

• Digit = 0, N = 3

Output = 53505354

• Digit = 2, N = 2

Output = 5348

• Digit = 5, N = 0

Output = 5

# Rules

This is , so shortest answer (in bytes) wins!

• may we take the digit as a string?
– att
Oct 23 '19 at 0:30
• in that case, what about the inverse - may we output or take input as numbers, rather than strings?
– att
Oct 23 '19 at 0:50
• If, and only if your language has no method of input, you may store the input in two variables or in a list. What does that mean? And why not just rely on our default I/O methods? Oct 23 '19 at 1:02
• BTW: Apart from that, this is a nicely written first challenge. :-) Oct 23 '19 at 1:27
• @val Functions are acceptable. Oct 23 '19 at 16:06

# Perl 6, 28 bytes

{($^a,*.ords.join...*)[$^b]}


Try it online!

### Explanation:

{                          }  # Anonymous codeblock
(               ...*)[$^b] # Index into an infinite list$^a,                        # Starting from the given number
*                       # Where each element is
.ords.join             # The ordinal values joined

• (As an aside, Perl 6 is now officially called Raku) Oct 24 '19 at 6:19

# 05AB1E, 3 bytes

FÇJ


Takes N as first input and the digit as second.

Explanation:

F    # Loop the (implicit) first input (N) amount of times
Ç   #  Convert the characters in the string at the top of the stack to its unicode values
#  (which will take the second input implicitly in the first iteration)
J  #  Join these unicode integers together to a single string
# (after the loop, the result is output implicitly)


# Python 2, 55 bytes

f=lambda s,n:f(ord(s),n-1)+f(s[1:],n)if n*s else s


Try it online!

56 bytes

lambda s,n:eval("''.join(ord(c)for c in"*n+" s"+")"*n)


Try it online!

Generates and evaluates monstrosities like:

''.join(ord(c)for c in''.join(ord(c)for c in''.join(ord(c)for c in s)))


56 bytes

f=lambda s,n:s*0**n or''.join(ord(c)for c in f(s,n-1))


Try it online!

• and...or saves a byte TIO Oct 23 '19 at 16:42

# Jelly, 7 5 bytes

ṾOVƊ¡


Try it online!

-2 bytes after a friend helped me figure out what's wrong with O

For some reason, to run all test cases with a footer, an extra byte is required for the explicit ⁹ nilad: Try it online!

Ṿ        Stringify the input
O       and convert each character to a codepoint,
V      then concatenate them and eval the result,
Ɗ¡    repeated a number of times equal to the right argument.

• Nice. Don't know Jelly, but does it help at all that you can take the input as a string? I was wondering if you could somehow avoid the first step? Oct 23 '19 at 6:56
• V turns it back into an integer anyhow, so the best I could do would probably just be to change the order of things, since using V to stringify and then concatenate the strings all in one byte seems like it ought to be optimal, even though it does end up with an integer. Oct 23 '19 at 7:46

# Brachylog, 7 bytes

{ṫạc}ⁱ⁾


Try it online!

{   }ⁱ     Repeat
ṫ         stringifying,
ạ        converting to a list of codepoints,
c       and concatenating
⁾    a number of times equal to the last element of the input.

• Huh, not sure I've ever had one of my answers downvoted before. Nov 7 '19 at 6:20

# J, 14 13 bytes

[:,":@u:~"+&3


Try it online!

### How it works

The "bind" operator & is commonly used to bind a constant to a dyad, so that it can be used as a monad. However, the same form can be used as a dyad: x n&v y (where n is a noun and v is a dyadic verb) or x v&n y applies monadic n&v or v&n to y repeatedly x times. Using this feature, we can design the target function like this:

x some_constant&some_dyad y
run some_constant some_dyad y x times
... or ...
run y some_dyad some_constant x times


In this case, there is an obvious choice for the some_constant, which is 3 for 3 u: y.

And here goes the full explanation:

[:,":@u:~"+&3
&   Apply this function x times...
u:~   3  Convert chars of y to ASCII values (3 u:)
":@   "+    Convert each number back to string
[:,            Flatten the array to get a single string


# Ruby, 30 bytes

->s,n{n.times{s=s.bytes*''};s}


Try it online!

# C# (.NET Core), 174 147 bytes

class Z{static void Main(string[] a){for(int n=int.Parse(a);n-->0;){var x="";foreach(char c in a)x+=c-0;a=x;}System.Console.Write(a);}}


Big help from Jo King.

Try it online!

# Ungolfed

class Z
{
static void Main(string[] a)
{
int n = int.Parse(a);
for (; n-- > 0;)
{
var x = "";
foreach (char c in a)
x += c - 0; //c-0 gets converted to int, and then the int is
//automatically converted to a string
a=x;
}
System.Console.Write(a);
}
}

• @JoKing I thought of that first and somehow thought it was longer. But after all the substring business and calc'ing p that failed. Thanks! Oct 23 '19 at 2:54
• foreach(char c in a) -> foreach(var c in a), -1 byte Oct 23 '19 at 5:32
• Also, get rid of extra space in Main(string[] a) Oct 23 '19 at 5:33
• Move the a=x part into the top part of the for-loop, like this: for(int n=int.Parse(a);n-->0;a=x) Oct 23 '19 at 5:39
• With using System.Linq; the inner part of the loop can be reduced to: a=string.Concat(a.Select(c=>c-0));, -6 bytes Oct 23 '19 at 13:06

# JavaScript (ES6),  43  40 bytes

Thanks to @tsh for reminding me that I didn't use currying this time :p (-3 bytes)

Takes input as (N)(digit).

n=>g=k=>n--?g(k.replace(/./g,c=>c^48)):k


Try it online!

### How?

This is a simple recursive function. The only trick in there is c^48. Because c is a string, we need to coerce it to an integer. We could do +c+48, but that would be 1 byte longer. Using a bitwise XOR is safe here, as $$\48\$$ is $$\110000_2\$$ and c is less than $$\10000_2\$$.

• I believe n=>g=k=>n--?g(k.replace(/./g,c=>c^48)):k is valid.
– tsh
Oct 23 '19 at 2:32

(!!).iterate(>>=show.fromEnum)


Try it online!

+5 then -5 bytes from Jo King clarifying the rules and then working it into pointfree.

My first Haskell golf so I've probably done something horribly wrong. In addition to having misspelled golf, I tried to import ord without putting it in my byte count!

    .                             The composition of
iterate                      infinitely iterating, starting with the argument,
(>>=             )    concatenating the results of mapping
show              finding the string representation of
.fromEnum     the codepoint of the argument,
(!!)                              with indexing into the resulting infinite list.

• You do have to import Data.char if you want to use ord. You can also do this in pointfree style for 30 bytes with fromEnum
– Jo King
Oct 23 '19 at 2:45

# Japt-h, 5 bytes

VÆ=mc


Try it

VÆ=mc   V = number of times, U = digit
VÆ      V times do: (Collects each result into an array)
=mc     Map every digit of U to it's ASCII value, and make that the new U
-h      Take last element


eval's/./ord$&/ge;'x<>  Try it online! # J, 18 bytes ([:,3":@u:"0])@[&0  Try it online! From the J dictionary: The phrase x f@[&0 y is equivalent to f^:x y , apply the monad f x times to y. That is, it's a shortcut for power of ^: applied as many times as the left arg. Which explains the ( )@[&0  part of the code. Now for what's in the parentheses: 3 u:] converts to a unicode code point, but unfortunately has infinite rank, and we want to apply it with 0 rank, hence the added "0. The code point is a number, and we convert it back to a string with format ":. Finally, we flatten , this list of strings. • Can you explain your code, I don't know what's going on. Thanks! Oct 23 '19 at 6:34 • @GalenIvanov Done! Oct 23 '19 at 6:42 • Thank you! Apparently I can't remember this shortcut to ^: Oct 23 '19 at 6:44 # PowerShell, 51 49 bytes -2 bytes thanks to mazzy param($s,$n),1*$n|%{$s=-join($s|% t*y|%{+$_})};$s


Try it online!

# Python 2, 63 57 bytes

f=lambda i,n:n and f(''.join(ord(c)for c in i),n-1)or i


Try it online!

-6 bytes due to Jonathan Allan noting that the input can be a string.

Takes input as single digit string and an integer number of repetitions.

• Take i as a string and save six bytes, TIO Oct 23 '19 at 15:38
• @Jonathan Allan: Ah! I missed that that was permitted. Oct 23 '19 at 21:49

# Bracmat, 63 bytes

get':%?a %?n&whl'(!n+-1:~<0:?n&str$vap$((=.asc$!arg).!a):?a)&!a  Try it online! • Nice 1st answer. One suggestion is to add a Try It Online link in your answer so other users can easily verify your code. It's not required but highly recommended. It can also generate CG&CC posts which is nice. Oct 24 '19 at 12:23 # Haskell, 30 bytes (!!).iterate(show.fromEnum=<<)  Try it online! • I don't know Haskell, but there is already almost identical solution Oct 23 '19 at 8:07 • @GalenIvanov The linked one does work exactly the same way as this one. Oct 23 '19 at 8:10 • @GalenIvanov Yup, they're the same. I came up with it independently. Two same answers isn't surprising here since I think it's the best Haskell can do. – xnor Oct 23 '19 at 8:15 • Yes, it's not surprising to have this when the code is short :) Oct 23 '19 at 8:20 • I was inspired to write mine entirely by just how perfect an application of the list monad it is, so it definitely makes sense that I'd not be alone in it Oct 23 '19 at 23:02 # Charcoal, 9 bytes ＦＮ≔⭆η℅κηη  Try it online! Link is to verbose version of code. Takes N as the first input and the digit as the second input. Explanation: ＦＮ  Repeat N times... ≔⭆η℅κη  Map each character to its ordinal and concatenate. η  Output the final result. Sadly ＦＮ≦℅ηη doesn't work... # Lua, 55 bytes a,N=...for i=1,N do a=a:gsub('.',('').byte)end print(a)  Try it online! Take input as arguments. Explanation is fairly obvious. # Alternative solution: Lua, 60 bytes a,N=...for i=1,N do a=table.concat{a:byte(1,-1)}end print(a)  Try it online! # Lua, 67 bytes i=io.read d=i(1)for _=1,i()do d=d:gsub(".",string.byte)end print(d)  Try it online! Let d be the digit we will transform (always of length 1, so we ask to read 1 character with io.read(1)). If N > 0, replace each character by its byte value. Return the digit. # K (oK), 13 9 bytes -4 bytes thanks to ngn (,/$i$)/  Try it online! • (,/$i$)/ works too, with swapped args – ngn Nov 2 '19 at 13:22 • @ngn Thank you! Apparently I didn't know how x and y are applied to this tacit function. Nov 2 '19 at 17:00 # Wolfram Language (Mathematica), 41 bytes ""<>ToString/@ToCharacterCode@#&~Nest~##&  Try it online! # APL (Dyalog Unicode), 16 bytes {(∊⍕¨∘⎕UCS)⍣⍵⊢⍺}  Try it online! Left input is a one-digit string, right input is the number of iteration. Returns the string representation of the result. ### How it works {(∊⍕¨∘⎕UCS)⍣⍵⊢⍺} { } Dyadic dfn, ⍺=digit string, ⍵=iteration ⊢⍺ Start with ⍺ ( )⍣⍵ Repeat ⍵ times... ⎕UCS Convert each char to Unicode codepoint ⍕¨∘ Convert each number back to string ∊ Enlist (flatten) all chars into one string  # PHP, 58 bytes for([,$a,$b]=$argv;$b--;)$a=strtr($a,range(48,57));echo$a;


Try it online!

Input digit and number are two command arguments ($argv) in same order. ### Comented for( [,$a,$b]=$argv;  // $a is input digit and$b is number
$b--; // loop$b times
)
$a= // set$a to
strtr(         // strtr in array mode, replaces keys with values
$a, // replace in$a itself
range(48,57) // an array with keys 0...9 and values 48...57
);
echo$a; // at the end, output$a


# C# (Visual C# Interactive Compiler), 55 bytes

a=>b=>{for(;b-->0;a=a.SelectMany(l=>l-0+""));return a;}


Try it online!

# Python 3, 69 60 bytes

f=lambda n,i:i and f(''.join(str(ord(c))for c in n),i-1)or n


Try it online!

# Red, 62 57 bytes

func[d n][loop n[parse d[any[change p: skip(0 + p/1)]]]d]


Try it online!

Explanation:

f: func [ d n ] [                  ; a function with 2 parameters
loop n [                       ; repeat n times
parse d [                  ; parse the string with the following rules
any [                  ; one ore more
change p: skip     ; change any string with length 1 (a single digit)
(0 + p/1)          ; with its representation as a number 48..57
]
]
]
d                              ; return the altered string
]


# Icon, 72 63 bytes

Inspired by @xnor's Python 2 solution

procedure f(d,n)
return(*d*n<1&d)|f(48+!d,n-1)||f(d[2:0],n)
end


Try it online!

# Retina, 21 bytes

.+¶

"$+"+.$.(*_48*


Try it online! Takes N as the first input and the digit as the second input. Explanation:

.+¶


Delete N from the output.

"$+"+  Repeat N times. .$.(*_48*


Replace each digit with its ASCII code.

Translation of Nahuel Fouilleul's solution. Thanks to Veskah for pointing it out.

.
⎕UCS⍵M


Try it online!

. replace any character

⎕UCS with the Universal Character Set ordinal of the
⍵M Match

This is equivalent to the Dyalog APL expression '.'⎕R{⍕⎕UCS⍵.Match}⍣⎕⊢⍞. Try it online!