Skip to content

Instantly share code, notes, and snippets.

View gist:1427153
class UnoClient
def initialize(uno)
@uno = uno
@cards = []
end
def draw
@cards << @uno.draw
end
View bowling_h.rb
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
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
# 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)
@dan5
dan5 / fizzbuzz0.hs
Created Feb 5, 2011
Haskellでプログラムを書く勉強会#0の成果
View fizzbuzz0.hs
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
require 'yaml'
# Retains as a constant
CONFIG = YAML.load_file('config.yml')
# or
# Retains as an instance variable.
class Config
def initialize(name)