4 ms·
Much like stop50's solution, I also used the modulo, but I make use of the terminal to overwrite the number. It's only three lines of code, but I split up the l
by unsnap_biceps 11mo ago
Much like stop50's solution, I also used the modulo, but I make use of the terminal to overwrite the number. It's only three lines of code, but I split up the list to be more readable on here.
This works from 1 to 100000000000000000000 before it overflows, and 100000000000000000000 is above the max size of a unsigned 64 bit int, so I feel that it's good enough
fizzbuzz = [
"fizzbuzz ",
"", "",
"fizz ",
"",
"buzz ",
"fizz ",
"", "",
"fizz ",
"buzz ",
"",
"fizz ",
"", "" ]
for n in range(99999999999999999999-30, 100000000000000000000):
print(f"{n}\r{fizzbuzz[n%15]}")
- floxy 11mo agoVery nice.
- kiratp 11mo agoA for loop has an implicit conditional in its stop condition check.
- kstrauser 11mo agoI 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.
- hug 11mo agoThe 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.