Skip to content

Instantly share code, notes, and snippets.

@judofyr
Forked from JEG2/fizzbuzz.rb
Created August 1, 2012 21:37
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save judofyr/3230984 to your computer and use it in GitHub Desktop.
Save judofyr/3230984 to your computer and use it in GitHub Desktop.
Writing FizzBuzz with flip-flops
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
@DouglasAllen
Copy link

I'm confused about the !
Is this a not or a bang?

@judofyr
Copy link
Author

judofyr commented Oct 5, 2012

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