-
-
Save judofyr/3230984 to your computer and use it in GitHub Desktop.
Writing FizzBuzz with flip-flops
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
a=b=c=(1..100).each do |num| | |
print num, ?\r, | |
("Fizz" unless (a = !a) .. (a = !a)), | |
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))), | |
?\n | |
end |
Using flip-flops has to be benchmarked. I think that there is nothing wrong with using faster, more common methods. It doesn't make sense to iterate every value of the 1 to 100 range and then still have to eval each condition of a flip-flop.
Have you done a ven test ever? Just a thought. Map the state at every eval.
I'm confused about the !
Is this a not or a bang?
And here's a version of FizzBuzzBazz:
a=b=c=d=(e=1..100).each do |num|
print num, ?\r,
("Fizz" unless (a = !a) .. (a = !a)),
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
("Bazz" unless ((d = !d) .. (d = !d)) ... (e = !e)),
?\n
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay, after some improvements in my verifier-program, I now know there are solutions for everything from 1 to 17 \o/