Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
V items = [(‘beef’, 3.8, 36.0),
|
||||
(‘pork’, 5.4, 43.0),
|
||||
(‘ham’, 3.6, 90.0),
|
||||
(‘greaves’, 2.4, 45.0),
|
||||
(‘flitch’, 4.0, 30.0),
|
||||
(‘brawn’, 2.5, 56.0),
|
||||
(‘welt’, 3.7, 67.0),
|
||||
(‘salami’, 3.0, 95.0),
|
||||
(‘sausage’, 5.9, 98.0)]
|
||||
|
||||
V MAXWT = 15.0
|
||||
|
||||
V sorted_items = sorted(items.map((name, amount, value) -> (value / amount, amount, name)), reverse' 1B)
|
||||
V wt = 0.0
|
||||
V val = 0.0
|
||||
[(String, Float, Float)] bagged
|
||||
|
||||
L(unit_value, amount, name) sorted_items
|
||||
V portion = min(MAXWT - wt, amount)
|
||||
wt += portion
|
||||
V addval = portion * unit_value
|
||||
val += addval
|
||||
bagged [+]= (name, portion, addval)
|
||||
I wt >= MAXWT
|
||||
L.break
|
||||
|
||||
print(‘ ITEM PORTION VALUE’)
|
||||
print(bagged.map((n, p, a) -> ‘#10 #3.2 #3.2’.format(n, p, a)).join("\n"))
|
||||
print("\nTOTAL WEIGHT: #2.2\nTOTAL VALUE: #2.2".format(wt, val))
|
||||
Loading…
Add table
Add a link
Reference in a new issue