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

LOGO-L> middle number



here is some code for the middle number problem.

k.large returns the k-th largest number of list :l

so  
k.large [1 45 6] 2
will return 
6


to k.large :l :k
if :k = 1 [output max.list :l]
output k.large remove.first max.list :l :l :k - 1
end

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

to max.list :l
if (count :l) = 1 [output first :l]
output reduce [max ?1 ?2] :l
end

to min :a :b
if :a > :b [output :b]
output :a
end

to remove.first :obj :l
if emptyp :l [output []]
if :obj = first :l [output butfirst :l]
output fput first :l  remove.first :obj butfirst :l
end


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