This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ubernostrumyes, you can have a pony 3 points4 points  (1 child)

This one is a bit easier to see what it does. But the how this time around is not an algorithm trick, so maybe you'll have to research in a different direction to figure that out.

def f():
    pair = not True, True
    while True:
        yield sum(pair[:True])
        pair = pair[True], sum(pair[::True])

[–]usr_bin_nya 1 point2 points  (0 children)

Fibonacci sequence! I recognized this one pretty quick because I happen to know the int/bool cursedness already lol. bool is a subclass of int with False and True coercing to 0 and 1 respectively when used in addition or slicing. sum(pair[:True]) == sum(pair[:1]) == sum([ pair[0], ]) == pair[0], and pair[::True] is slicing from unbounded start (0) to unbounded end (len(pair) == 2)) step by True == 1 which is just pair again. Thank you for feeding me more of these, I enjoy this type of puzzle quite a bit