Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think the final output of a simple solution to your last question can always be just four lines.

    def bar(baz):
        baz()
        baz()

    bar(bar(bar(bar(foo)))) and bar(bar(foo)) and foo()
for N=21, for example. Actually, you can make it two lines if your goal is really to minimize LOC:

    def bar(baz): baz() and baz()

    bar(bar(bar(bar(foo)))) and bar(bar(foo)) and foo()


Whoops, `baz() and baz()` actually doesn't work, because foo may not return a truthy value (and bar definitely doesn't). One fix, which actually makes it even shorter, is just `baz(), baz()`.

Same goes for `bar(bar(...)) and bar()`; all the `and`s should be commands instead in my solution above. Of course, this is Python-specific.


s/commands/commas/g




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: