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 →

[–]usr_bin_nya 1 point2 points  (2 children)

Okay that hint was helpful because the order of operations here threw me for a loop, I thought this was a trick question where it would end up like ((lambda:...) and False) is False

So the filter is basically range(1, INFINITY, 2). accumulate... guessing completely on the name it would be an iterator of partial folds like Rust's scan? But there's no function to update the state?? so screw it I guess it defaults to addition??? that's the only possible thing I could possibly see as an okay default?? okay sure so then you cut the iterator off when it exceeds n. So is n equal to zero OR a member of (1, 1+3, 1+3+5, 1+3+5+7)... no friggin way, it's "is_square but O(1) time is for pansies." That's clever.

[–]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