Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
link printf
|
||||
|
||||
procedure main()
|
||||
room := 15
|
||||
every (x := !(choices := get_items())).uprice := x.price / x.weight
|
||||
choices := reverse(sortf(choices,4))
|
||||
|
||||
every (value := 0, x := !choices) do {
|
||||
if x.weight <= room then {
|
||||
printf("Take all of the %s (%r kg) worth $%r\n",x.name,x.weight,x.price)
|
||||
value +:= x.price
|
||||
room -:= x.weight
|
||||
}
|
||||
else {
|
||||
fvalue := x.uprice * room
|
||||
printf("Take (%r kg) of the %s worth $%r\n",room,x.name,fvalue)
|
||||
value +:= fvalue
|
||||
break
|
||||
}
|
||||
}
|
||||
printf("Total value of a full knapsack is $%r\n",value)
|
||||
end
|
||||
|
||||
record item(name,weight,price,uprice)
|
||||
|
||||
procedure get_items()
|
||||
return [ item("beef", 3.8, 36),
|
||||
item("pork", 5.4, 43),
|
||||
item("ham", 3.6, 90),
|
||||
item("greaves", 2.4, 45),
|
||||
item("flitch", 4.0, 30),
|
||||
item("brawn", 2.5, 56),
|
||||
item("welt", 3.7, 67),
|
||||
item("salami", 3.0, 95),
|
||||
item("sausage", 5.9, 98) ]
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue