# 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

# 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!

# Red, 62 bytes

func[s][forall s[s/1: #""+ s/1]pad/left/with rejoin s 5 #"A"]


Try it online!

# Red, 50 bytes

func[v][insert/dup v 17 5 take/last/part v + 48 5]


Try it online!

Takes input as a vector of code points and returns output as the same.

• insert/dup v 17 5 Insert five 17s at the beginning
• v + 48 Add 48 to each element
• take/last/part v 5 Take the last five elements
• Nice! Good choice of input and output types. Commented Oct 9, 2022 at 18:12
• @GalenIvanov Thanks! Means a lot coming from our local Red guru. Commented Oct 10, 2022 at 2:36
• I'm far from being a guru :) Commented Oct 10, 2022 at 10:14

# Raku, 31 bytes

{TR/0..9/Aa..i/}o*.fmt('%05d')


Try it online!

*.fmt('%05d') is an anonymous function that formats its integer argument to five digits, padded on the left with zeroes. { TR/0..9/Aa..i/ } is a second anonymous function that transliterates its string argument, turning 0 into A and 1-9 into a-i. The o operator composes those two functions.

# Rust, 67 bytes

|a|format!("{:A>5}",a.map(|d|char::from(d+96)).collect::<String>())


Try it online!

# C++ (gcc), 142138 137 bytes

-4 thanks to @ceilingcat.

First time golfing in C++, there are probably many places where improvements could be made. #include <bits/stdc++.h> was really expensive in terms of bytes.

#include<bits/stdc++.h>
int f(int n){for(int i=5;i--;){putchar(((n%(int)exp10(i+1))/(int)exp10(i))?(n%(int)exp10(i+1))/exp10(i)+96:65);}}


Try it online!

Takes integer inputs and outputs as string.

• 102 bytes Commented Oct 17, 2022 at 0:41
• 58 bytes as a lambda
– jdt
Commented Nov 11, 2022 at 0:56
• 53 bytes as a preprocessor macro.
– jdt
Commented Nov 11, 2022 at 12:40

# C#, 43 bytes

x=>x.PadLeft(5,'').Select(y=>(char)(y+48))


 represents the character with code 17; 48 is added to this to produce A.

Try it online!

# Elixir, 41 bytes

&for<<x<-String.rjust(&1,5,17)>>,do: x+48


Try it online!

• This is cool. I honestly don't recall seeing an Elixir answer here before. Commented Oct 11, 2022 at 9:33

# Pyth, 1413 12 bytes

@L+\AG+mZ-5l


Try it online!

Explanation:

@L+\AG+mZ-5l # whole program

# implicit output
L           # left map with lambda d:
@            # using index
+          #  concatenate
\A        #   literal "A"
G       #   and literal "abc...xyz"
+      # into a concatenation of:
mZ    #  a constructed list of n zeroes
#   where n is: (the 2nd argument for m is supplied an int)
-5  #    the difference of 5
l #    and the length of implicit input (Q)
#  and the implicit input (Q)


# ><>, 17 16 bytes

r5l6=.a7+!
68*+o


Try it online

Explanation

r        !    # reverse stack on first iteration
5l6=.        # if stack length is 5, move to next row
a7+     # else add 17 to stack
68*+o         # add 48 to each item on stack and print as char


# k, 18 bytes

"A"^-5$10h$96+10\:


# x86-16 machine code, 20 17 bytes

00000000: fcb8 4141 abab fd03 f14e ac04 30aa e2fa  ..AA.....N..0...
00000010: c3


Callable function, custom calling convention. Input string at DS:[SI], CX = input string length (1-5), output string buffer at ES:[DI].

Listing:

FC          CLD                 ; string direction forward
B8 4141     MOV AX, 'AA'        ; AL and AH = pad char
AB          STOSW               ; pad only first 4 chars
AB          STOSW
FD          STD                 ; string direction reverse
03 F1       ADD  SI, CX         ; SI = end of input string
4E          DEC  SI             ; SI = last char of input
A_LOOP:
AC          LODSB               ; load next char
04 30       ADD  AL, 'a'-'1'    ; aaaaaa convert
AA          STOSB               ; write to output
E2 FA       LOOP A_LOOP


#### Test program output:

Props: -3 bytes thx to @l4m2!

• Your second call fails due to wrong direction
– l4m2
Commented Dec 23, 2022 at 18:21
• @l4m2 oh, do you mean because there's no explicit CLD in the beginning? Okay... that's fair - as a DOS standalone I can assume DF=0, but as a function I cannot. Will fix. Commented Dec 24, 2022 at 16:36
• push cx/.../pop cx => mov ax, 'AA'/stosw/stosw
– l4m2
Commented Jan 15, 2023 at 5:18
• @l4m2 wow, that seems so obvious now that you mention that! Thanks! Commented Jan 16, 2023 at 6:34

# PHP, 58 bytes

fn($x)=>strtr(sprintf("%05d",$x),1234567890,"abcdefghiA");


Attempt This Online!

The solution is based on the characters translation. sprintf fills the string with the trailing zeroes which are get translated to "A" while the digits 123456789 are converted to abcdefghi.

# Ly, 25 bytes

iry5L[f5f-['Ao,]]pp['0+o]


Try it online!

Pretty straight forward reading of the rules...

ir                        - read the digits in a codepoints, reverse stack
y5                      - push digit count, push "5"
L                     - check: digitCount<5
[          ]pp       - exec block if digit count < 5
f5f-                - subtract digit count from 5, get pad count
[   ,]          - loop once for each pad digit...
'Ao            - print "A"
[    ] - loop or all the codepoints on the stack
'0+   - convert from 0-9 to a-i
o  - print as character


# Jelly, 15 bytes

DịØa;@”Ax5¤Uḣ5U


Try it online!

Almost certainly I'm missing some atoms or syntax tricks that can get this down further. 11 bytes are spent to handle the padding.

Explanation:

DịØa;@”Ax5¤Uḣ5U
D               get decimal representation
ịØa            index into lowercase alphabet
”Ax5¤     repeat "A" 5 times
;@          prepend "A"s to the other string
Uḣ5U take the last 5 characters

• -2 bytes: DịØa”Ax5¤;ṫ-4. There's got to be a builtin but I can't find it either. Commented Oct 8, 2022 at 19:41

# J, 29 bytes

There probably is a shorter way (perhaps with a.) than a hard-coded string mapping, but everything I tried ended up being longer.

'Aabcdefghi'{~],~[:0"0[:i.5-#


Try it online!

Takes input as array of numbers and outputs a string.

# Knight (v2), 41 bytes

;=iP;=s*'A'5;Wi;=s+sA+96[i=i]iO Gs-Ls 5 5


Try it online!

# Ruby-nl, 28 bytes

p$_.rjust(5).tr" 1-9","Aa-i"  Attempt This Online! ultra verbose awk solution: echo '43213 8645 342 99991' |  awk '$!NF=sprintf("%c%c%c%c%c",___+(__+$(_=($(_<_)=sprintf("%.*d%s",5-NF,
_=_<_,$_))^_))^!!$_,___+(__+$++_)^!!$_,(__+$++_)^!!$_+___,
___+(__+$++_)^!!$_,___+(__+$++_)^!!$_)' __=32 ___=64 FS=

dcbac
Ahfde
AAcdb
iiiia


# Arturo, 62 45 bytes

\$[s][pad.with:Ajoin map s=>[to :char 96+]5]


Try it

# Thunno 2, 7 bytes

ÄLJ'A5ṙ


Try it online!

#### Explanation

ÄLJ'A5ṙ  '# Implicit input
Ä         # Number to alphabet
L        # Lowercase each
J       # Join into a string
'A    '# Using "A" as a filler,
5ṙ   # pad the string to length 5
# Implicit output


# Rust, 110 bytes

Takes the number and returns the converted string in the aaaaa way.

|x:u64|"A".repeat((4-x.ilog(10))as _)+&x.to_string().bytes().fold(format!(""),|mut s,b|{s.push((48+b)as _);s})


Attempt This Online!

# Rust, 93 bytes

Returns a byte slice, i.e. Vec<u8> instead that corresponds to the ASCII-encoded aaaaa string.

|x:u64|{let mut v=vec![65;(4-x.ilog(10))as _];v.extend(x.to_string().bytes().map(|b|48+b));v}


Attempt This Online!

# Pxem, 0 + 45 = 45 bytes

Filename, with non ascii byte. For example \5 is U+0005.

\5.t.w.i1.-a.+.m\1.-.t.m.a.cj.x.s.vA.v.cj.a.v.p


Try it online!

## How it works

\5.t        register = 5
.w          while pop() != 0
.i          push getchar() # eof is -1
1.-a.+      push(97+abs(pop()-49))
.m\1.-.t    register -= 1
.m          push register
.a          endwhile
.cj.x       while top > 106
.s          drop
.vA.v       insert 65 to bottom of stack
.cj.a       endwhile
.v.p        putchar() from bottom to top
`