Created
July 3, 2012 06:30
-
-
Save npras/3038075 to your computer and use it in GitHub Desktop.
Ruby Challenge 2: The Twelve Days of Christmas
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
# 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