Skip to content

Instantly share code, notes, and snippets.

@npras
Created July 3, 2012 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npras/3038075 to your computer and use it in GitHub Desktop.
Save npras/3038075 to your computer and use it in GitHub Desktop.
Ruby Challenge 2: The Twelve Days of Christmas
# challenge 2: http://www.therubygame.com/challenges/2
gifts = "12 Drummers Drumming
11 Pipers Piping
10 Lords-a-Leaping
9 Ladies Dancing
8 Maids-a-Milking
7 Swans-a-Swimming
6 Geese-a-Laying
5 Gold Rings
4 Colly Birds
3 French Hens
2 Turtle Doves
A Partridge in a Pear Tree."
day = 10
def Solution(gifts, day)
t = 0
g = gifts.tr('A', '1').split("\n").reverse
day.times do |x|
t += g[x].split(" ", 2)[0].to_i
end
t
end
puts "#{Solution gifts, day}" # => 55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment