Hacker News new | ask | show | jobs
by kiratp 206 days ago
A for loop has an implicit conditional in its stop condition check.
1 comments

I could see that both ways. Python’s for loops are different than, say, C’s, in that they always consume an iterator. The implementation is that it calls next(iter) until it raises a StopIteration exception, but you could argue that’s just an implementation detail and not cheating.

If you wanted to be more general, you could use map() to apply the function to every member of the iterator, and implementation details aside, that feels solidly in the spirit of the challenge.

The dirty solution I wrote in Powershell does something similar:

1..100 | % {"$_ $(('fizz','')[$_%3])$(('buzz','')[$_%5])"}

I am not sure that using [$_%3] to index into a two-value array doesn't count as a "disguised boolean" thought.