Advertisement
brewersfan1976

knapsack_light.rb

May 30th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.50 KB | None | 0 0
  1. def knapsackLight(value1, weight1, value2, weight2, maxW)
  2.     if weight1 + weight2 <= maxW then
  3.        return value1 + value2
  4.     end
  5.        
  6.     if value1 > value2 and weight1 <= maxW then
  7.        return value1
  8.     end
  9.        
  10.     if value2 > value1 and weight2 <= maxW then
  11.        return value2
  12.     end
  13.        
  14.     if value1 < value2 and weight1 <= maxW then
  15.        return value1
  16.     end
  17.        
  18.     if value1 == value2 then
  19.        return value1
  20.     end
  21.        
  22.     return 0
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement