Conversation
Training/Medium/gift.rb
Outdated
| participants.times do | ||
| list << gets.to_i | ||
| end | ||
| list.sort |
| list.sort | ||
| end | ||
|
|
||
| def not_possible? |
There was a problem hiding this comment.
Methods should have one purpose. This one tells us if something is possible - true/false. That said, it will look something like:
budgets_list.inject(0, :+) < gift_price
Training/Medium/gift.rb
Outdated
| end | ||
|
|
||
| def start | ||
| return if not_possible? |
There was a problem hiding this comment.
Changing not_possible? method will require some refactoring here as well:
if not_possible?
puts 'IMPOSSIBLE'
return
end
Training/Medium/gift.rb
Outdated
| contribution = (money_to_pay / contributions_count).to_i | ||
| contribution = budget if budget < contribution | ||
| money_to_pay -= contribution | ||
| puts contribution |
There was a problem hiding this comment.
Would be good to collect the results in an array and print it in a print method or in the bottom of the file when you start the script.
Training/Medium/spoon.rb
Outdated
| end | ||
|
|
||
| def start | ||
| nodes.each do |node| |
There was a problem hiding this comment.
Use map and collect the result, so that it is returned from calling start and you'll avoid printing in the middle of an object's method.
Training/Medium/spoon.rb
Outdated
| nodes.each do |node| | ||
| result = "#{node[0]} #{node[1]}" | ||
| result += add_coordinates(find_right_node(node)) | ||
| result += add_coordinates(find_bottom_node(node)) |
There was a problem hiding this comment.
Use << operator where suitable, because it's faster. Doesn't create extra string objects.
Training/Medium/spoon.rb
Outdated
| ' -1 -1' | ||
| else | ||
| " #{result[0]} #{result[1]}" | ||
| end |
There was a problem hiding this comment.
You may have the same result with:
result ? " #{result[0]} #{result[1]}" : ' -1 -1'Also this methods doesn't actually add any coordinates, it just returns them -> def coordinates(result)
Put print action out of the class and use each_with_object to fill array with contributions
f55e9c8 to
7563008
Compare
No description provided.