Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,63 @@
|
|||
global globalItems = #()
|
||||
global usedMass = 0
|
||||
global neededItems = #()
|
||||
global totalValue = 0
|
||||
struct kn_item
|
||||
(
|
||||
item, weight, value
|
||||
)
|
||||
|
||||
itemStrings = #("map#9#150","compass#13#35","water#153#200", \
|
||||
"sandwich#50#160","glucose#15#60","tin#68#45", \
|
||||
"banana#27#60","apple#39#40","cheese#23#30", \
|
||||
"beer#52#10","suntan cream#11#70","camera#32#30", \
|
||||
"T-shirt#24#15","trousers#48#10","umbrella#73#40", \
|
||||
"waterproof trousers#42#70","waterproof overclothes#43#75", \
|
||||
"note-case#22#80","sunglasses#7#20", "towel#18#12", \
|
||||
"socks#4#50","book#30#10")
|
||||
|
||||
fn sortByValue a b =
|
||||
(
|
||||
if a[1].value > b[1].value then return -1
|
||||
else
|
||||
(
|
||||
if a[1].value == b[1].value then return 0
|
||||
else return 1
|
||||
)
|
||||
)
|
||||
fn chooseBestItem maximumWeight: items: =
|
||||
(
|
||||
local itemsCopy = deepcopy items
|
||||
local possibleItems = #()
|
||||
for i = 1 to itemsCopy.count do
|
||||
(
|
||||
if itemsCopy[i].weight <= maximumWeight do append possibleItems (#(itemsCopy[i],i))
|
||||
)
|
||||
qsort possibleItems sortByValue
|
||||
if possibleItems.count > 0 then return possibleItems[1] else return 0
|
||||
)
|
||||
|
||||
for i = 1 to itemStrings.count do
|
||||
(
|
||||
local split = filterstring itemStrings[i] "#"
|
||||
local itemStruct = kn_item item:split[1] weight:(split[2] as integer) \
|
||||
value:(split[3] as integer)
|
||||
appendifunique globalItems itemstruct
|
||||
)
|
||||
|
||||
while usedMass < 400 do
|
||||
(
|
||||
local item = chooseBestItem maximumweight:(400-usedMass) items:(globalItems)
|
||||
if item != 0 then
|
||||
(
|
||||
deleteitem globalItems (item[2])
|
||||
appendifunique neededItems item[1]
|
||||
usedMass += item[1].weight
|
||||
) else exit
|
||||
)
|
||||
for i in neededitems do
|
||||
(
|
||||
format "Item name: %, weight: %, value:%\n" i.item i.weight i.value
|
||||
totalValue += i.value
|
||||
)
|
||||
format "Total mass: %, Total Value: %\n" usedMass totalValue
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Item name: water, weight: 153, value:200
|
||||
Item name: sandwich, weight: 50, value:160
|
||||
Item name: map, weight: 9, value:150
|
||||
Item name: note-case, weight: 22, value:80
|
||||
Item name: waterproof overclothes, weight: 43, value:75
|
||||
Item name: suntan cream, weight: 11, value:70
|
||||
Item name: waterproof trousers, weight: 42, value:70
|
||||
Item name: glucose, weight: 15, value:60
|
||||
Item name: banana, weight: 27, value:60
|
||||
Item name: socks, weight: 4, value:50
|
||||
Item name: compass, weight: 13, value:35
|
||||
Item name: sunglasses, weight: 7, value:20
|
||||
OK
|
||||
Total mass: 396, Total Value: 1030
|
||||
OK
|
||||
Loading…
Add table
Add a link
Reference in a new issue