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 2014-04-07 7:32

Since when is /prog/ full of idiots?

Here, have a trivial and fast solution in Python{2,3} (same algorithm can be easily implemented in most other good languages):


from __future__ import print_function

def f1(fs, i, w):
    w('a')
    w('b')
    w('c')
    w('d')
    w('e')
    w('f')
    w('g')
    w('h')
    w('i')
    w('j')
    w('k')
    w('l')
    w('m')
    w('n')
    w('o')
    w('p')
    w('q')
    w('r')
    w('s')
    w('t')
    w('u')
    w('v')
    w('w')
    w('x')
    w('y')
    w('z')

def fn(fs, i, w):
    p = lambda l: (lambda s: w(l + s))
    f = fs[i]
    i -= 1
    f(fs, i, p('a'))
    f(fs, i, p('b'))
    f(fs, i, p('c'))
    f(fs, i, p('d'))
    f(fs, i, p('e'))
    f(fs, i, p('f'))
    f(fs, i, p('g'))
    f(fs, i, p('h'))
    f(fs, i, p('i'))
    f(fs, i, p('j'))
    f(fs, i, p('k'))
    f(fs, i, p('l'))
    f(fs, i, p('m'))
    f(fs, i, p('n'))
    f(fs, i, p('o'))
    f(fs, i, p('p'))
    f(fs, i, p('q'))
    f(fs, i, p('r'))
    f(fs, i, p('s'))
    f(fs, i, p('t'))
    f(fs, i, p('u'))
    f(fs, i, p('v'))
    f(fs, i, p('w'))
    f(fs, i, p('x'))
    f(fs, i, p('y'))
    f(fs, i, p('z'))

def main():
    fs = [None, f1, fn, fn, fn]
    f1(fs, 0, print)
    fn(fs, 1, print)
    fn(fs, 2, print)
    fn(fs, 3, print)
    fn(fs, 4, print)

if __name__ == '__main__':
    main()

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