View gist:1427153
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 UnoClient | |
def initialize(uno) | |
@uno = uno | |
@cards = [] | |
end | |
def draw | |
@cards << @uno.draw | |
end |
View bowling_h.rb
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
def score(pins) | |
frames = pins.join(',').scan(/(\d+),?(\d+)?/).map{|e| e.map{|i| i.to_i}} | |
ss = frames.map{|s1, s2| s1 == 10 ? :strike : (s1 + s2 == 10 ? :spare : nil)} | |
sum = frames.size > 10 ? frames.pop[0] : 0 | |
frames.zip(ss.unshift(nil)).zip(ss.unshift(nil)).map{|e1, e2| [e1[0], [e1[1], e2]]}.each do |score, hist| | |
sum += score[0] if hist[0] == :strike and hist[1] == :strike | |
case hist[0] | |
when :strike | |
sum += score[0] + score[1] | |
when :spare |
View bowling3.rb
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
def strike?(pins, idx) | |
pins[idx * 2] == 10 | |
end | |
def spare?(pins, idx) | |
pins[idx * 2] + pins[idx * 2 + 1] == 10 | |
end | |
def score_strike_spare(pins) | |
score = 0 |
View bowling.rb
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
# 1 --- | |
def score(pins) | |
pins.inject(&:+) | |
end | |
pins = [1, 4, 2, 8, 5, 0, 10, 0, 0, 4, 5, 5, 2, 0, 6, 1, 10, 0, 10, 5, 5] | |
p score(pins) | |
# 2 --- | |
def strike?(pins, idx) |
View fizzbuzz0.hs
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
main = putStrLn $ concat $ map addln $ map fizzbuzz [1..20] | |
addln str = concat [str, "\n"] | |
fizzbuzz a = if (a `mod` 3) == 0 then "fizz" | |
else if (a `mod` 5) == 0 then "buzz" | |
else show a |
View gist:230557
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
require 'yaml' | |
# Retains as a constant | |
CONFIG = YAML.load_file('config.yml') | |
# or | |
# Retains as an instance variable. | |
class Config | |
def initialize(name) |