-4
\$\begingroup\$

The program

Given a number, program must return the alphabet letter correspondent.

Rules

  • The challenge here is to make it as short as possible, everyone knows it is a very easy program to do.
  • The number is not zero-based, it means 1 is A, 2 is B, 3 is C and so it goes...
  • Any language will be accepted.
\$\endgroup\$
5
  • \$\begingroup\$ I suspect the winning answer will be tiny. \$\endgroup\$ – DavidC Sep 14 '12 at 2:53
  • \$\begingroup\$ I think my answer won \$\endgroup\$ – dspyz Sep 18 '12 at 1:01
  • \$\begingroup\$ @BernaMariano What does "given a number" mean? \$\endgroup\$ – Toothbrush Feb 20 '14 at 11:34
  • \$\begingroup\$ @toothbrush If Goku gives you a 3, use 3. \$\endgroup\$ – BernaMariano Feb 25 '14 at 18:43
  • \$\begingroup\$ @BernaMariano Well, I'm not sure what you mean, but is my answer OK, then? \$\endgroup\$ – Toothbrush Feb 25 '14 at 18:44

38 Answers 38

1
2
0
\$\begingroup\$

Haskell, 38 bytes

main = putChar $ ('a':['a'..'z']) !! c

Where c is the number.

\$\endgroup\$
1
  • \$\begingroup\$ There is a lot of unnecessary white space: main=putChar$('a':['a'..'z'])!!c works as well. However you can not assume input to be present in a certain variable, but then again returning from a function is acceptable, so f c=('a':['a'..'z'])!!c or equivalently (('a':['a'..'z'])!!) works. \$\endgroup\$ – Laikoni Mar 20 '18 at 10:54
0
\$\begingroup\$

Java 8, 15 bytes (as lambda function)

n->(char)(n+64)

Try it online.

Java 8, 84 bytes (as full program)

interface M{static void main(String[]a){System.out.printf("%c",new Byte(a[0])+64);}}

Try it online.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This works only for single digit. Double digit input will fail. ex: give 10 as input and output still comes as A. You care considering charAt(0), for double digits, you have to consider 2 characters. \$\endgroup\$ – BarathVutukuri Mar 20 '18 at 10:46
  • \$\begingroup\$ @BarathVutukuri Thanks, fixed! \$\endgroup\$ – Kevin Cruijssen Mar 20 '18 at 10:49
0
\$\begingroup\$

Haskell, 11 bytes

(['@'..]!!)

Try it online! This anonymous function indexes into the string "@ABCDEFG ...".

\$\endgroup\$
0
\$\begingroup\$

Fortran (GFortran), 30 bytes

READ*,I
PRINT*,ACHAR(I+64)
END

My entry in the good ol' Fortran.

Try it online!

\$\endgroup\$
0
\$\begingroup\$

FORTH 16 BYTES

: n 64 + EMIT ;

OUTPUT:

8 N
8 N H ok
5 N
5 N E ok
12 N
12 N L ok
12 N
12 N L ok
15 N
15 N O ok
23 N
23 N W ok
15 N
15 N O ok
18 N
18 N R ok
12 N
12 N L ok
4 N
4 N D ok
\$\endgroup\$
0
\$\begingroup\$

Tcl, 31 bytes

puts [format %c [incr argv 64]]

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Japt, 2 bytes

dI

Try it or test all numbers

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

PHP 442

$alphabet = Array('A' => 1,'B' => 2,'C' => 3,'D' => 4,'E' => 5,'F' => 6,'G' => 7,'H' => 8,
'I' => 9,'J' => 10,'K' => 11,'L' => 12,'M' => 13,'N' => 14,'O' => 15,'P' => 16,'Q' => 17,
'R' => 18,'S' => 19,'T' => 20,'U' => 21,'V' => 22,'W' => 23,'X' => 24,'Y' => 25,'Z' => 26
)

function testInputForAlphabetCharacter($input){
    for($index = 0; $index < count($alphabet); $i = $i + 1){
        if($alphabet[$index] == $input){
            echo($index);
        }
    }
}


$input = $_GET['input'];
testInputForAlphabetCharacter($input);
\$\endgroup\$
4
  • 2
    \$\begingroup\$ @scleaver... o_0 \$\endgroup\$ – Ian Brindley Feb 20 '14 at 9:30
  • 2
    \$\begingroup\$ I agree with @IanBrindley, this is serious overkill... There's no chance of shrinking this down? \$\endgroup\$ – WallyWest Feb 20 '14 at 10:56
  • 1
    \$\begingroup\$ echo chr(64+$input); \$\endgroup\$ – Ian Brindley Feb 20 '14 at 13:29
  • 4
    \$\begingroup\$ this is as small as i could get it \$\endgroup\$ – scleaver Feb 21 '14 at 23:11
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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