Skip to content

Instantly share code, notes, and snippets.

@xcobar

xcobar/games.rb Secret

Created February 24, 2019 15:00
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 xcobar/afde617a4abd23d2eae783c4403a51a6 to your computer and use it in GitHub Desktop.
Save xcobar/afde617a4abd23d2eae783c4403a51a6 to your computer and use it in GitHub Desktop.
# 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