public
Created

  • Download Gist
golf.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Byte counts don't include newlines, def... and end
 
# Hole 1: 61 bytes
def fizzbuzz(n)
"FizzBuzz#{n}"[(n%3<1?0:(n%5<1?4:8))..(n%5<1?7:(n%3<1?3:-1))]
end
 
# Hole 2: 72 bytes
def caesar(s,n)
s.tr "a-zA-Z",(h="#{(a=(?a..?z).to_a*'')[n%=26]}-za-#{a[n+1]}")+h.upcase
end
 
# Hole 3: ... nah
 
# Hole 4: 20 bytes
def count(s,u)
s.scan(/#{u}/i).size
end
# If you want to allow special characters, you have to do
# s.scan(/#{Regexp.quote u}/i).size
# but this works for most cases

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.