-
-
Save xcobar/afde617a4abd23d2eae783c4403a51a6 to your computer and use it in GitHub Desktop.
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
# Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection. | |
# For example: ["3:1", "2:2", "0:1", ...] | |
# Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match: | |
# if x>y - 3 points | |
# if x<y - 0 point | |
# if x=y - 1 point | |
# Notes: | |
# there are 10 matches in the championship | |
# 0 <= x <= 4 | |
# 0 <= y <= 4 | |
game_results = ['3:1', '2:2', '0:1', '3:2'] | |
def points(games) | |
@points = 0 | |
games.each do |result| | |
results = result.split(':').map(&:to_i) | |
if results[0] > results[1] | |
@points += 3 | |
elsif results[0] < results[1] | |
@points += 0 | |
elsif results[0] == results[1] | |
@points += 1 | |
end | |
end | |
puts @points | |
end | |
points(game_results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment