Tell me more ×
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.

Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'.

Your task is to write a set of (up to 5) programs in any language (which has a text-based syntax*) to output all 26 letters of the alphabet in order. However for each vowel aeiou, at least one of the programs must not include any occurrence of the vowel.

So there must be

  • a program that does not use 'a' anywhere in the syntax of the program.
  • a program that does not use 'e' anywhere in the syntax of the program.
  • a program that does not use 'i' anywhere in the syntax of the program.
  • a program that does not use 'o' anywhere in the syntax of the program.
  • a program that does not use 'u' anywhere in the syntax of the program.

All of them must output 'abcdefghijklmnopqrstuvwxyz'.

The winner shall be the solution where the length of all programs is the shortest.

* since the constraint wouldn't be much of a challenge in Piet or Whitespace


Current rankings (30/4/2012):

share|improve this question
1  
if one manages to make a single program that does not contain any vowel, do we need multiply the length of the program by 5? – w0lf Apr 24 '12 at 10:55
@w0lf No, in that case the length of the single program would suffice. – shamp00 Apr 24 '12 at 11:06
2  
@w0lf: No, it says "up to 5 programs" and "length of all programs", which I read as "there can be only one program and its length counts in this case". – schnaader Apr 24 '12 at 11:09
This doesn't really add much to the existing print-the-alphabet questions. – Peter Taylor Apr 24 '12 at 13:45
4  
@PeterTaylor: You don't think having to avoid using vowels in your syntax is a unique challenge? As a JS programmer, it's especially interesting :) – mellamokb Apr 24 '12 at 13:51
show 2 more comments

51 Answers

1 2

In Perl,

it's also possible without any vowels

but much harder than in Ruby etc. This uses a total of 101 chars but doesn't require cmd line (perl -e) invocation.

`\160\145\162\154\40\55\145\40\42\160\162\151\156\164\40\123\124\104\105\122\122\40\141\56\56\172\42`

=> Result: abcdefghijklmnopqrstuvwxyz

In contrast to the 'similar looking' PHP Solution, this is a real program. The program decoded reads:

perl -e "print STDERR a..z"

After encoding to octal values, another perl interpreter is called during run by the `` (backticks). The backticks would consume the output, therefore it's printed to STDERR.

The encoding is done by sprintf:

my $s = q{perl -e "print STDERR a..z"};
my $cmd = eval(
       '"' . join('', map sprintf("\\%o",ord $_), split //, $s) . '"'
       );

and the eval'd encoding is the program posted (within backticks):

"\160\145\162\154\40\55\145\40\42\160\162"
"\151\156\164\40\123\124\104\105\122\122"
"\40\141\56\56\172\42"

Regards

rbo

share|improve this answer
3  
You could shorten this to 44 characters by only encoding the vowels :) – marinus Apr 30 '12 at 22:35

Factor, 264 characters

No ae, 60 characters:

USING: io ;
"\u000061bcd\u000065fghijklmnopqrstuvwxyz" print

No io, 102 characters:

USE: eval
"USE: \u000069\u00006f
\"abcdefgh\u000069jklmn\u00006fpqrstuvwxyz\" pr\u000069nt" eval( -- )

No u, 102 characters:

FROM: math.ranges => [a,b] ;
FROM: io => print ;
FROM: strings => >string ;
97 122 [a,b] >string print

Every language, in the previous answers, uses less than 200 characters. Factor is the only language to use more than 200 characters and to use 3 programs. Factor is difficult, because outputting without io is a challenge, and programming without u is almost impossible.

The first 2 programs are variations of

USE: io
"abcdefghijklmnopqrstuvwxyz" print

Alternatives to io are scarce; formatting still needs i and o, and prettyprint needs i. I saw string evaluation in a Python answer, and took the hint. With eval, I can escape away i and o, but I need a and e in eval, and u in \uxxxxxx escapes.

The hardest challenge is to remove u. This means no USE:, USING:, \uxxxxxx, nor sequences. My best program without u needs all of aeio. I would like a Factor program without aeu, but my only way to remove ae is to use u.

share|improve this answer

Perl 5.10+, 8 + 22 = 30 chars

No e, i, o, u:

say a..z

No a, i, o, u:

s//"s\x61y \x61..z"/ee

Both of these need the -M5.010 switch (which is considered free) to enable the say feature. For older perls, it can be replaced with print for an extra four chars (and loss of trailing newline in output):

print a..z
s//"pr\x69nt \x61..z"/ee
share|improve this answer

Bash 34 characters

This is my 34 characters long bash snippet, close to marinus snippet but shorter :

/*/?ch? $'\145ch\157 {\x61..z}'|sh
share|improve this answer

Ruby, 22

$><<[*?`..?{][1,26]*''

No letters whatsoever :)

share|improve this answer

Python, 94 78 chars

It prints the alphabet when running in an interactive shell (which prints the expression it evaluates).
Python isn't the tool for this task. Printing requires print, loop constructs require in or while, so i is quite a problem.

Both these expressions evaluate to the a-z string. The first doesn't use i,o, the second doesn't use a,e,u

"%c"*26%tuple(range(97,123))
''.join([chr(ord(c)-1)+c for c in'bdfhjlnprtvxz'])

Brute-force approach, 110 chars:

"%c"*26%(97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122)
share|improve this answer
eval's got no i. – boothby Apr 25 '12 at 1:54
2  
@boothby Yes it does: evil. There. – Konrad Rudolph Apr 25 '12 at 9:03

D no 'u' (64 chars)

import std.stdio;void main(){for(char c=96;c++<'z';){write(c);}}

D only i (92 chars)

mixin("imp\157rt std.stdi\157;v\157id m\141in(){f\157r(ch\141r c;c++<'z';){writ\145(c);}}");

abusing the mixin and octal escape in string literals

share|improve this answer
What about the complementary program(s) that don't use a,e,i,o? – mellamokb Apr 25 '12 at 12:52
@mellamokb check now :) – ratchet freak Apr 25 '12 at 13:24
4  
You still need a version with no i. – shamp00 Apr 27 '12 at 15:45

BASH: 16 + 32 = 48 characters

Here's some inspiration to all you shell-lovers:

Using a, i (no e, o, u): 16 characters

printf %q {a..z}

Using e, o (no a, i, u): 32 characters

$0<<<$'echo {\x61..z}|tr -d " "'

works well, providing you've set your computer up with an automatic

#!bin/bash

I'm sure someone out there knows how to un-vowel this!

share|improve this answer

12 characters in Burlesque

'`'zr@[-\[sh

(see here in action.)

With a:

'a'zr@\[sh

share|improve this answer

C# – 278/149

Variant 1 – Full standalone programs

A and I are unavoidable here because of class and static.

Without U: 81 chars:

class C{static void Main(){for(int x=65;x<91;++x)System.Console.Write((char)x);}}

Without E: 96 chars:

class C{static void Main(){for(int x=65;x<91;++x)Syst\u0065m.Consol\u0065.Writ\u0065((char)x);}}

Without O: 101 chars:

class C{static int Main(){System.C\u006fns\u006fle.Write("abcdefghijklmn\x6fpqrstuvwxyz");return 0;}}

Total (with A, I missing): 278

Variant 2 – Pure code

Without A, E, I, O: 97 chars

Syst\u0065m.C\u006fns\u006fl\u0065.Wr\u0069t\u0065("\u0061bcd\u0065fgh\x69jklmn\x6fpqrstuvwxyz");

Without U: 52 chars

for(int x=65;x<91;++x)System.Console.Write((char)x);

total: 149

share|improve this answer
class C{static void Main(){for(var x='@';x++<'Z';)System.Console.Write(x);}} shorter one for first program. – tia Apr 25 at 12:50

Haskell, 12

['\97'..'z']

Or is this cheating? :)

share|improve this answer
I admittedly don't know much about Haskell, but it gives me this error: Parse error: naked expression at top level – primo Dec 20 '12 at 9:39
You run it in the interpreter – RobAu Dec 20 '12 at 10:21

Tcl, 49 chars

p\165ts \141bcd\145fgh\151jklmn\157pqrst\165vwxyz

Yeah, \ substitution works for commands. (And all other kinds of substitution as well)

share|improve this answer

Python, 83

No a, i, o or u; 47:

x=97;s='';exec"s+=chr(x);x+=1;"*26+"pr\x69nt s"

No e; 36:

print"abcd\x65fghijklmnopqrstuvwxyz"
share|improve this answer

C 108

Technically cheating, but

x[]={1684234849,1751606885,1818978921,1886350957,1953722993,2021095029,31353};y(){z("%s",x);}

Compile with -Dy=main -Dz=printf (I counted those towards the char count). Of course if you're allowing -D, go full hog and say -Dp=main(c){for(;c<27;)putchar(96+c++);} 39 characters there. (Or one, depending on how you count).

share|improve this answer
With the same method, you could shorten a lot with "abcd%cfg.... – ugoren Jun 3 '12 at 19:55
Yes, but the the array was more intimidating. That's half comprehensible. – walpen Jun 3 '12 at 21:32

Perl (25 24 ) (18?) (no wowels, little cheating)

script.pl contains:

$"="";s//@{["\x61"..z]}/

it has to be executed this way:

echo | perl -p script.pl

or

echo | perl -pe '$"="";s//@{["\x61"..z]}/'

If you don't mind spaces between letters in the alphabet, it can be shortened to 18 characters:

s//@{["\x61"..z]}/

($" variable defines separator to be used for printing arrays, space is default)

UPDATES:

  • s/^/ -> s//
share|improve this answer

Befunge, 26

>"`">1+:"z"`v
:,  ^      @_

Minimizing whitespace is part of the challenge of Befunge, so I included it in the character count. It might be possible to take out some of that whitespace, but the instructions themselves seem minimal.

share|improve this answer

Lua, 56

_G["pr\105nt"]"\97bcd\101fgh\105jklmn\111pqrst\117vwxyz"

share|improve this answer

Smalltalk (Squeak 4.x) 78 chars

Since we program by sending messages to objects, and that most messages are made of english words, this is a real challenge in Smalltalk.

However it is possible to exploit this curiosity: we can concatenate a String and a ByteArray with binary selector ,

'',#[97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122]

We can also exploit arithmetic on ByteArray to shorten to 78 chars

'',(#[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25]+97)

Now can we write a loop without using to:do: whileTrue: repeat?
Yes we can, with recursion, but we need to stop the recursion with a test, and can we without using one of ifTrue: ifFalse: or: and:?
Yes we can just implement the message of our choice in True/False.
Let's see how far we can go...

We can't use the receiver of a message, self has a vowel: so we need a message with two parameters, say x:z:, sent to any object (9 chars)

0x:''z:97

we implement x:z: message in Object (38 chars - 47 total)

x:x z:z z<123?[^0x:x,(#[0]+z)z:z+1].^x

we implement ? in class False (2 chars - 49 total):

?x

we implement ? in class True: (6 chars - 55 total)

?x^x x

But now, how to evauate the block without sending the message value (3 vowels)...
The best I could was to implement x in class BlockClosure: (16 chars - 71 total)

x<primitive:201>

But that still consumes 2 vowels... And we're not far from original 78...

I still got a nice obfuscation - golfing in Smalltalk is really contre-nature ;)

share|improve this answer

Erlang escript 75

It's pretty hard to do any golfing in Erlang but anyway:

$ cat alphabet 

'm\x61\x69n'(_)->
'\x69\x6f':'f\x6frm\x61t'('l\x69sts':'s\x65q'(97,122)).

Note empty line at beginning of escript and also line break in main function. They are both mandatory. Run it using

$ escript alphabet
share|improve this answer

JavaScript, 43 Chars (run in terminal)

"\141bcd\145fgh\151jklmn\157pqrst\165vwxyz"
share|improve this answer
This just generates the alphabet, not outputs it as required. – manatwork Apr 9 at 16:31
for(t= 65; t < 96 ; t++){
printf("%c",t) ;
}
share|improve this answer
4  
This is fine for a, e and u but it contains i and o. You need to provide another program that does the same but doesn't include i and o in order to meet the spec. – Gareth Oct 1 '12 at 10:17
1 2

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.