31
\$\begingroup\$

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!

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

52 Answers 52

1
2
2
\$\begingroup\$

Perl 5 -plF, 24 bytes

$_=A x(5-@F).y/1-9/a-i/r

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Red, 62 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\begingroup\$ Nice! Good choice of input and output types. \$\endgroup\$ Oct 9, 2022 at 18:12
  • \$\begingroup\$ @GalenIvanov Thanks! Means a lot coming from our local Red guru. \$\endgroup\$
    – chunes
    Oct 10, 2022 at 2:36
  • \$\begingroup\$ I'm far from being a guru :) \$\endgroup\$ Oct 10, 2022 at 10:14
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Rust, 67 bytes

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

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C++ (gcc), 142 138 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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 102 bytes \$\endgroup\$
    – ceilingcat
    Oct 17, 2022 at 0:41
  • \$\begingroup\$ 58 bytes as a lambda \$\endgroup\$
    – jdt
    Nov 11, 2022 at 0:56
  • 1
    \$\begingroup\$ 53 bytes as a preprocessor macro. \$\endgroup\$
    – jdt
    Nov 11, 2022 at 12:40
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

Elixir, 41 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ This is cool. I honestly don't recall seeing an Elixir answer here before. \$\endgroup\$
    – chunes
    Oct 11, 2022 at 9:33
2
\$\begingroup\$

Pyth, 14 13 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)
\$\endgroup\$
2
\$\begingroup\$

><>, 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
\$\endgroup\$
2
\$\begingroup\$

k, 18 bytes

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

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
C3          RET                 ; return to caller

Test program output:

enter image description here

Props: -3 bytes thx to @l4m2!

\$\endgroup\$
4
  • \$\begingroup\$ Your second call fails due to wrong direction \$\endgroup\$
    – l4m2
    Dec 23, 2022 at 18:21
  • \$\begingroup\$ @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. \$\endgroup\$
    – 640KB
    Dec 24, 2022 at 16:36
  • 1
    \$\begingroup\$ push cx/.../pop cx => mov ax, 'AA'/stosw/stosw \$\endgroup\$
    – l4m2
    Jan 15, 2023 at 5:18
  • \$\begingroup\$ @l4m2 wow, that seems so obvious now that you mention that! Thanks! \$\endgroup\$
    – 640KB
    Jan 16, 2023 at 6:34
2
\$\begingroup\$

Uiua, 11 10 9 bytes

⬚@A↙¯5+@`

Try it!

  • -1 byte from Dominic van Essen
  • -1 byte from Bubbler
 ⬚@A↙¯5+@`
       +@`  # add backtick character
 ⬚@A↙¯5     # take the last five characters, filling any excess with A
\$\endgroup\$
4
  • 1
    \$\begingroup\$ 10 bytes: ⇌⬚@A↙5⇌+@` \$\endgroup\$ Oct 22, 2023 at 8:44
  • \$\begingroup\$ @DominicvanEssen Ah, of course. Thanks! \$\endgroup\$
    – chunes
    Oct 22, 2023 at 15:33
  • 1
    \$\begingroup\$ 9 bytes: ⬚@A↙¯5+@` \$\endgroup\$
    – Bubbler
    Oct 22, 2023 at 23:01
  • \$\begingroup\$ @Bubbler Excellent. I had no idea negative-take was a thing. \$\endgroup\$
    – chunes
    Oct 23, 2023 at 0:11
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ -2 bytes: DịØa”Ax5¤;ṫ-4. There's got to be a builtin but I can't find it either. \$\endgroup\$
    – naffetS
    Oct 8, 2022 at 19:41
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

Knight (v2), 41 bytes

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

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Ruby -nl, 28 bytes

p$_.rjust(5).tr" 1-9","Aa-i"

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

Arturo, 62 45 bytes

$[s][pad.with:`A`join map s=>[to :char 96+]5]

Try it

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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!

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.