Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -4,60 +4,60 @@ global neededItems = #()
|
|||
global totalValue = 0
|
||||
struct kn_item
|
||||
(
|
||||
item, weight, value
|
||||
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")
|
||||
"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
|
||||
)
|
||||
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
|
||||
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
|
||||
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
|
||||
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 "Item name: %, weight: %, value:%\n" i.item i.weight i.value
|
||||
totalValue += i.value
|
||||
)
|
||||
format "Total mass: %, Total Value: %\n" usedMass totalValue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue