# Number to String in aaaaa way!

In this challenge, you are going to take a number and turn it into a string, but not in the common way. You will use the aaaaa way!

The aaaaa way is simply replacing each digit of the input number with the letter at that position in the alphabet. For example, 11111 would become aaaaa and 21223 would become babbc. If the number is less than 5 digits you need to left-pad it with an "A". For example, 12 would be AAAab.

## Rules

• Your code can be a function or a complete program that outputs to STDOUT.
• The returned string must be 5 letters.
• It's obvious that the input would be a 1 to 5 digits number that has digits from 1 to 9.
• You can get both input and output in number and strings or in array form like [1,2,1,3,1] and ['a','b','a','c','a'].

## Test cases

In: 43213 -> Out: dcbac
In: 8645  -> Out: Ahfde
In: 342   -> Out: AAcdb
In: 99991 -> Out: iiiia


This is , so smallest program wins!

• The rule states that input has digits 1 thru 9. What about 0? Does it become j? Commented Nov 17, 2022 at 4:14
• @roblogic, no input wont have a 0. Only 1 to 9 and output is a to i. Commented Nov 17, 2022 at 11:13

# Python, 44 bytes

lambda s:f"{s:05}".translate("bcdefghiAa"*9)


Attempt This Online!

Takes an integer and returns a string.

# JavaScript (ES6), 48 bytes

Expects an integer and returns a string.

f=(n,k=5)=>k?f(n/10|0,k-1)+"Aabcdefghi"[n%10]:''


Try it online!

# C (gcc), 48 bytes

k;f(n){k++>4?k=0:f(n/10)|putchar(n?n%10+96:65);}


Try it online!

## 47 bytes

This version was suggested by @jdt.

i;f(*o,x){for(i=5;i;x/=10)o[--i]=x?96+x%10:65;}


Try it online!

• Impressive! Javascript is not mostly a good language for golfing but this is really awesome Commented Oct 7, 2022 at 12:27
• 45 bytes
– c--
Commented Oct 7, 2022 at 19:51
• @c-- This is very tempting and I did a similar suggestion some days ago. But, as I said for the other answer, the function will not be reusable anymore when k overflows. Commented Oct 7, 2022 at 19:57
• Is k=0 really needed? Yea you can only execute the function once, but isn't that enough? Commented Oct 10, 2022 at 13:40
• @12431234123412341234123 Our consensus is that functions have to be reusable arbitrarily often. Commented Oct 10, 2022 at 13:49

# C (clang), 696763 61 bytes

f(x,o,i)char*o;{for(memset(o,65,i=5);x;x/=10)o[--i]=x%10+96;}


Try it online!

# Japt, 9 bytes

Takes input as a string.

c+48 ù'A5


Try it

c+48 ù'A5     :Implicit input of string
c+48          :Map charcodes, adding 48 to each
ù'A5     :Left pad with "A" to length 5


# Python 3, 50 bytes

lambda l:''.join(chr(96+i)for i in l).rjust(5,'A')


Takes a list of integers as input

Try it online!

• Please could the downvoter explain why this was downvoted? It works fine for all test cases. Commented Oct 7, 2022 at 11:31

# Nibbles, 5 bytes (10 nibbles)

&"A"5+''

     +     # add each element of input
''  # to '' character
&          # then justify the text
"A"       # using the "A" character
5      # to a width of 5


• Your code shows the first character as &, but your explanation shows a $. Is this a typo? Commented Oct 7, 2022 at 15:30 • @TheThonnu Yes I wanted to say that too Commented Oct 7, 2022 at 15:32 • Oh, yes, it's a typo. Sorry! Commented Oct 7, 2022 at 15:40 • (and if you're interested, the list of commands is here)... Commented Oct 7, 2022 at 15:42 # Factor, 29 bytes [ >dec 48 v+n 5 65 pad-head ]  Attempt This Online! -6 from chunes. • [ 48 + ] map => 48 v+n and you're allowed to take input as a string so you don't need >dec. Commented Oct 7, 2022 at 18:42 # Fig, $$\14\log_{256}(96)\approx\$$ 11.524 bytes $t5$J*/A5OC+96  Try it online! • No pad operator really hurts... Commented Oct 10, 2022 at 19:10 # sed, 42 bytes y/123456789/abcdefghi/ :a s/^.{,4}$/A&/
ta


Attempt This Online!

# Excel (ms365), 63 61 bytes

-2 Thanks to @EngineerToast for 61 bytes:

=RIGHT(CONCAT("AAAA",CHAR(96+MID(A1,SEQUENCE(LEN(A1)),1))),5)


Or, the original answer for 63 bytes:

=CONCAT(MID("Aabcdefghi",MID(TEXT(A1,"00000"),ROW(1:5),1)+1,1))


Note that it can probably be done with less bytes if input is an array of numbers but thought I'd take a single integer as startpoint.

• 61 bytes =RIGHT(CONCAT("AAAA",CHAR(96+MID(A1,SEQUENCE(LEN(A1)),1))),5) Commented Oct 11, 2022 at 13:11

# Julia, 48 bytes

~x=replace(lpad(x,5,'A'),('1':'9'.=>'a':'i')...)


Attempt This Online!

# Julia 1.0, 67 65 bytes

~x=getindex.([Dict(0:9 .=>['A';'a':'i'])],[0;0;0;0;x][end-4:end])


Try it online!

-2 bytes thanks to @MarcMush: replace [[0,0,0,0];x] with [0;0;0;0;x]

• Function is defined with the unary operater ~
• The dictionary is wrapped in an array to allow passing multiple values.
• For padding, I concatenate a zero array and the input array. Only the last five elements [end-4:end] are used.
• -2 bytes : [0;0;0;0;x]  Commented Nov 18, 2022 at 21:37

# POSIX Shell Command Language + Utilities, 26 bytes

printf %05d $1|tr 0-9 Aa-i  Self-explanatory: printf renders the argument padded to five columns with zeroes, then tr does the transformation per spec. Transcript of test cases: $ cat a.sh; echo; wc -c a.sh
printf %05d $1|tr 0-9 Aa-i 26 a.sh$ ./a.sh 8645; echo
Ahfde
$./a.sh 43213; echo dcbac$ ./a.sh 8645; echo
Ahfde
$./a.sh 342; echo AAcdb$ ./a.sh 99991; echo
iiiia


# APL (Dyalog Extended), 13 bytes

Full program prompting for digit number list

'A'@=¯5↑⎕⊇⌊⎕A


Try it online!

⎕A uppercase Alphabet

⌊ Lowercase that

⎕⊇ use the input to select from that (1-indexed)

¯5↑ take the last 5 elements of that, adding padding elements on the left

'A' put "A"s where equal to the padding element

# Vyxal, 8 bytes

øA∑\A5ø↳


Try it Online!

Finally, a use for some of the more niche string digraphs. Takes input as a list of digits, outputs a single string.

## Explained

øA∑\A5ø↳
øA        # Get the nth letter of the alphabet for each digit in the input
∑       # Join as a single string
\A     # Push the string "A" to the stack
5    # Push the number 5 to the stack
ø↳  # And left pad the single string from early with "A"s until it's 5 characters long

• Nooooo I was actually close to finding the answer till I saw this... dammit :(. Oh well, +1 Commented Oct 9, 2022 at 13:06

# simply 0.11, 66 bytes

This abuses bugs in the parser, to save bytes.
It works with the commit 98783927a8a232b8e0afb46f380e02348b0f7cbb - current commit at the time.
The behaviour will, VERY LIKELY, change in the future.

Creates an anonymous function that receives an array of numbers, and outputs the value.

fn($L){if$l=&len($L)<5for$_ in$l..4out'A'each$L as$i;out!ABCL[$i]}


## Example of usage:

This should output "AAfcf".

$fn = fn($L){if$l=&len($L)<5for$_ in$l..4out'A'each$L as$i;out!ABCL[$i]} call$fn([5,2,5]);


## How it works?

It simply checks the length of the array, and if it is lower than 5, it outputs 1 to 5 'A's.

It goes from 0 to 4 because it uses a range operator.
Going from 4 to 4, is just 1 iteration - the number 4 itself.
Going from 0 to 4, is 5 iterations - the number 0, number 1, number 2, number 3 and number 4.

Then, it uses the pre-existing constant !ABCL, which contains the letters from a to z, in lowercase.
The values in the array are used as indexes into the constant.

## Ungolfed

Very code-y looking:

$fn = fn($list) => {
$len = &len($list);
if $len < 5 then { for$_ in $len..4 { echo 'A'; } } foreach$list as $index { echo !ABCL[$index];
}
};


Pseudo-code looking:

Set $fn to an anonymous function($list)
Begin.
Set $len to the result of calling &len($list).
In case $len < 5 then Begin. Loop from$len to 4 as $_ Begin. Show the value 'A'. End. End. Loop through$list as $index Begin. Show the contents of !ABCL[$index].
End.
End.


All versions do the exact same.

# MathGolf, 12 bytes

(h5,'A*\É▄\§


Input as a list of digits; output as string.

Try it online.

Or alternatively:

▄▒\(§y♫α'A═╡


Input as a list of digits; output as a string wrapped inside a list.

Try it online.

Explanation:

(        # Decrease each digit in the (implicit) input-list by 1
# (because MathGolf uses 0-based indexing)
h       # Push the length of the list (without popping)
5,     # Calculate 5-length
'A* '# Repeat "A" that many times
\       # Swap so the list as at the top again
É      # For-each over the digits, using 3 characters as inner code-block:
▄     #  Push the lowercase alphabet
\    #  Swap so the current digit is at the top
§   #  Index the digit into the alphabet
# (after which the entire stack joined together is output implicitly as result)

▄        # Push the lowercase alphabet
▒       # Convert it to a list of characters
\      # Swap so the (implicit) input-list is at the top
(     # Decrease each digit by 1 (because MathGolf uses 0-based indexing)
§    # Index each digit in the list into the alphabet list
y   # Join it back together again
♫        # Push 10000
α       # Pair it with the earlier string
'A═   '# Pad both to an equal length by left-padding with "A"
╡   # Remove the last item from the pair (the 10000)
# (after which the entire stack joined together is output implicitly as result)


# 05AB1E, 11 bytes

₃+>çΔ'Aš5.£


Input as a list of digits; output as a list of characters.
(If the inputs would have been 0-based (digits 0-9 mapping to a-j) instead of 1-based, the > could have been dropped.)

Or alternatively:

5j9LðšA¬uì‡


Both input and output as a string.

Explanation:

Unfortunately 05AB1E lacks a left-pad up to length builtin (unless by spaces), so most of the bytes are to account for that in the first program..

₃+>          # Add 96 to each value
ç         # Convert each from a codepoint-integer to a character
Δ        # Loop until the result no longer changes:
'Aš    '#  Prepend an "A"
5.£  #  Leave (up to) the last 5 characters from the list
# (after which the result is output implicitly)

5j           # Left-pad the (implicit) input-string with spaces up to length 5
9L         # Push list [1,2,3,4,5,6,7,8,9]
ðš       # Prepend a space: [" ",1,2,3,4,5,6,7,8,9]
A          # Push the lowercase alphabet: "abcdefghijklmnopqrstuvwxyz"
¬         # Push its first character (without popping): "a"
u        # Uppercase it: "A"
ì       # Prepend it: "Aabcdefghijklmnopqrstuvwxyz"
‡      # Transliterate the space-padded input from [" ",1,2,3,4,5,6,7,8,9] to
# "Aabcdefghij..."
# (after which the result is output implicitly)


# BQN, 17 15 bytes

Edit: -2 bytes thanks to Razetime

¯5↑"AAAA"∾+⟜''


Try it at BQN REPL

          +⟜''     # add each element of input to the '' character
∾          # join this to
"AAAA"           # "AAAA" (shorter than (5⥊'A'))
_5↑                 # take -5 elements
# (which takes 5 elements from the end)

• ¯5↑ takes from the end Commented Oct 7, 2022 at 16:13
• @Razetime - Thanks! Commented Oct 7, 2022 at 16:53

# brainfuck, 64 bytes

>>>>>+>,[>,]<<<<<<-[---[----<+>]<++.>>-]>[<-[----->+<]>---.[-]>]


Try it online!

## Explanation

>>>>>+>


Move to position 5, make the value there 1, and move to position 6.

,[>,]


Read the digits into consecutive positions from there onward.

<<<<<<


Move 6 positions to the left. From here, each 0 before the 1 in position 5 indicates an A to be output.

-[---[----<+>]<++.>>-]


Subtract 1. Loop while it's not 0 (thus was not 1):

• Subtract 3 more, making −4.
• Loop subtracting 4 and adding 1 to the left, producing (256-4)/4=63 in the cell to the left.
• Move left, add 2 more for 65, and output that (A).
• Move right twice, for a net movement of 1 to the right, and subtract 1 (and repeat).
>[<-[----->+<]>---.[-]>]


Move right. Loop while it's not 0 (over all the digits):

• Move left and subtract 1, making −1.
• Loop subtracting 5 and adding 1 to the right, adding (256-1)/5=51 to the digit's character code.
• Move right and subtract 3, for a net +48 to the digit's character code. 48 is the difference between 1 and a, and likewise for the other digits (as both digits and letters are contiguous in ASCII).
• Output the letter produced from the digit.
• Zero that position (as it will be reused in the next iteration) and move right (and repeat).

# R, 38 bytes

\(d)intToUtf8(tail(c(!1:5,d+31),5)+65)


Attempt This Online!

Takes input as a vector of digits, outputs a string.

# Retina 0.8.2, 21 bytes

Td_l
^
AAAA
!.{5}$ Try it online! Link includes test cases. Explanation: Td_l  Translate digits to lowercase letters. ^ AAAA  Prefix four As. !.{5}$


Take the last 5 letters.

A port of @Jiří's sed answer is also 21 bytes:

Td_l
+^.{0,4}$A$&


Try it online! Link includes test cases.

# Pyth, 9 bytes

.[\A5m@Gt


Test suite

This answer uses a sufficiently different approach from the existing Pyth answer(s).

##### Explanation:
.[\A5m@Gt   | Full code
.[\A5m@GtdQ | with implicit variables
------------+----------------------------------------------------
m    Q | Replace each number d in the input with
@G    |  the character of the lowercase alphabet with index
td  |  d minus 1
.[\A5       | Pad the array on the left with A to a length of 5


# K (ngn/k), 13 bytes

"A"^-5$c$96+


Try it online!

• c$96+ convert input of digits to corresponding letters • -5$ left-pad to length 5 with spaces
• "A"^ fill spaces with "A" (and implicitly return)

# Python,  42  41 bytes

-1 thanks to loopy walt's suggestion to use XOR, ^, instead of addition.

lambda a:[chr(96^d)for d in[33]*5+a][-5:]


An unnamed function that accepts a list of integers from $$\[1,9]\$$ and returns a list of characters.

Try it online!

• lambda a:[chr(96^d)for d in[33]*5+a][-5:] saves a byte. Commented Oct 8, 2022 at 23:34
• Nice save @loopywalt, thanks! Commented Oct 8, 2022 at 23:43

# Thon, 19 bytes

n"Aabcdefghi"b5"A"J


Input as a number (e.g. 824). Output as a string (e.g. AAhbd).

Explanation

n"Aabcdefghi"b5"A"J
n                    // Input a number
"Aabcdefghi"        // Push the string of letters
b       // Convert the number to Base-"Aabcdefghi" (see below)
5"A"J  // Fill with "A" up to 5 characters
// (implicit output)


Converting to base-"Aabcdefghi" is a trick to replace every "1" with "a", every "2" with "b", etc.

# Thon (Symbols), 16 bytes

(Note: this language is newer than the challenge)

)ş{í1-å;}""]5AṚ


Explanation

)ş{í1-å;}""]5AṚ
)                 // Create an empty list
ş                // Get input as a string
{      }        // For each character in the input:
í              //   Convert to an integer
1-            //   Subtract 1
å          //   Push the lowercase alphabet and get the character
;         //   Append to the list
""]     // Join the list by an empty string
5AṚ  // Fill the string with "A" up to 5 characters
// (implicit output)


# Charcoal, 13 bytes

✂⁺×⁴A⭆Ｓ§β⊖ι±⁵


Try it online! Link is to verbose version of code. Explanation:

    A           Literal string A
×             Repeated
⁴            Literal integer 4
⁺              Concatenated to
Ｓ         Input as a string
⭆          Map over digits
β       Predefined variable lowercase alphabet
§        Indexed by
ι     Current digit
⊖      Decremented
✂               Sliced from
⁵   Literal integer 5
±    Negated


# Pyth, 18 bytes

V-5lzp"A")Vzp@GtsN


Try it online!

### Explanation

V-5lzp"A")Vzp@GtsN
V                   # For loop with N as variable
z               # Input
l                # Length
-5lz               # Subtract length of input from 5
p"A"           # Prints "A"
)          # End of for loop
p       # Print without any additional newline
G     # Initialized to "abcdefghijklmnopqrstuvwxyz"
sN  # Cast N to an integer
t    # Subtract 1
@      # Get element at index


# PowerShell, 39 bytes

-join($args|%{[char](96+$_)})|% *ft 5 A


Try it online!

Takes integers as unnamed arguments. Nothing fancy, just adds 96 to get to the ASCII code of 'a', casts to a char, joins the chars to a string, then pipes the string to % (an alias for ForEach-Object), which will call the string's member "PadLeft". Output is implicit.

# Ruby, 37 bytes

-3 bytes thanks to Dingus

->a{a.map{''<<_1+96}.join.rjust 5,?A}


Attempt This Online!

• Commented Oct 7, 2022 at 14:09
• @Dingus Nice work! Commented Oct 7, 2022 at 16:48

# J-uby, 34 bytes

I think I’m finally starting to get the hang of J-uby. A few bytes shorter than my Ruby answer.

:*&(:+&96|:chr)|:join|~:rjust&?A&5


Attempt This Online!