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

LOGO-L> pirate problem



ok, here is a maathematicians solution.

pirate.sol :treasures 100

will give you the solution.


to all.subsets :set
if emptyp :set [output [[]]]
output sentence all.subsets butfirst :set ~
	map [fput first :set ?]	all.subsets butfirst :set
end

to funtable :arglist :fun
output map [list ? apply :fun ?] :arglist
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 pirate.sol :set :maxload
output max.elements (filter [(last ?) < 1 + :maxload] ~
	funtable all.subsets :treasures "sum) [last ?]
end

to treasure.values :set
output funtable all.subsets :set "sum
end

Make "treasures [3 24 28 51 11 15 17]

--
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