Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge #9002

Name: Anonymous 2011-05-02 20:12

The task:

Print strings from "a" to "zzzzz" without using any loop or conditional statements. Don't just write all 1000 permutations out by hand. The output should look like this:
a
b
c
...
aa
ab
ac
...
zzzzx
zzzzy
zzzzz


inb4 lipthfags and dead dogs using some obscure functionality of their obscure languages.

Name: Anonymous 2012-01-15 18:31

Solve the problem by converting to bases. But you run into the problem of the character set is base 27 not base 26.

So here's some hacky perl that doesn't use a lot of memory. For the rest of you, why did you over complicate it?

 my $i = 0;
 my $l = "";
 while ($l ne "zzzzz") {
     eval {
         $l = convert($i);
         print $l,$/;
     };
     $i++;
 }
 sub convert {
     my ($in) = @_;
     my $mod = $in%27;
     if ($mod == 0) { die "Fuckit"; }
     my $diff = $in - $mod;
     my $new = $diff / 27;
     my $c = ((' ','a'..'z')[$mod]);
     return ($new==0)?$c:convert($new).$c;
 }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List