Skip to content

Instantly share code, notes, and snippets.

@gyu-don
Last active March 23, 2023 20:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyu-don/3777bfa02d2e86cfa9fb64084f3c42dc to your computer and use it in GitHub Desktop.
Save gyu-don/3777bfa02d2e86cfa9fb64084f3c42dc to your computer and use it in GitHub Desktop.
maybe, shortest fizzbuzz of python3
for i in range(100):print(i%3//2*"Fizz"+i%5//4*"Buzz"or-~i)
@Priultimus
Copy link

Why do you do negative bitwise NOT instead of just adding 1?

@cn-ml
Copy link

cn-ml commented Feb 9, 2021

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