Created
November 22, 2011 22:58
-
-
Save hannahherbig/1387323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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