[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> multiple pirates



here is a solution for the case of
more than one treasure with the same value

[[5 10] [7 20]]

would indicate 10 treasures of value 5 and 20 treasures of value 7

it should be much faster when some of the treasures
occur with a high frequency.


erich


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


to all.counted.subsets :set
if emptyp :set [output [[]]]
output sentence ~
      (crossmap [[x y] fput :x :y] make.smaller.series first :set ~
		all.counted.subsets butfirst :set) ~
	all.counted.subsets butfirst :set
end

to doubles.value :l
if emptyp :l [output 0]
output apply "sum map [product first ? last ?] :l
end

to fun.invoke.table :arglist :fun
output map [list ? invoke :fun ?] :arglist
end

to make.smaller.series :obj
output map [(list first :obj ?)] iseq 1 last :obj
end

to max :a :b
if :a < :b [output :b]
output :a
end

to max.elements :candidates :valfun
localmake "ourmax max.list map [invoke :valfun ?] :candidates
output filter [:ourmax = invoke :valfun ?] :candidates
end

to max.list :l
output reduce "max :l
end

to multiple.sol :set :maxload
output max.elements (filter [(last ?) < 1 + :maxload] ~
	fun.invoke.table all.counted.subsets :set [doubles.value ?]) 
[last ?]
end

Make "mult.treasures [[5 20]]


--
Erich Neuwirth <neuwirth@smc.univie.ac.at>
Computer Supported Didactics Working Group, Univ. Vienna
Visit our SunSITE at http://sunsite.univie.ac.at



---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home