74
\$\begingroup\$

Our task is to, for each letter of the (English) alphabet, write a program that prints the alphabet, in a language whose name starts with that letter.

Input: none

Output:

abcdefghijklmnopqrstuvwxyz

uppercase and trailing newline optional

Rules:

  • The scoring metric is the length of the programming language name, plus the length of the code. Hence, C will be assessed a "penalty" of 1, while GolfScript will be assessed a penalty of 10.
  • One language/implementation per answer. Multiple answers are encouraged.
  • If a programming language name's first letter is not an English letter, it should not be coerced into one. It will be treated as a separate letter (meaning less competition).
  • No answer will be accepted until every English letter has a solution.

Current rankings:

Tell me if I'm missing anybody.

Automatic leaderboard (experimental)

var QUESTION_ID=2078;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&r.indexOf('non-competing')===-1&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],lang:/<a/.test(a[1])?jQuery(a[1]).text():a[1],link:s.share_link})}),e.sort(function(e,s){var d=e.lang[0].toLowerCase(),a=s.lang[0].toLowerCase();return(d>a)-(d<a)||e.size-s.size});var s={},a=null,n="A";e.forEach(function(e){n=e.lang[0].toUpperCase(),a=e.size;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+" is for").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.lang,p=o[0].toUpperCase();s[p]=s[p]||{language:e.language,lang:e.lang,letter:p,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return(e.letter>s.letter)-(e.letter<s.letter)});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.language).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),jQuery("#languages").append(jQuery(i))}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*(?:<[^>]+>)?(?:[^]+?for )?((?:<a[^>]*?>)?(?:(?! [(=→-])[^\n,:])*[^\s,:])(?:[,:]| [(=→-]).*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px} /* font fix */ body {font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;} /* #language-list x-pos fix */ #answer-list {margin-right: 200px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Winners by Letter</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <h2>Everything</h2> <table class="answer-list"> <thead> <tr><td></td><td>Language</td><td>Author</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
9
  • 1
    \$\begingroup\$ Are we allowed to print junk to stderr? \$\endgroup\$ Apr 18, 2011 at 22:02
  • \$\begingroup\$ @Peter Taylor: Go nuts. To answer your question, yes, printing junk to stderr is fine (as long as stdout is correct). \$\endgroup\$
    – Joey Adams
    Apr 18, 2011 at 22:05
  • \$\begingroup\$ Is it OK to print the alphabet IN BIG LETTERS? \$\endgroup\$
    – SE is dead
    Jun 21, 2016 at 18:25
  • \$\begingroup\$ Funge is distinct from Befunge. Surely my pedanticism will be rewarded on a site dedicated to feats of it! \$\endgroup\$
    – tngreene
    Mar 23, 2017 at 19:53
  • 7
    \$\begingroup\$ Is *0*5AB1E the same as *o*sabie :P? \$\endgroup\$ Jun 6, 2019 at 14:58

164 Answers 164

1
2 3 4 5 6
26
\$\begingroup\$

P is (actually) for Piet - 57 codels

Large version (codel size = 6)

p is for piet - big

Small version (codel size = 1)

p is for piet - small

Tested with Erik's piet interpreter npiet and developed with Piet Creator.

Edit: Here is a "trace" version (generated with npiet -tpf) so you can see how it works.

Execution starts in the top left and goes around the border clockwise. The top edge and right edge are setup (calculating the value of a (97) takes quite a few codels). The loop starts on the bottom edge and goes to the left edge. When the value of z is reached the program turns right into the cross section under the first P and terminates.

Click the image to enlarge and see details

\$\endgroup\$
6
  • \$\begingroup\$ Oooh, Piet is always a nice one. And you don't happen to have a working Windows binary of Piet Creator lying around, do you? (I was too lazy to hunt all dependencies and prerequisites just to play around a bit again.) \$\endgroup\$
    – Joey
    Apr 24, 2011 at 21:01
  • \$\begingroup\$ And aren't that actually 400 codels and 57 coding codels? (I don't think we had a consensus how to count Piet here, though) \$\endgroup\$
    – Joey
    Apr 24, 2011 at 21:04
  • 1
    \$\begingroup\$ @Joey I'll see if I can cook up a build of Piet Creator for windows. It's been awhile since I tested it there. You're right about the codels. If I was to lay the program out in a line it would be 57 codels (give or take a few), the version above is more eye friendly (like whitespace in other langs). Perhaps Piet submissions should have both minimal and eye-catching sources. We better decide, because I'm planning many more Piet answers :) \$\endgroup\$
    – Casey
    Apr 24, 2011 at 21:16
  • \$\begingroup\$ Well, you could open a question on meta to ask for clarification how Piet code should be handled :-). I would have submitted Piet solutions too, long ago. Except pietdev was quite buggy and for Piet Creator I needed Qt and a few other things just to build it ;-). And just using a bitmap editor is quite ... cumbersome ... \$\endgroup\$
    – Joey
    Apr 24, 2011 at 21:20
  • \$\begingroup\$ @Joey Piet Creator still needs several important enhancements to be truly awesome, hopefully I can add those soon. I end up using mainly Piet Creator, and then use Paint or the GIMP to move blocks of color around. Pietdev was my main inspiration for PC. Getting some feedback on PC would be great, I'll get on that windows build ASAP. \$\endgroup\$
    – Casey
    Apr 24, 2011 at 23:55
17
\$\begingroup\$

P is for Perl, 10 characters -> Score: 14

print a..z
\$\endgroup\$
1
  • 35
    \$\begingroup\$ What about say a..z? \$\endgroup\$
    – mbx
    Jul 5, 2011 at 14:03
15
\$\begingroup\$

P is for Python 2, 29 chars -> Score: 35

Every few years I come here with an update. See below.

Also I'm proposing the addition of range expressions to Python over here with demo code here. That would allow us to make an even more compact answer.

Mar 2023: 29 chars

I realize the question says the output can be uppercase which allows us to shave off another char. It is quite ridiculous I didn't see that before.

print bytearray(range(65,91))

Nov 2019: 30 chars

I did it, after 8 years I realized there is a shorter way in python 2!

print bytearray(range(97,123))

Previous code that was as big as trivial print:

Jul 2011: 33 chars

print'%c'*26%tuple(range(97,123))

print'abcdefghijklmnopqrstuvwxyz'

Edit: Check out the breakthrough with Python 3 where I also found a solution smaller than trivial print: https://codegolf.stackexchange.com/a/195165/2212

\$\endgroup\$
1
  • 2
    \$\begingroup\$ This is the same length as print'abcdefghijklmnopqrstuvwxyz'... \$\endgroup\$
    – nneonneo
    Jul 14, 2014 at 22:45
14
\$\begingroup\$

K is for K, 12 characters -> Score: 13

`0:_ci97+!26
\$\endgroup\$
4
  • \$\begingroup\$ Surely you can adapt one of your solutions to A+, right? \$\endgroup\$
    – Joey
    Apr 19, 2011 at 6:48
  • \$\begingroup\$ Setting up A+ is a little funky. I've done it before but I don't really feel like it. (Owl, newLISP and zshell were all turnkey.) \$\endgroup\$ Apr 19, 2011 at 6:53
  • 3
    \$\begingroup\$ i assume that's k2 or k3. in k4/q, you can do it in 7 chars with 1 .Q.a;. \$\endgroup\$ Jan 20, 2014 at 10:10
  • \$\begingroup\$ you don't need `0: or 1@ in codegolf \$\endgroup\$
    – ngn
    Jan 24, 2018 at 15:34
14
\$\begingroup\$

Y is for Yoix, 44 characters → Score: 48

int x;for(;++x<27;)yoix.stdio.putchar(96+x);
\$\endgroup\$
0
13
\$\begingroup\$

W is for Whitespace, 72 characters -> Score: 82

enter image description here

[Sp][Sp][Sp][Tab][Tab][Sp][Sp][Sp][Sp][Tab][LF][LF][Sp][Sp][Tab][Tab][LF][Sp][LF][Sp][Tab][LF][Sp][Sp][Sp][Sp][Sp][Tab][LF][Tab][Sp][Sp][Sp][Sp][LF][Sp][Sp][Sp][Sp][Tab][Tab][Tab][Tab][Sp][Tab][Tab][LF][Tab][Sp][Sp][Tab][LF][Tab][Sp][Sp][Sp][LF][LF][Sp][LF][Tab][Tab][LF][LF][Sp][Sp][Sp][Sp][LF][LF][LF][LF]

I spent ages getting this stupid thing to work last night and then found that whitespace doesn't show as code here! Then, while I was sulking, my Internet connection died. So, I'm posting it now just so I didn't waste an hour of my life last night getting it to work.

\$\endgroup\$
2
  • 7
    \$\begingroup\$ I would have thought that it was obvious from the now-deleted comment along with my solution that I've never written any Whitespace before. Apparently not. \$\endgroup\$
    – Gareth
    Apr 24, 2011 at 10:04
  • \$\begingroup\$ @Mego Any chance we can have my name taken off this since I had nothing at all to do with it? \$\endgroup\$
    – Gareth
    Dec 30, 2018 at 22:55
11
\$\begingroup\$

A is for APL,  14  11 chars/bytes* → score 14

⎕UCS 96+⍳26

This works at least in Dyalog and Nars2000.


* APL can be written in its own (legacy) single-byte charset that maps APL symbols to the upper 128 byte values. Therefore, for the purpose of scoring, a program of N chars that only uses ASCII characters and APL symbols can be considered to be N bytes long.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ ⎕a works in APLX. \$\endgroup\$
    – Adám
    May 8, 2017 at 5:37
  • \$\begingroup\$ uppercase and trailing newline optional so ⎕A works. \$\endgroup\$
    – Adám
    Oct 2, 2019 at 17:11
10
\$\begingroup\$

G is for Golfscript, 8 characters -> Score: 18

123,97>+
\$\endgroup\$
10
\$\begingroup\$

R is for R, 19 → Score: 20

cat(letters,sep="")
\$\endgroup\$
3
  • \$\begingroup\$ Alternatively (20 characters): cat(letters,sep="") \$\endgroup\$
    – Paolo
    Mar 7, 2012 at 16:10
  • \$\begingroup\$ Is not letters good enough? I don't see the spec specifying the output must be a contiguous string. Sure, the example given is in that form, but the 'trailing newline is optional'? \$\endgroup\$
    – Gaffi
    Aug 10, 2016 at 22:56
  • \$\begingroup\$ @Gaffi: I believe I held other languages to the same standard in this thread, namely, the output must be "abc...xyz" exactly, with no intervening characters). I suppose I could change the rule and win my own contest, but that wouldn't be very fun. \$\endgroup\$
    – Joey Adams
    Aug 14, 2016 at 1:44
7
\$\begingroup\$

R is for Ruby, 13 characters -> Score: 17

A Ruby 1.9 solution Matma Rex came up with:

print *?a..?z

My original Ruby 1.8 solution (15 characters -> Score: 19):

$><<[*'a'..'z']
\$\endgroup\$
6
  • \$\begingroup\$ This one doesn't match the criteria? Output contains additional characters. Also, if it's OK, it'd be $><<[*?a..?z] for Ruby 1.9 (shaving off 2 chars). \$\endgroup\$
    – Matma Rex
    Apr 19, 2011 at 17:17
  • 1
    \$\begingroup\$ Shortest correct version I can conceive is print *?a..?z. It's the same length and the one I suggested above. We can't use $><< because << has some weird precedence rules and everything blows up. We can't use p or puts instead of print since they print every letter on separate line. \$\endgroup\$
    – Matma Rex
    Apr 19, 2011 at 17:26
  • \$\begingroup\$ Sorry, should've mentioned that this is for Ruby 1.8. In Ruby 1.8, Array#to_s is the same as Array#join, so it'll just print the alphabet with no extra characters. But your 1.9 solution is indeed shorter. \$\endgroup\$
    – Ventero
    Apr 19, 2011 at 18:50
  • \$\begingroup\$ Output is: codepad.org/atGFGVuQ \$\endgroup\$ Jul 5, 2011 at 15:54
  • \$\begingroup\$ @George: Your output is from Ruby 1.8 (which can be verified here: codepad.org/pvyqzaPP). As the post mentions, this is a solution for Ruby 1.9. \$\endgroup\$
    – Ventero
    Jul 5, 2011 at 18:14
7
\$\begingroup\$

F is for Fish (><>), 19 chars -> Score: 23

Because it's a damn beautiful language!

30"`"1+::o&p&"y"(?;
\$\endgroup\$
4
  • \$\begingroup\$ Isn't this answer scored 22 because <>> is only three characters long, not four. Is there a reason you used the longer name in the score. \$\endgroup\$ Oct 15, 2015 at 18:08
  • \$\begingroup\$ @ppperry Well the language name can't both start with an F and be <><. \$\endgroup\$
    – flornquake
    Jan 5, 2016 at 18:38
  • 1
    \$\begingroup\$ The name of the language is ><>, not <>< \$\endgroup\$ Jun 19, 2016 at 16:48
  • \$\begingroup\$ This doesn't seem to work- it just prints a. tio.run/##S8sszvj/39hAKUHJUNvKKl@tQE2pUknD3vr/fwA \$\endgroup\$
    – Chris
    Jun 6, 2019 at 15:18
7
\$\begingroup\$

D is for dc, 17 characters → Score: 19

97[dP1+dBD>x]dsxx
\$\endgroup\$
2
  • \$\begingroup\$ outputs "ab" and quits in dc version 1.06.95 \$\endgroup\$
    – Wossname
    Jun 6, 2017 at 13:49
  • \$\begingroup\$ @Wossname echo '97[dP1+dBD>x]dsxx' | dc does work in dc version 1.07.1 \$\endgroup\$
    – BlackCap
    Jan 27, 2018 at 17:58
6
\$\begingroup\$

O is for Owl, 11 characters -> Score: 14

a[%)1+%z>]!
\$\endgroup\$
6
\$\begingroup\$

S is for Scala, 16 chars => score 21

'a'to'z'mkString

18 chars => score 23

'a'to'z'mkString""

22 chars => score 27

('a'to'z')map(print _)

\$\endgroup\$
6
\$\begingroup\$

B is for Befunge → 18 characters

"a"::,1+10p"y"`#@_
\$\endgroup\$
1
6
\$\begingroup\$

P is for Python 2, 42 characters → Score: 48

import string
print string.ascii_lowercase
\$\endgroup\$
2
  • 6
    \$\begingroup\$ print 'abcdefhijklmnopqrstuvwxyz' \$\endgroup\$ Jul 4, 2011 at 10:15
  • 7
    \$\begingroup\$ print'abcdefhijklmnopqrstuvwxyz' \$\endgroup\$
    – nneonneo
    Jul 14, 2014 at 22:45
6
\$\begingroup\$

C is for C, 36 35 characters → Score: 36

main(a){for(;putchar(a+++64)-90;);}
\$\endgroup\$
4
  • \$\begingroup\$ You can drop 2 characters by assuming a (argc) equals one rather than having to initialize it. \$\endgroup\$
    – Joey Adams
    Apr 18, 2011 at 22:35
  • 1
    \$\begingroup\$ But this doesn't even compile... \$\endgroup\$
    – user1406
    Apr 24, 2011 at 14:33
  • 1
    \$\begingroup\$ Best I could get to compile was 59, or 42 without the include: #include<stdio.h> main(){for(int a=27;--a;)putchar(96+a);} \$\endgroup\$
    – user1406
    Apr 24, 2011 at 14:41
  • \$\begingroup\$ Daniel, it works with MSVC 10 here. \$\endgroup\$
    – Joey
    Apr 24, 2011 at 20:51
5
\$\begingroup\$

L is for Logo, 26 characters → Score: 30

for[i 97 122][type char i]
\$\endgroup\$
5
\$\begingroup\$

P is for Python 2, 41 characters → Score: 47

print''.join(chr(i+97)for i in range(26))
\$\endgroup\$
5
\$\begingroup\$

P is for PowerShell, 15 characters → Score: 25

-join('a'..'z')
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Hmm, not sure whether to make this W or P. \$\endgroup\$
    – Joey Adams
    Apr 18, 2011 at 21:11
  • 1
    \$\begingroup\$ Technically it's W, since the correct name of the language (and product) is Windows PowerShell. Yes, it bugs me too. \$\endgroup\$
    – Joey
    Apr 18, 2011 at 21:12
  • \$\begingroup\$ The language is now just PowerShell, with the products being Windows PowerShell or PowerShell Core, so this now has a score of 32. \$\endgroup\$
    – SE is dead
    Oct 31, 2019 at 1:56
  • \$\begingroup\$ @dorukayhan: When using PowerShell Core we can also shorten it to -join('a'..'z') which results in 25. \$\endgroup\$
    – Joey
    Oct 31, 2019 at 20:10
4
\$\begingroup\$

B is for bc - 2 + 28 = 30

"abcdefghijklmnopqrstuvwxyz"
\$\endgroup\$
4
\$\begingroup\$

J is for J, 14 characters -> Score: 15

echo u:97+i.26
\$\endgroup\$
2
  • \$\begingroup\$ Why bother with echo? u:97+i.26 is a complete J program. \$\endgroup\$ Apr 26, 2011 at 5:34
  • 6
    \$\begingroup\$ Because that has no output when run as a script (for me, anyway). \$\endgroup\$ Apr 26, 2011 at 6:06
4
\$\begingroup\$

T is for Thue, 35 characters → Score: 39

0::=~abcdefghijklmnopqrstuvwxyz
::=
0
\$\endgroup\$
4
\$\begingroup\$

A is for AppleScript, 41 -> Score: 52

display alert"abcdefghijklmnopqrstuvwxyz"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I know this is a long time since posting, but you can use "abcdefghijklmnopqrstuvwxyz", since the return value is output to the results pane. \$\endgroup\$ Feb 3, 2016 at 20:45
4
\$\begingroup\$

M for Matlab, 13 chars, Score 19

disp('a':'z')

M for Matlab, 18 chars, Score 24

disp(char(97:122))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I don't have matlab at hand but I think you need disp(..) to prevent this outputting ans = . \$\endgroup\$
    – Nabb
    Apr 24, 2011 at 6:06
  • \$\begingroup\$ Correct, changed in the answer. \$\endgroup\$
    – jpjacobs
    Apr 26, 2011 at 8:31
4
\$\begingroup\$

B is for BrainF***, 38 + 9 = 47

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

Can be reduced to 31+9 = 40, if cells wrap around at 256:

++[>+>++<<+++++]>----->[<.+>++]
\$\endgroup\$
0
4
\$\begingroup\$

B is for Bash: 4 + 16 = 20

printf %s {a..z}

or 15 with just:

echo {a..z}

if output of the form a b c ... is allowed (as seen in many other answers).

\$\endgroup\$
1
  • \$\begingroup\$ I don't think so. Linefeed is optional, output is "abcdefghijklmnopqrstuvwxyz" \$\endgroup\$ Apr 19, 2011 at 4:30
3
\$\begingroup\$

I is for Inform 6, 41 + 6 = 47

[Main i;for(i=26:i--:)print(char)'z'-i;];
\$\endgroup\$
3
\$\begingroup\$

U is for Unlambda - 8 + 79 = 87

``````````````````````````.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.zr
\$\endgroup\$
3
\$\begingroup\$

H is for Haskell, 21 characters → Score: 28

main=putStr['a'..'z']
\$\endgroup\$
1
2 3 4 5 6

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.