Instantly share code, notes, and snippets.

Created November 30, 2022 21:04
Show Gist options
• Save Schwad/9cf63f647ad3d16dc8d01eff554aae50 to your computer and use it in GitHub Desktop.

# Oh it's just FizzBuzz, right?

It's been a fun conference. You've done well to make it this far. We're proud of you!

You're probably exhausted, so for today we're treading familiar territory. We want you to implement FizzBuzz for your solution.

Just include your code in the snippet below and submit.

Here's the twist:

We'll be benchmarking winners based on number of instructions used! FizzBuzz in a nutshell: return "Fizz" if a number is divisible by 3, "Buzz" if divisible by 5, "FizzBuzz" if divisible by both!

If you have no idea how we're going to measure that, don't worry, we'll share our work! The legendary @kddnewton has provided a method for us that we'll be using to check your work here:

(Note: no cute solutions here with the tests, proper fizzbuzz! We will be checking it on the human level as well)

```def count_iseq(iseq)
iseq[12].select { _1 in [:ensure | :rescue, *] }.sum { count_iseq(_1[1]) } +
iseq[13].sum do
case _1
in Integer | Symbol
0
in [*, ["YARVInstructionSequence/SimpleDataFormat", *] => child_iseq, *]
1 + count_iseq(child_iseq)
in Array
1
end
end
end

def count(source)
count_iseq(RubyVM::InstructionSequence.compile(source).to_a)
end```
```def solution(number)
# Your code here
end

raise unless solution(3) == "Fizz"
raise unless solution(5) == "Buzz"
raise unless solution(15) == "FizzBuzz"

puts "It works!"```
to join this conversation on GitHub. Already have an account? Sign in to comment