Skip to content

Instantly share code, notes, and snippets.

@tk3369
Created February 17, 2018 19:08
Show Gist options
  • Save tk3369/890ddc12832659ae4a9db2d02477366f to your computer and use it in GitHub Desktop.
Save tk3369/890ddc12832659ae4a9db2d02477366f to your computer and use it in GitHub Desktop.
# fizz buzz the bit twiddling way
mymod(n,m,f) = mod(n, m) == 0 ? f : 0x00
fb(n) = ["None", "Fizz", "Buzz", "FizzBuzz"][1 + (mymod(n,3,0x01) | mymod(n,5,0x02))]

Results:

julia> fb.(collect(1:15))
15-element Array{String,1}:
 "None"    
 "None"    
 "Fizz"    
 "None"    
 "Buzz"    
 "Fizz"    
 "None"    
 "None"    
 "Fizz"    
 "Buzz"    
 "None"    
 "Fizz"    
 "None"    
 "None"    
 "FizzBuzz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment