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 2011-05-02 21:15

>>1
>The output should look like this:

ok

print """
a
b
c
...
aa
ab
ac
...
zzzzx
zzzzy
zzzzz
"""

Name: Anonymous 2011-05-03 6:55

>>21
By connecting SIGFPE to an exit function and dividing some dummy volatile value with ('z' - c0) + ('z' - c1) + ('z' - c2) + ('z' - c3) + ('z' - c4), you could make it terminate at the right time.

Name: Anonymous 2011-05-05 0:44

>>22
>>23
>>26
>>30
Ok, thanks for all your tips but I did it somewhat different now. Hers's the new code, with cheap ASM, function pointing and actual spaces instead of null characters:
#include <stdio.h>

char c0 = 0, c1 = -1, c2 = -1, c3 = -1, c4 = -1, done;
unsigned long t;
void (*f)();
void p(), x();

void p()
{
 printf("%c%c%c%c%c\n",
        ((c4 + 'a') & ((c4 >= 0) * 0xFF)) | (' ' & ((c4 < 0) * 0xFF)),
        ((c3 + 'a') & ((c3 >= 0) * 0xFF)) | (' ' & ((c3 < 0) * 0xFF)),
        ((c2 + 'a') & ((c2 >= 0) * 0xFF)) | (' ' & ((c2 < 0) * 0xFF)),
        ((c1 + 'a') & ((c1 >= 0) * 0xFF)) | (' ' & ((c1 < 0) * 0xFF)),
        (c0 + 'a'));
 c0++;
 c1 += c0 > 25;
 c2 += c1 > 25;
 c3 += c2 > 25;
 c4 += c3 > 25;
 done = (c0 > 25) & (c1 > 25) & (c2 > 25) & (c3 > 25) & (c4 > 25);
 c0 %= 26;
 c1 %= 26;
 c2 %= 26;
 c3 %= 26;
 c4 %= 26;
 f = (void*) ((p & ((1 - done) * 0xFFFFFFFF)) | (x & (done * 0xFFFFFFFF)));
 asm("movl %0, %%esp\n" : : "r"(t));
 f();
}

void x()
{
 /* YES, it's reached now. Feels good to return zero. */
 printf("DONE!!\n");
 exit(0);
}

int main(void)
{
 asm("movl %%esp, %0\n" : "r"(t) : );
 p();
}


...yes, this compiles for me. I'm using TCC/Win32 for compiling, so ASM is in GAS/AT&T format. The function pointing didn't work like this for me in GCC, though.
I also removed the return statement, since this might be interpreted as a jump/loop/whatever. Only calls now, no JMPs.

Name: Anonymous 2012-01-15 8:16

Check my dubs.

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;
 }

Name: Anonymous 2012-01-15 19:30

Recursion not counting as a loop is just stupid.

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