Skip to content

Instantly share code, notes, and snippets.

@hannahherbig
Created November 22, 2011 22:58
Show Gist options
  • Save hannahherbig/1387323 to your computer and use it in GitHub Desktop.
Save hannahherbig/1387323 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment