Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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

(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.
  • The programming language should have existed prior to the writing of this post, on this eighteenth of April 2011.
  • 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.

share|improve this question
13  
It's not my lord, what should I do? –  Joey Apr 18 '11 at 20:56
    
Are we allowed to print junk to stderr? –  Peter Taylor Apr 18 '11 at 22:02
    
@Peter Taylor: Go nuts. To answer your question, yes, printing junk to stderr is fine (as long as stdout is correct). –  Joey Adams Apr 18 '11 at 22:05
    
So much for points. This is a wiki now. –  Joey Adams Apr 18 '11 at 22:45
6  
Joey: I flagged it for moderator attention regarding CW, for the following reasons: (1) The task is trivial in any programming language, there is no challenge nor any difficulty. (2) It is more akin to a collection of implementations in as many languages as possible, not actually a real contest (honestly: there isn't much room to golf here). Since how the task is designed it encourages plenty of answers that can be churned out in dozens I didn't think this was something that should follow the usual rules of a golf or challenge. Apparently at least one mod agrees with me. –  Joey Apr 18 '11 at 23:11

78 Answers 78

B is for Bash: 4 + 16 = 20 or 15

printf %s {a..z}

or just:

echo {a..z}

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

share|improve this answer
    
I don't think so. Linefeed is optional, output is "abcdefghijklmnopqrstuvwxyz" –  user unknown Apr 19 '11 at 4:30

L is for LUA: 3 + 40 = 43

repeat n=1+(n or 96)print(("%c"):format(n))until(n>122)

-> 55

repeat n=1+(n or 96)print(string.char(n))until(n>122)

-> 53

for i=97,122 do print(string.char(i))end

-> 40

share|improve this answer
    
Please keep the code blocks clean, so user scripts like Code Golf UserScript Enhancement Pack which insert code block sizes in the document can show correct values. I mean, please post separate solutions in separate code blocks and specify the code length outside the code block. –  manatwork Oct 20 '14 at 10:17
1  
Thanks. This way is much easier to spot out count mistakes: i.stack.imgur.com/qezQZ.png Seems you included in both cases the final newline character in the count. That is unnecessary. –  manatwork Oct 20 '14 at 10:29

P is for PostScript, 29 chars → Score: 39

(abcdefghijklmnopqrstuvwxyz)=
share|improve this answer

B, 45 -> Score: 46

main(){auto i;i=95;while(i++<122)putchar(i);}
share|improve this answer

m4

abcdefghijklmnopqrstuvwxyz

(Hey, shinh lists it as a supported language)

share|improve this answer

Xtal

"abcdefghijklmnopqrstuvwxyz".p;
share|improve this answer
    
Awesome, thanks for filling in X with something interesting! I guess you mean Gnu Xtal System (found with a Google search), but I'm not sure. Could you add a link? –  Joey Adams Apr 18 '11 at 23:37
    
It's actually Xtal as used in golf.shinh.org: code.google.com/p/xtal-language , you can see some post-mortems at golf.shinh.org/l.rb?xtal –  ninjalj Apr 18 '11 at 23:48

E, 28 characters → Score: 29

for x in 0..25{print('a'+x)}
share|improve this answer

Q is for QBasic, 29 characters → Score: 35

?"abcdefghijklmnopqrstuvwxyz"

Untested, but programming is like riding a bike, right?

share|improve this answer
    
You can get injured while riding a bike. I dare you to drop that space before the quotation mark. –  Joey Adams Apr 18 '11 at 22:38
    
Nah, that would look too much like "optimized" BASIC programs... –  ninjalj Apr 18 '11 at 22:43
2  
You can use ? instead of print ... –  Joey Apr 18 '11 at 23:06
    
Feel free to edit, I haven't programmed in BASIC for more than a decade. –  ninjalj Apr 18 '11 at 23:11
    
Done :-). Tested now, even. –  Joey Apr 18 '11 at 23:42

N is for newLISP, 35 characters -> Score: 42

(print"abcdefghijklmnopqrstuvwxyz")
share|improve this answer

L#, 28 characters → Score: 30

"abcdefghijklmnopqrstuvwxyz"
share|improve this answer

Z is for zsh, 31 characters -> Score: 38

echo abcdefghijklmnopqrstuvwxyz
share|improve this answer

F is for False, 17 characters -> Score: 22

97[$123\>][$,1+]#
share|improve this answer

U is for Unicon, 50 + 6 = 56

procedure main();every writes(char(97 to 122));end
share|improve this answer

c,34 characaters -> score : 35

main(a){for(;a++<27;putch(95+a));}
share|improve this answer
1  
putch isn't in standard C, and isn't present on my system. Thus, I'm not going to add this to the rankings, at least not under C. Arguably, you could change the language name to "VC" (for (Microsoft) Visual C) and put it under V ;-) –  Joey Adams Apr 20 '11 at 16:35
    
@Joey: Shouldn't any C example be classified under the compiler name, then? –  Joey Apr 24 '11 at 21:11
    
@Joey, @avinashse: I went ahead and reluctantly added this to the scoreboard. –  Joey Adams Apr 25 '11 at 18:10
1  
talking about vc++... if you set the entry point to f and the subsystem to console, you get a breathtaking 1 + 30 = 31 f(a){26-a&&f(putch(a+97)-96);} :) –  bebe Jul 14 '14 at 20:13

G is for Groovy 25 -> Score: 31

('a'..'z').each{print it}
share|improve this answer

Q is for Q (4 characters) -> Score 5

.Q.a 

Output:

"abcdefghijklmnopqrstuvwxyz"

If this isn't valid base don the rules I'm afraid Q doesn't actually permit strings to be outputted. The closest it can get is to cast as a symbol:

`$.Q.a

Output:

`abcdefghijklmnopqrstuvwxyz
share|improve this answer
    
What is the Q programming language? Could you provide a link? –  Joey Adams Mar 7 '12 at 16:58
    
Yeah sure here is a link to the wikipedia page for the language, and the trial version can be downloaded here for personal/non-commercial use. –  sinedcm Mar 8 '12 at 12:29
    
Nice find! I really want to put this on the scoreboard and accept it, but it doesn't match the required output format. Is there a way to get rid of the quote characters? The current winner has a score of 13, so you have 7 characters of breathing room. –  Joey Adams Mar 8 '12 at 14:28
    
Unfortunately it isn't possible in Q, How about a 2 point penalty for the extra characters in the output? :) –  sinedcm Mar 8 '12 at 16:43
    
For 8 characters, -1@.Q.a; –  slackwear May 30 '12 at 14:25

A is for awk: 37 characters -> score 40

BEGIN{for(i=96;i++<122;)printf"%c",i}
share|improve this answer

B is for Batch File, 31 characters → Score: 41

echo abcdefghijklmnopqrstuvwxyz
share|improve this answer

PHP, 26 characters -> Score: 29

abcdefghijklmnopqrstuvwxyz
share|improve this answer

Ada, 92 characters -> Score: 95

with ada.text_io;use ada.text_io;procedure a is begin put("abcdefghijklmnopqrstuvwxyz");end;
share|improve this answer

F is for F#, 36 characters -> Score: 38

printf("abcdefghijklmnopqrstuvwxyz")
share|improve this answer

Wake

all: "abcdefghijklmnopqrstuvwxyz"
share|improve this answer

E, 26 characters → Score: 27

for x in'a'..'z'{print(x)}

This is based off Joey's answer.

share|improve this answer

Python 36+6 = 42

print''.join(map(chr,range(97,123)))

Not the shortest...

share|improve this answer

Tcl - 31 + 3 = 34

puts abcdefghijklmnopqrstuvwxyz
share|improve this answer

C++, 32 + 3penalty = 35

I could not find C++. So this is my option for it:

char a=96;while(a++<122)cout<<a;

the output is:

abcdefghijklmnopqrstuvwxyz

PS. It's my first golf, pls comment if i did something wrong

share|improve this answer

Forth, 29 + 5 Score: 34

: a 123 97 do i emit loop ; a

Previous (Forth, 48 + 5 Score: 53 (unclean score = 48))

: a 97 begin dup emit 1 + dup 123 = until drop ;

This is the clean version.

: a 97 begin dup emit 1 + dup 123 = until ;

The second one leaves stuff on the stack.

a 
abcdefghijklmnopqrstuvwxyz  ok
share|improve this answer
    
Or even : b ." abcdefghijklmnopqrstuvwxyz" ; at 36 characters –  leancz Dec 16 '13 at 12:17
    
If uppercase output were permitted then you could drop a character with 91 65 do ... I have to say you should probably include the word a (+2 chars) at the end of your line for these to be "programs", otherwise nothing is actually executed or printed. :( I do like golfing in Forth but it often carries that penalty! –  Darren Stone Dec 17 '13 at 9:46
    
@DarrenStone OK, I've changed it - I do wonder about that though as I see, for example C source code in code golf that would also not print anything without being compiled and executed at a command line. I'm just starting out at code golf and trying to remember Forth from my youth. It is fun. –  leancz Dec 17 '13 at 10:12
    
Yeah, it sucks that control structures (IF, LOOP, etc.) can't be used in interpreted mode, only in a word definition. Shaving down your string constant idea, the following would be a program and requires no word definition/execution penalty. ." abcdefghijklmnopqrstuvwxyz" Unfortunately, it's 30 chars! Happy Forthing! –  Darren Stone Dec 17 '13 at 10:21

P is for posting an answer way too late 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]$_}
share|improve this answer

P is for PHP - 33 characters - Score: 36

echo implode("",range("a", "z"));
share|improve this answer

C++: 32+3 = 35

char c=96;while(c++<122)cout<<c;
share|improve this answer
    
I almost want to score this as 32, given that your code contains "c++". Alas, I didn't put this in the original rules. –  Joey Adams Jul 15 '14 at 20:44
    
@JoeyAdams You're right, I corrected it :) –  cagirici Jul 15 '14 at 21:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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