PEP 308: Obfuscated Nested Ternaries (INACAIS)

Gerrit Holl gerrit at nl.linux.org
Thu Feb 20 09:00:42 EST 2003


Hi,

For the Obfuscated Contest: rewrite this peace of code
using ternaries. Preferably with a lot of ('s and )'s :)

    if x > 0:
        if y > 0:
            seq = (tl, br, b, br, r, br)
        elif y == 0:
            seq = (l, r, t, r, b, r)
        else:
            seq = (bl, tr, t, tr, r, tr)
    elif x == 0:
        if y > 0:
            seq = (t, b, l, b, r, b)
        elif y == 0:
            seq = (tl, tr, br, bl, tl)
        else:
            seq = (b, t, l, t, r, t)
    else:
        if y > 0:
            seq = (tr, bl, b, bl, l, bl)
        elif y == 0:
            seq = (r, l, t, l, b, l)
        else:
            seq = (br, tl, t, tl, l, tl)

Actually, I would use case here if available:
switch (x, y):
    case (-1, -1): ...
    case (-1, 0): ...
    case (-1, 1): ...
    case (0, -1): ...
    case (0, 0): ...
    case (0, 1): ...
    case (-1, -1): ...
    case (-1, 0): ...
    case (-1, -1): ...

I am using this to draw an arrow pointing to direction.
The direction is given by (x, y) and the arrow should,
obviously, point to that direction. INACAIS...

yours,
Gerrit.

-- 
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list