ruby <3
def score(values) values.tally.sum do |n, cnt, acc = 0| case [n, cnt] in 1, 3.. then cnt -= 3 acc += 1000 redo in 6, 3.. then cnt -= 3 acc += 600 redo in 5, 3.. then cnt -= 3 acc += 500 redo in 4, 3.. then cnt -= 3 acc += 400 redo in 3, 3.. then cnt -= 3 acc += 300 redo in 2, 3.. then cnt -= 3 acc += 200 redo in 1, 1.. then cnt -= 1 acc += 100 redo in 5, 1.. then cnt -= 1 acc += 50 redo else acc end end end p score([5, 1, 3, 4, 1]) # => 50 + 2 * 100 = 250 p score([1, 1, 1, 3, 1]) # => 1000 + 100 = 1100 p score([2, 4, 4, 5, 4]) # => 400 + 50 = 450
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
ruby <3