Skip to content

Instantly share code, notes, and snippets.

@jszmajda
Created December 19, 2011 03:21
Show Gist options
  • Save jszmajda/1495239 to your computer and use it in GitHub Desktop.
Save jszmajda/1495239 to your computer and use it in GitHub Desktop.
Ticket To Ride Scoring
def points(x)
{
1 => 1,
2 => 2,
3 => 5,
4 => 7,
6 => 15,
8 => 21
}[x.to_i]
end
def get_score(person)
sco = {}
[1,2,3,4,6,8].each do |i|
puts "how many #{i}s?"
sco[i] = gets
end
sco.inject(0){|s,(k,v)| s + (points(k)*v.to_i)}
end
puts "How many players?"
scores = []
gets.to_i.times do |pn|
puts "player number #{pn + 1}:"
x = get_score(pn)
puts "How many destination points?"
x += gets.to_i
puts "How many stations remaining?"
x += gets.to_i * 4
puts "Extra points?!"
x += gets.to_i
scores << x
end
scores.each_with_index do |sco, i|
puts "Player number #{i + 1} got #{sco}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment