Skip to content

Instantly share code, notes, and snippets.

@mandykoh
Created February 14, 2019 12:05
Show Gist options
  • Save mandykoh/4d106f289a8bdea3e76c76b6d5122b0c to your computer and use it in GitHub Desktop.
Save mandykoh/4d106f289a8bdea3e76c76b6d5122b0c to your computer and use it in GitHub Desktop.
FizzBuzz with Regexes
#!/usr/bin/env ruby
@parts = ''
(0...100).each { |i| @parts += ',' + (i + 1).to_s }
def mark(n, label)
@parts.gsub! /((,\w+){#{n - 1}})(,\w+)/, "\\1,#{label}"
end
mark 3, 'Fizz'
mark 5, 'Buzz'
mark 15, 'FizzBuzz'
puts @parts.split(',')[1..-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment