Last active
March 23, 2023 20:23
-
-
Save gyu-don/3777bfa02d2e86cfa9fb64084f3c42dc to your computer and use it in GitHub Desktop.
maybe, shortest fizzbuzz of python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(100):print(i%3//2*"Fizz"+i%5//4*"Buzz"or-~i) |
Note that the loop iterates the numbers 0 thru 99 inclusive. So instead of x we must print x+1. Negative bitwise not is the same as +1 in twos-complement. There are now these three options: -~x
x+1
1+x
following the or. If we were to put the second option there we would need an additional space because otherwise python would recognize orx
as an identifier instead of a keyword and would raise a syntax error. Same goes of or1
so -~x
is the choice here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why do you do negative bitwise NOT instead of just adding 1?