Guest User

Untitled

a guest
Apr 26th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. places = {
  2. 'pep' => 4,
  3. 'quiznos' => 6,
  4. 'jitb' => 5,
  5. 'lafonda' => 10,
  6. 'phut' => 8,
  7. 'hunter' => 15,
  8. 'd1' => 2
  9. }
  10.  
  11. days, funds = ARGV.map {|arg| arg.to_i }
  12. daily_funds = funds / days.to_f
  13.  
  14. planned_places = []
  15. while planned_places.size < days
  16. planned_places += places.select {|name, price| price <= daily_funds }.sort_by { rand }
  17. end
  18. planned_places = planned_places[0...days]
  19.  
  20. funds_used = 0.0
  21. planned_places.each_with_index do |(planned_place_name, planned_place_price), day|
  22. puts "Day #{day + 1}: #{planned_place_name} (#{planned_place_price})"
  23. funds_used += planned_place_price
  24. end
  25.  
  26. funds_remaining = funds - funds_used
  27. puts
  28. puts "Of #{funds}, used #{funds_used} and have #{funds_remaining} remaining"
Add Comment
Please, Sign In to add comment