Posts
Been inspired by @lemire@mastodon.social and started to practice some more bit ops (python code from phone ).
labels = ["{}","Buzz", "Fizz","FizzBuzz"]
for i in range(1, 101):
dv3 = int(i % 3 == 0)
dv5 = int(i % 5 == 0)
sel = (dv3 << 1) | dv5
print(labels[sel].format(i))
Reasoning (pretty obv)
div 3 T
(1<<1)|0 = 2 (idx for Fizz)
div5 T
(0<<1)|1 = 1 (idx for Buzz)
both T
(1<<1)|1 = 3 (Idx for FizzBuzz)
both F = (0<<1) | 0 = 0 ( print count of i)
Branchless FizzBuzz. Easily scalable lol.
My fav chptrs are: Data Norm., Exist. Process. and FSM. I started prefixing my functions based on this table here, which makes it very easy to track bugs(the prefix alone makes me more aware ). There are some funny “philosophical” questions that arrive doing this, and I wonder what @fabs@mastodon.gamedev.place answer would be. Would an init func be a mutating func or a gen func. You could argue that uninited space is muted on initialisation, but that’s usually not thought of as a mutation.