Last active
June 12, 2023 15:28
-
-
Save mdk-aza/4c464abc98ac4277447bfe2ee3678635 to your computer and use it in GitHub Desktop.
fizz_buzzをコードゴルフ風に
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) | |
# コードゴルフで解いた | |
# i%3//2*"Fizz" は、i%3//2の結果が3の倍数なら1、それ以外なら0になり、0 * "Fizz"は空文字になる。//は割り算した際に小数点を切り捨てる | |
# i%5//4*"Buzz" は、i%5//4の結果が4の倍数なら1、それ以外なら0になり、0 * "Buzz"は空文字になる。//は割り算した際に小数点を切り捨てる | |
# or-~iはその前の文字が空文字だった場合に、-~iを実行し、-~iはビット反転演算子を使用してiに1を加える |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment