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

## 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.
• I suspect the winning answer will be tiny. – DavidC Sep 14 '12 at 2:53
• I think my answer won – dspyz Sep 18 '12 at 1:01
• @BernaMariano What does "given a number" mean? – Toothbrush Feb 20 '14 at 11:34
• @toothbrush If Goku gives you a 3, use 3. – BernaMariano Feb 25 '14 at 18:43
• @BernaMariano Well, I'm not sure what you mean, but is my answer OK, then? – Toothbrush Feb 25 '14 at 18:44

# DC - 6 characters

Full program including input and output.

?64+af


save to file and run with $dc file • 1 character shorter: ?64+P – seshoumara Sep 2 '16 at 8:46 • Typically: dc -f file – user19214 Mar 20 '18 at 9:57 ## APL (4) (Full program) ⎕⌷⎕A  Explanation: ⎕ (user input) ⌷ (index) ⎕A (alphabet) (They're supposed to be boxes, it's not an encoding problem.) # Brainfuck, 107 bytes >,----------[>++++++[-<------>],----------]<[<]>>[<--[->++++++++++<]>>]+++++++[-<+++++++++>]<-.>++++++++++.  # brainfuck, 64 56 50 bytes Thanks to Dorian for saving 3 bytes and inspiring 3 more ,>,[<+[-<+>[-<]>>]<[<++<-]>++>>]<<+++[->+++++<]>+.  Try it online! ## How it works ,>, Gets input [ if a two digit number <+[-<+>[-<]>>] Gets modulo 2 of first number plus 1 <[<++<-] Sets the fives cell to 2 if the first number is a 2 >++ Adds another 2 to the fives cell >>] Moves to cell after ones cell <<+++ Adds 3 to fives cell [->+++++<] Multiply the fives cell by 5 and add it to the ones cell >+. Add one and print  • Can be made shorter. Instead of tens, use "fives". Increment the tens by two for each ten, then multiply by five. Saves 3 Bytes. ,>,[<[-<+>[-<]>>]>[>++>]<++[-<+++++>]]++++[-<++++>]<. – Dorian Jul 13 '18 at 11:14 • Even more. By changing the 4*4 routine in the end to 3*5+1, you can use the fives and add them to the 3. It's a bit tricky to exit the if then, but it saves another 4 Bytes. ,>,[<[-<+>[-<]>>]<<<[->+<]>+>>]<<+++[->+++++<]>+. – Dorian Jul 13 '18 at 11:45 • @Dorian Your second solution doesn't work for numbers over 20, but thanks for the bytes saved! – Jo King Jul 13 '18 at 12:36 • Oh, I'm sorry. Didn't test it well enough. I'm glad you repaired it. – Dorian Jul 13 '18 at 12:44 ## R, 11 characters LETTERS[x]  Usage: LETTERS[21] [1] "U"  # Befunge-93, 7 6 bytes "&++,@  Try it online! Takes advantage of the extra spaces at the end of a wrapping string literal by adding two spaces (32*2 = 64) to the inputted number to turn it into the corresponding alphabetic character. Funnily enough, if we use a implementation that doesn’t include the wrapping spaces, we can do "&+.@ to add the @ (64) to the number instead. ## J, 7 characters a.{~64+  Usage:  a.{~64+1 A  # TI-Basic, 34 bytes sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",Ans,1  This is as short as it gets... # PHP, 17 bytes <?=chr(64+$argn);


Run s pipe with -F

# MATL, 4 bytes (Non-competing)

64+c


Try it online!

Because, why not. Takes input implicitly, pushes 64 and adds it to the input number. Finally it converts the number to its ASCII-equivalent using c.

# Ly, 6 bytes

n8:*+o


Try it online!

# Husk, 4 bytes

c+64


Try it online!

Boring, but probably optimal. Adds 64 to the given number and converts it to ASCII. !¡→'A is cuter (awww, the exclamation marks are friends!) but one byte longer.

# Pyth - 5 3 Bytes

@Gt


Saved two bytes thanks to ovs

Completely forgot about t and implicit Q

Explanation:

@    Index
G   in alphabet of
t  one less than
Q Input (implicitly added to solve arity)

• @Gt for 3 bytes – ovs Nov 28 '17 at 16:21
• @ovs Thanks. Forgot about t and implicit Q – Tornado547 Nov 28 '17 at 16:27

# Perl, 20 characters

chr(($ARGV[0] + 64))  Verification : risk@skynet:~/perl$ for x in {1..26}; do perl ./ord.pl $x; done; ABCDEFGHIJKLMNOPQRSTUVWXYZrisk@skynet:~/perl$


# Hexagony, 10 Bytes

Try it online!

A({/'+;?/@


Expanded:

  A ( {
/ ' + ;
? / @ . .
. . . .
. . .


This honestly took me way longer than it should have, as it's just 2 simple reflections.

The simplest version for this problem is only 2 bytes longer

  A ( {
. . . .
? ' + ; @
. . . .
. . .


('@'..'Z')[$args]  # PowerShell, 19 18 bytes -1 byte thanks to @mazzy lol I don't think it'll get much shorter than this. [char](64+"$args")


Try it online!

Takes input from a command line argument.

• You can. Try this [char](64+"$args"). :) – mazzy Dec 27 '18 at 19:37 # q/k (7) As partially applied composition: 10h$64+


## Ruby 1.9 (10)

(x+64).chr


Reading from STDIN and printing to STDOUT:

$><<(gets.to_i+64).chr  # Burlesque (6 characters) Assuming the number is already on the stack: 64.+L[ (see here in action.). Does the usual: Add 64, convert to character based on ASCII value. If number is supplied as a string via stdin to stdout (10 characters): ri64.+L[sh Alternative version without using ASCII value conversion: '@'Zr@\/!! ## Javascript, 25 chars String.fromCharCode(66-x);  ## PHP, 22 chars echo chr(66-$argv[0])


# GolfScript, 7

64+]''+


### Commentary

64    # corresponds to '@' in ASCII (65 is 'A')
+]    # add the input to 64. ']' is used for ASCII.
''+   # the conversion process


1 corresponds to A

26 corresponds to Z

• It can indeed: assuming that the only thing on the stack is the number from 1 to 26, you don't need the [. – Peter Taylor Sep 18 '12 at 12:14
• @PeterTaylor Okay, thank you! – Rob Sep 18 '12 at 20:31

# Classic ASP (14 bytes):

<%=Chr(c+64)%>


Expects c to hold the character number.

• program must return -> I see no program, I don't see c being initialized, I don't see anything returned/printed. – RobIII Feb 19 '14 at 21:32
• @RobIII OK; changed to Classic ASP. Is that what you mean? – Toothbrush Feb 20 '14 at 9:18
• Where does the value of c come from? You'd need something like request.form("c") or something (and the inevitable cast to int/long etc.). – RobIII Feb 20 '14 at 11:30
• @RobIII The question says "given". Perhaps we can ask for clarification? – Toothbrush Feb 20 '14 at 11:31
• I interpret this as "when the program is given" but asking for clarification won't hurt ;) – RobIII Feb 20 '14 at 11:32

C# 4,50KB (196 characters)

My first time here =)

using System; namespace W { class P { static void Main(string[] args) {
}
}
}

• First of all, don't forget the byte count of the program. Second, there are several ways of shortening this. First, remove all unnecessary whitespace (for example, the  s after the " ",s. You could split the string " abcdefghijklmnopqrstuvwxyz". Also, rather than compile a list beforehand, it is much more efficient to choose the characters based off of ascii values. – Justin Feb 19 '14 at 20:58
• Also: the contest explicitly mentions The program; this is not a complete program but (part of) a function. Other than that: drop the array/lookup! Ever heard of the ASCII table? ;-) And dont forget that, if you insist on a "lookup table", a string is an array of chars: string a=" abcdefghijklmnopqrstuvwxyz"; shortens your code massively. – RobIII Feb 19 '14 at 21:20
• You can drop the namespace entirely, use the args for input instead of Console.readline, shorten args to a and drop the using System and just write System.Console.WriteLine. The .ToCharArray() is also not required (a string is a char-array implicitly). Finally, the WriteLine can be shortened to Write since the challenge doesn't specify that the program needs to output a newline. – RobIII Feb 20 '14 at 15:04
• ...So your entry could be shortened to 112 chars (compiled size doesn't matter, "lose" the 4,50KB) if you incorporate all these tips: class P{static void Main(string[] a){System.Console.WriteLine(" abcdefghijklmnopqrstuvwxyz"[int.Parse(a[0])]);}}. The only thing left to do to "optimize" this code further is to drop the alphabet string and just use ASCII as I did in my entry which will get you down to 88 :-) – RobIII Feb 20 '14 at 15:07
• Oh, and your entry states "196 characters"; I don't know how you counted (but I assume you looked at the filesize of the .cs file?): your entry is actually 162 chars when all non-functional(!) whitespace is removed: using System;namespace W{class P{static void Main(string[] args){Console.WriteLine(" abcdefghijklmnopqrstuvwxyz".ToCharArray()[int.Parse(Console.ReadLine())]);}}}. – RobIII Feb 20 '14 at 15:10

# C#, 87

class P{static void Main(string[]a){System.Console.Write((char)(int.Parse(a[0])+64));}}


Complete program (not some (part of a) "function" expecting foo to be bar to work), accepts command line parameter: foo.exe 1 prints A, foo.exe 16 prints P

# C#, 10

When I make the same assumptions as, for example, the 'code-golfers' that posted the VSCript Classic ASP, Python, Burlesque, Ruby, C solutions we can get it down to 10:

(char)x+64


"Assuming x is magically initialized / passed in / on the stack / whatever excuse" and the contest doesn't explicitly require me to print it, just "return" it (which most of the above solutions don't do, either).

• I've changed my answer to a full Classic ASP example now. – Toothbrush Feb 20 '14 at 9:19
• Well, the author of the question did NOT specify how the number is given. "Given a number" is completely under-specified. Is it on stdin, is it a command line argument is it given somewhere else... You have no other choice than to make assumptions about how you get that number and how you return it. – mroman Oct 1 '14 at 13:17
• @mroman See my comments on the Classic ASP and C answers. – RobIII Oct 1 '14 at 19:40

# Tcl, 30 bytes

puts [expr [scan $argv %c]-64]  Try it online! # Python 2, 9 bytes chr(64+x)  ### Or, reading from stdin and printing to stdout: 21 print chr(64+input())  • Submissions have to be full programs or functions, and your first solution is a "snippet". You should only include your second solution. – Jakob Nov 28 '17 at 2:38 BrainFuck, 66 ,>,----------[<[->++++++++++<]++++++[>+++++++<-]>>]++++[<++++>-]<.  • Require number ends with \n(10) and mod 256 env – l4m2 Nov 28 '17 at 4:16 • Please add some explanation in the body of the answer. – pajonk Nov 28 '17 at 10:31 # Jelly, 3 bytes ịØA  Try it online! # SmileBASIC, 18 bytes INPUT N?CHR$(N+64)