Skip to content

Instantly share code, notes, and snippets.

@idlehands
Created August 10, 2016 03:01
Show Gist options
  • Save idlehands/860a785d8b6fde7b0e0bb9dd2f3d0422 to your computer and use it in GitHub Desktop.
Save idlehands/860a785d8b6fde7b0e0bb9dd2f3d0422 to your computer and use it in GitHub Desktop.
Ruby starter file for for Algorithm Toolbox on Coursera
#!/usr/bin/env ruby
# by Jeffrey Matthias
def get_optimal_value(capacity, weights, values)
value = 0.0
# your code here
value
end
if __FILE__ == $0
number_of_items, capacity = gets.split().map(&:to_i)
values = []
weights = []
number_of_items.times do
value, weight = gets.split().map(&:to_i)
values << value
weights << weight
end
answer = get_optimal_value(capacity, weights, values)
puts "#{'%.4f' % answer}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment