Created
July 10, 2011 09:31
-
-
Save MrJaba/1074408 to your computer and use it in GitHub Desktop.
Ruby Golf for IPRUG
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
class Golf | |
class << self | |
def hole1(r) | |
r.inject 1,:* | |
end | |
def hole2(s) | |
s.split.sort_by{|a| a[1]}.join " " | |
end | |
def hole3(n) | |
(1..n).inject 1,:* | |
end | |
def hole4(a) | |
a.map{|b| b.sub(/man\((.*)\)/,'hat(man(\1))').sub(/dog\((.*)\)/,'dog(\1(bone))').sub(/cat/,'dead') } | |
end | |
def hole5(a) | |
(1..a[-1]).map{|b| a.each_cons(b).to_a}.flatten 1 | |
end | |
def hole6(t) | |
(1..t).map{|a| a%3==0 && a%5==0 ? 'fizzbuzz': a%3==0 ? 'fizz' : a%5 == 0 ? 'buzz' : a} | |
end | |
def hole7(t) | |
r = [] | |
b,c = t[0],t[0] | |
i=0 | |
t.each{|a| a - t[i-1] > 1 ?( c = t[i-1]; (b == c ? r << "#{b}" : r << "#{b}-#{c}"); b=a) : c=a; i+=1} | |
r << "#{b}-#{c}" | |
end | |
def hole8(u) | |
a = [1,1] | |
(2..u-1).each{|i| a << a[i-1]+ a[i-2]} | |
a | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment