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
5  
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
show 9 more comments

63 Answers

up vote 9 down vote accepted

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

`0:_ci97+!26
share|improve this answer
    
Surely you can adapt one of your solutions to A+, right? –  Joey Apr 19 '11 at 6:48
    
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.) –  Jesse Millikan Apr 19 '11 at 6:53
2  
i assume that's k2 or k3. in k4/q, you can do it in 7 chars with 1 .Q.a;. –  Aaron Davies Jan 20 at 10:10
add comment

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

print a..z
share|improve this answer
10  
What about say a..z? –  mbx Jul 5 '11 at 14:03
add comment

Y is for Yoix, 44 characters → Score: 48

int x;for(;++x<27;)yoix.stdio.putchar(96+x);
share|improve this answer
    
+1 Great find ! –  ninjalj Apr 18 '11 at 23:43
add comment

W is for Whitespace, 51 characters -> Score: 61

highlighting

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

[Sp][Sp]
[Sp]
[Sp][Sp][Sp][Sp][Tab][Tab][Tab][Tab][Sp][Tab][Tab]
[Tab][Sp][Sp][Sp][Tab]
[Sp][Sp][Sp][Sp][Sp][Tab]
[Tab][Sp][Sp][Sp][Sp]
[Sp]
[Tab][Tab]
[EOF]
share|improve this answer
    
I've replaced your solution with a golfed version -- please attempt to golf your solution next time. –  Nabb Apr 24 '11 at 5:56
5  
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. –  Gareth Apr 24 '11 at 10:04
add comment

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

123,97>+
share|improve this answer
add comment

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

share|improve this answer
    
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.) –  Joey Apr 24 '11 at 21:01
    
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) –  Joey Apr 24 '11 at 21:04
    
@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 :) –  Casey Apr 24 '11 at 21:16
    
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 ... –  Joey Apr 24 '11 at 21:20
    
@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. –  Casey Apr 24 '11 at 23:55
show 1 more comment

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.

share|improve this answer
add comment

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']
share|improve this answer
    
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). –  Matma Rex Apr 19 '11 at 17:17
1  
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. –  Matma Rex Apr 19 '11 at 17:26
    
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. –  Ventero Apr 19 '11 at 18:50
    
Output is: codepad.org/atGFGVuQ –  Nathan Osman Jul 5 '11 at 15:54
    
@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. –  Ventero Jul 5 '11 at 18:14
show 1 more comment

Smallest Python (33 + 6 -> Score 39)

print'%c'*26%tuple(range(97,123))
share|improve this answer
add comment

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

a[%)1+%z>]!
share|improve this answer
add comment

B is for Befunge

"a"::,1+10p"y"`#@_
share|improve this answer
add comment

P is for Python, 42 characters → Score: 48

import string
print string.ascii_lowercase
share|improve this answer
6  
print 'abcdefhijklmnopqrstuvwxyz' –  Charles Beattie Jul 4 '11 at 10:15
add comment

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

Because it's a damn beautiful language!

30"`"1+::o&p&"y"(?;
share|improve this answer
add comment

P is for Python, 41 characters → Score: 47

print''.join(chr(i+97)for i in range(26))
share|improve this answer
add comment

R is for R, 19 → Score: 20

cat(letters,sep="")
share|improve this answer
    
Alternatively (20 characters): cat(letters,sep="") –  Paolo Mar 7 '12 at 16:10
    
@Paolo: Ah, thanks! –  Joey Adams Mar 7 '12 at 17:03
add comment

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 _)

share|improve this answer
add comment

W is for Windows PowerShell, 22 characters → Score: 40

-join[char[]](97..122)
share|improve this answer
    
Hmm, not sure whether to make this W or P. –  Joey Adams Apr 18 '11 at 21:11
    
Technically it's W, since the correct name of the language (and product) is Windows PowerShell. Yes, it bugs me too. –  Joey Apr 18 '11 at 21:12
add comment

M for Matlab, 13 chars, Score 19

disp('a':'z')

M for Matlab, 18 chars, Score 24

disp(char(97:122))
share|improve this answer
    
I don't have matlab at hand but I think you need disp(..) to prevent this outputting ans = . –  Nabb Apr 24 '11 at 6:06
    
Correct, changed in the answer. –  jpjacobs Apr 26 '11 at 8:31
add comment

C is for C, 36 characters → Score: 37

main(a){for(;++a<28;)putchar(95+a);}
share|improve this answer
    
You can drop 2 characters by assuming a (argc) equals one rather than having to initialize it. –  Joey Adams Apr 18 '11 at 22:35
    
But this doesn't even compile... –  Daniel Apr 24 '11 at 14:33
    
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);} –  Daniel Apr 24 '11 at 14:41
    
Daniel, it works with MSVC 10 here. –  Joey Apr 24 '11 at 20:51
add comment

B is for bc - 2 + 28 = 30

"abcdefghijklmnopqrstuvwxyz"
share|improve this answer
add comment

I is for Inform 6, 41 + 6 = 47

[Main i;for(i=26:i--:)print(char)'z'-i;];
share|improve this answer
add comment

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

echo u:97+i.26
share|improve this answer
    
Why bother with echo? u:97+i.26 is a complete J program. –  Gregory Higley Apr 26 '11 at 5:34
4  
Because that has no output when run as a script (for me, anyway). –  Jesse Millikan Apr 26 '11 at 6:06
add comment

L is for Logo, 26 characters → Score: 30

for[i 97 122][type char i]
share|improve this answer
add comment

T is for Thue, 35 characters → Score: 39

0::=~abcdefghijklmnopqrstuvwxyz
::=
0
share|improve this answer
add comment

A is for AppleScript, 41 -> Score: 52

display alert"abcdefghijklmnopqrstuvwxyz"
share|improve this answer
add comment

S is for Scheme, 37 -> Score: 43

(display"abcdefghijklmnopqrstuvwxyz")
share|improve this answer
add comment

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

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

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

++[>+>++<<+++++]>----->[<.+>++]
share|improve this answer
    
Instead of censoring, couldn't you have just used BF? –  Cole Johnson Apr 11 at 19:21
    
@ColeJohnson: I can do a lot of things! –  minitech Apr 11 at 22:52
    
Except be a moderator here ;) –  Cole Johnson Apr 11 at 23:24
add comment

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
add comment

P is for PostScript, 29 chars → Score: 39

(abcdefghijklmnopqrstuvwxyz)=
share|improve this answer
add comment

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.