70
\$\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\$
  • 1
    \$\begingroup\$ Are we allowed to print junk to stderr? \$\endgroup\$ – Peter Taylor Apr 18 '11 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 '11 at 22:05
  • \$\begingroup\$ Is it OK to print the alphabet IN BIG LETTERS? \$\endgroup\$ – dorukayhan wants Monica back Jun 21 '16 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 '17 at 19:53
  • 4
    \$\begingroup\$ Is *0*5AB1E the same as *o*sabie :P? \$\endgroup\$ – Magic Octopus Urn Jun 6 at 14:58

133 Answers 133

1
\$\begingroup\$

Z is for Z80Golf, 9 bytes + 7 = 16

00000000: 3e61 061a ff3c 10fc 76                   >a...<..v

Try it online!

According to the Web Archive, Z80Golf code golf machine was created (at least) in December 2007.

Disassembly

start:
  ld a, 97  ; the char to print
  ld b, 26  ; loop count
loop:
  rst $38   ; 1-byte alias for putchar
  inc a
  djnz loop ; decrement b and jump to `loop` if nonzero
  halt      ; end program
\$\endgroup\$
1
\$\begingroup\$

S is for Swift, 76 characters -> Score: 81

var s=""
for i in 97...122{s.append((Character(UnicodeScalar(i))))}
print(s)
\$\endgroup\$
  • 2
    \$\begingroup\$ Isn't it easier to just print a string containing the alphabet? \$\endgroup\$ – acrolith Oct 21 '16 at 16:41
  • \$\begingroup\$ Of course, but that just wouldn't be as fun \$\endgroup\$ – heratyian Oct 21 '16 at 17:57
  • \$\begingroup\$ my_string could be reduced to one letter. \$\endgroup\$ – pppery Sep 22 at 18:41
  • \$\begingroup\$ good call @pppery \$\endgroup\$ – heratyian Sep 23 at 17:27
  • \$\begingroup\$ You should update the bytecount after golfing your answer. \$\endgroup\$ – pppery Sep 23 at 19:05
1
\$\begingroup\$

I is for Io, 31 characters -> Score: 33

for($,65,90,$asCharacter print)
\$\endgroup\$
1
\$\begingroup\$

F is for Fish, 16 bytes; score 20

"a"r:o1+:"{"=?;r
\$\endgroup\$
1
\$\begingroup\$

X is for x86, 9 bytes + 3 -> score 12

(or "x86 machine code" for 9 + 16 = 25)

b0 61 aa 40 3c 7a 76 fa  c3

This is a function, callable with void alpha(char edi[26]), like the x86-64 System V calling convention but in 32-bit mode. Or 16-bit mode (where 40 decodes as inc ax, otherwise the same).

The question says "program" that "prints", and this is neither of those things. I'm not sure this should count. Making a DOS .com executable out of this would take a few extra bytes, or the .text section of a Linux executable, including print and exit system calls. But there are several other answers (like some C++ ones) that are merely snippets that wouldn't even compile without #include<iostream> and int main(){.

I'm just going to follow modern codegolf defaults for I/O methods (Default for Code Golf: Input/Output methods) which include returning a string in the caller's buffer.


An x86-64 version would cost 1 extra byte for inc al or inc eax, and 3 extra characters in the language name. I could call it x64 but that implies Windows where the standard calling convention doesn't use RDI. But that's irrelevant, this is an asm / machine-code answer which doesn't care about being called from other languages. So anyway, I could say "x64" for a 10 + 3 = 13 version, but I hate that name because it goes with using "x86" to mean specifically 32-bit, instead of the whole ISA.

Ungolfed:

                machine code     NASM/FASM source
     1                         alpha:
     2 00000000 B061               mov  al, 'a'
     3                         .loop:               ; do {
     4 00000002 AA                 stosb              ; *edi++ = al
     5 00000003 40                 inc  eax           ; more compact than inc al
     6 00000004 3C7A               cmp  al, 'z'
     7 00000006 76FA               jbe  .loop       ; }while(al<='z')
     8 00000008 C3                 ret 

Try it online! with a FASM _start caller.


Justification: "x86 machine code" is as much a description as a name. Machine code is something you can program in and can be considered a family of languages. But those languages don't usually have names other than the ISA. I'd usually say "x86 32-bit machine code" when posting an answer like this, but that's just to make it clear the answer is the machine code, not the asm source text in the same listing.

Out of all ISAs, x86 is clearly recognizable as the name of this one. It's not a language that people regularly program in directly; usually we generate it from assembly language (or higher level languages).

"IA" (Intel Architecture) or "IA-32" are other common names for the ISA, so I could argue for a score of 11 in the letter "I". (But the only "x" answer is xtal at 35, so posting this as x86 is a more useful answer for reducing the total sum length across all letters.

Of course "x86" can be considered ambiguous between the machine code and assembly language. And without context it's not obviously a programming language because it's better known as the name of an ISA.

\$\endgroup\$
  • \$\begingroup\$ I like this answer, it's a great intro to x86 assembly. I can't believe how few bytes each instruction takes. \$\endgroup\$ – Joey Adams Oct 7 at 16:39
  • \$\begingroup\$ @JoeyAdams: There are special-case short forms for the accumulator (EAX / AX / AL), and instructions with implicit operands like stosb. In "normal" 32-bit code most instructions are 2 to 4 bytes long, or longer with larger addressing modes or SIMD opcodes... And 64-bit code needs a REX prefix on many instructions, making the avg instruction length more like 4 in compiler output. See Tips for golfing in x86/x64 machine code I just updated the source version with comments for the benefit of people who don't know x86 asm, since you mentioned it :P \$\endgroup\$ – Peter Cordes Oct 7 at 16:44
  • \$\begingroup\$ But yes, ISAs with variable-length instructions optimize for the most common cases. Original 8086's main bottleneck was code-fetch from memory so they put some care into that design. It's evolved over time into an ugly Frankenstein's monster though, with much lack of long-term thinking about ISA extensions. :( See Agner Fog's 2009 blog post, Stop the instruction set war \$\endgroup\$ – Peter Cordes Oct 7 at 16:50
1
\$\begingroup\$

Wake, 33 bytes, score 37

all: "abcdefghijklmnopqrstuvwxyz"
\$\endgroup\$
1
\$\begingroup\$

D is for D2, 2 + 6 = 8

!a[.+]

!a expand to 10 +, setting the current cell to 10 (a in base 36), and [.+] print the current cell as a base 36 string and increment the cell. Since the maximum value a cell can hold is 35, at 36 the cell is zeroed and the loop stop.

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

P is for Pyth, 1 character -> Score: 5

G

Try it out!

That's it - just 1 letter. This is how it works:

  • The variable G is by default initialised to abcdefghijklmnopqrstuvwxyz in this language.
  • By default, the value returned by a program is printed out to the standard output.
\$\endgroup\$
0
\$\begingroup\$

vimscript

What does output mean?

Assuming output to the current vim buffer is ok:

:norm aabcdefghijklmnopqrstuvwxyz

Otherwise, output to stdout:

:!echo abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
0
\$\begingroup\$

AWK,33+3(Penalty)

END{for(;i<26;)printf"%c",97+i++}
\$\endgroup\$
0
\$\begingroup\$

T is for TI-BASIC, 27 + 8 = 35

"ABCDEFGHIJKLMNOPQRSTUVWXYZ

Can be run from command line, as a standalone program, or called as a function.

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

S is for Scala, Score: 40

print("abcdefghijklmnopqrstuvwxyz")
\$\endgroup\$
0
\$\begingroup\$

B is for Bash, 25 bytes

echo {a..z}|tr -d ' '

(21 bytes of code plus 4 for the language name)

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

R is for REXX, 15 characters → Score: 19

say xrange(a,z)
\$\endgroup\$
0
\$\begingroup\$

U is for uBASIC, 36 bytes → Score: 42

1 PRINT "abcdefghijklmnopqrstuvwxyz"

Try it online!

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

V is for VBA, 28 + 3 = 31

Anonymous VBE immediate window function that takes no input and outputs abcdefghijklmnopqrstuvwxyz to the VBE immediate window.

The two solutions below are of equal length and produce the same output

For i=97To 122:?Chr(i);:Next

Or

?"abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
0
\$\begingroup\$

U is for uBASIC, 30 + 6 = 36

Anonymous function that takes no input and outputs abcdefghijklmnopqrstuvwxyz

0?"abcdefghijklmnopqrstuvwxyz"

Try it online!

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

S is for SmileBASIC, 27 bytes + 10 = 37

FOR I=65TO 90?CHR$(I);
NEXT

Prints the alphabet in uppercase. (I'm not sure whether this is allowed, but other people are doing it so...)

Just 1 character shorter than the (even more) boring answer:

?"abcdefghijklmnopqrstuvwxyz
\$\endgroup\$
0
\$\begingroup\$

F is for FALSE, 15 bytes +5 = 20

97[$'{-][$,1+]#

Doesn't use any letters!

Explanation:

97 {push 97 (ASCII for 'a')}
  [ {function start}
   $'{- {subtract '{' from the current letter}
       ] {function end}
        [ {function start}
         $, {print the current letter}
           1+ {add 1}
             ] {function end}
              # {while loop. Run the second function while the first doesn't return 0}
\$\endgroup\$
0
\$\begingroup\$

P is for Powershell, 19 + 10 = 29

Because I'm bored at the moment, I hope you don't mind if I put up a quick PS that wouldn't have contended anyways...

97..122|%{[char]$_}

Simple char typecasting. You can shave off one byte by doing the alphabet in all caps.

65..90|%{[char]$_}
\$\endgroup\$
  • \$\begingroup\$ The output is wrong. This one outputs the alphabet with one character per line instead of all on one line. \$\endgroup\$ – Joey Oct 31 at 20:26
0
\$\begingroup\$

JavaScript, 34 + 10 = 44

alert('abcdefghijklmnopqrstuvwxyz')
\$\endgroup\$
  • \$\begingroup\$ alert(8337503854730415241050377135811259267835n.toString(36)) ;) \$\endgroup\$ – Kamil Kiełczewski Oct 7 at 19:21
0
\$\begingroup\$

PHP, 26 + 3 = 29

<?=implode('',range(a,z));
\$\endgroup\$
0
\$\begingroup\$

Racket, 46 bytes (score 52)

(for((i 26))(display(integer->char(+ i 97))))
\$\endgroup\$
0
\$\begingroup\$

I is for ICI, 37+3 bytes → 40

printf("abcdefghijklmnopqrstuvwxyz");
\$\endgroup\$
0
\$\begingroup\$

I is for Io, 35+2 bytes → 37

"abcdefghijklmnopqrstuvwxyz"println
\$\endgroup\$
0
\$\begingroup\$

C is for Common Lisp, Score 35 + 11 => 46

(princ"abcdefghijklmnopqrstuvwxyz")

Try it online!

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

H is for HTML -> 4+31

<HTML/>abcdefghijklmnopqrstuvwxyz

ps: browser will interpret the missing end tag

\$\endgroup\$
  • 2
    \$\begingroup\$ ABCDEFGHIJKLMNOPQRSTUVWXYZ is far better at 30. \$\endgroup\$ – Erik the Outgolfer Aug 3 '16 at 9:52
0
\$\begingroup\$

P is for PowerShell, 15 bytes+10 = 25

-join('a'..'z')

Try it online!

Uses the character range feature added in 6.0 to improve upon past answers.

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

Z is for Zsh, 19 characters -> Score: 22

19 character solution thanks to @GammaFunction.

<<<${(j::):-{a..z}}

Another 18 character solution using Perl.

perl -eprint\ a..z
\$\endgroup\$
  • 1
    \$\begingroup\$ Not sure whether that would qualify for Zsh, it's more "Zsh+perl" (which would have a much larger penalty). You can get a pure Zsh answer in 19 characters, though: <<<${(j::):-{a..z}} \$\endgroup\$ – GammaFunction Sep 26 at 9:05
0
\$\begingroup\$

F is for Forth (gforth), 26 + 5 = 31

'{ 'a [do] [i] emit [loop]

Try it online!

Two improvements over the submission by leancz 6 years ago:

  • An ASCII char prefixed with a quote gives the ASCII value of that char. So '{ saves a byte over 123. 'a is just for consistency.
  • The looping words including do and loop can't be used in interpreted mode, but gforth provides interpreted versions surrounded with brackets like [do] and [loop]. If a function uses three or less such words, using interpreted mode saves some bytes, as illustrated below.
\ using compiled mode
: a '{ 'a do i emit loop ; a
\ using interpreted mode
'{ 'a [do] [i] emit [loop]
\$\endgroup\$

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.