News for hackers. Stuff that matters.
Re:Why 37signals Doesn't Hire Programmers Based on Brainteasers by psykotic on Friday January 06, 2012 @01:44AM (#3432309)
Yeah, that works. My left-to-right traversal would be also a little nicer if C had parallel assignments as in Python:

    for i in range(n):
        p = 0
        for j in range(i):
            buf[j], p = buf[j] + p, buf[j]
        buf[i] = 1
Of course, you can also do this in C with a riff on the old in-place swap trick, e.g. buf[j] = buf[j] + p, p = buf[j] - p, but that's too clever by half, albeit kind of cool.

There are no comments on this comment yet.