71
\$\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 '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
    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
  • 6
    \$\begingroup\$ Is *0*5AB1E the same as *o*sabie :P? \$\endgroup\$ Jun 6 '19 at 14:58

148 Answers 148

1
\$\begingroup\$

S is for SmileBASIC, 39 37 bytes

FOR I=65TO 90?CHR$(I);:NEXT
\$\endgroup\$
3
  • 1
    \$\begingroup\$ I do not believe you have properly read the scoring rules for this challenge. Your score is the length of your code plus the length of the language name. \$\endgroup\$
    – Pavel
    Feb 3 '17 at 6:25
  • \$\begingroup\$ Fixed, sorry. (padding) \$\endgroup\$
    – snail_
    Feb 3 '17 at 13:49
  • \$\begingroup\$ You can save 2 characters by adding 65 to the start/end of the loop. \$\endgroup\$
    – 12Me21
    Feb 3 '17 at 13:58
1
\$\begingroup\$

S is for SMBF, 10 chars -> Score: 14

SMBF stands for Self-modifying Brainf***, and both names are used interchangeably. The original interpreters were named smbf.c and smbf.rb.

\x1a is a hex literal (a single non-printable ASCII character) for the decimal number 26.

<[-<.+>]a\x1a

The \x1a is used as a loop counter. a is printed and incremented each time.

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

R is for R, 17 bytes Score -> 18

intToUtf8(97:122)

Try it online!

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

M is for M, 20 characters → Score: 21

let s={"a".."z"}in s

(M language reference)

\$\endgroup\$
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\$
5
  • 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\$ Sep 22 '19 at 18:41
  • \$\begingroup\$ good call @pppery \$\endgroup\$
    – heratyian
    Sep 23 '19 at 17:27
  • \$\begingroup\$ You should update the bytecount after golfing your answer. \$\endgroup\$ Sep 23 '19 at 19:05
1
\$\begingroup\$

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

for($,65,90,$asCharacter print)
\$\endgroup\$
0
1
\$\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
  • 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\$ Sep 26 '19 at 9:05
1
\$\begingroup\$

F is for Fish, 16 bytes; score 20

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

Wake, 33 bytes, score 37

all: "abcdefghijklmnopqrstuvwxyz"
\$\endgroup\$
1
\$\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\$
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\$
0
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\$
1
\$\begingroup\$

Jelly, 2 bytes, score: 7

Jelly has a built-in.

Øa

Try it online!

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

Pyth, 1 byte, score: 5

Pyth has a shorter built-in than Jelly.

G

Try it online!

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

Pip, 1 byte, score: 4

z

Try it online!

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

V (vim), 3 bytes, score: 4

¬az

Try it online!

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

Wren, 58 bytes

The iteration method

System.printAll((97..122).map{|i|String.fromCodePoint(i)})

Try it online!

Wren, 42 bytes

The boring method

System.print("abcdefghijklmnopqrstuvwxyz")

Try it online!

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

Befunge-93, 33 bytes

I thought I could beat Brachylog... never mind.

"a">:,1+:"{"-#v_@
   ^          <

Try it online!

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

Ly, 11 bytes -> Score: 13

'Rrp['`+o]

Try it online!

Explanation

'          Push 26
  R          0-range
   r         reverse stack
    p        Pop 0
     ['`+o] Output the whole stack, added by 97
\$\endgroup\$
1
\$\begingroup\$

F is for Foo, 17 bytes, score: 20

&65>&26(-1<$c+1>)

Try it online!

Ties the Fish answer.

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

DOS, x86, 10 bytes + 3 = 13

This answer is fundamentally the same as Peter Cordes' x86, but uses DOS for I/O and as the "framework" of sorts to be able to "print[s] the alphabet" per the challenge description.

One could attempt to make the case that since this uses DOS API for said I/O that it one-step higher level than just x86. After all, DOS is an operating system, programming API, interpreter and framework all rolled into one, right? Also most every submission here eventually gets compiled down to machine code eventually to run, so aren't we really considering the submission to be the highest level required to produce the desired output?

Okay, feel free to call this rationalization baloney. It's not shorter than Peter's earlier x86 so just thought I'd throw in another take, competing or not! :)

Binary:

00000000: b061 cd29 403c 7a7e f9c3                 .a.)@<z~..

Listing:

B0 61       MOV  AL, 'a'        ; start at 'a'
    CLOOP:
CD 29       INT  29H            ; write AL to console
40          INC  AX             ; increment letter
3C 7A       CMP  AL, 'z'        ; is <= 'z'?
7E F9       JLE  CLOOP          ; if so, keep looping
C3          RET                 ; return to DOS

enter image description here

And yes "DOS" can be considered a generic term for other different non-IBM PC Disk Operating Systems. However Wikipedia's entry for "DOS" specifically refers to IBM DOS and describes DOS as "a common shorthand for disk-based operating systems on IBM PC compatibles".

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

ink, 26 bytes, score: 29

Glad to hear that newer languages are allowed.

abcdefghijklmnopqrstuvwxyz

Try it online!

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

Husk, 4 bytes → Score: 8

…"ab

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ …"ab saves a byte. \$\endgroup\$
    – Zgarb
    Jun 21 '20 at 16:44
1
\$\begingroup\$

Ni, 13 bytes, score: 15

#61>#1a{<!+>}

Try (the snippet) online!

Explanation

#61           Set Current as 'a'
   >          Move the pointer right
    #1a       Set current as 26
       {      Repeat 26 times:
        <         Move left
         !        Print the letter
          +       Increment the letter
           >      Move right
            }     (Automatically decrement counter)
\$\endgroup\$
1
\$\begingroup\$

W, 3 bytes (score: 4)

Near built-in solution, intended to beat Wake.

'zk

Explanation

'z   Push the character z
  k  Generate a downwards character range for that character.
\$\endgroup\$
1
\$\begingroup\$

Q is for QuadR, 26 bytes, Score: 31

abcdefghijklmnopqrstuvwxyz

Try it online!

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

V for Vyxal, 2 bytes, score 2+5=7

ka

Try it Online!

Dunno someone has posted this already

\$\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\$

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.