In general the solutions I like will scale easily. MeaningThe first two solutions are easy to generalize.
what would it take in each solution if the problem changed
slightly in the future (which in practice does way too often).Like what if now there was five numbers or 50.
Which solutions are easy to adapt and which are not?
As for solution 1 - you can always extract the needed ITEM from the sorted list (use your favorite sorting program).
As for solution 2 - here is Erich's generalized solution (as copied from the archive):
==================================================
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
===================================================
_/
_/ _/ _/_/_/_/_/ _/_/_/_/
_/
_/ _/_/ _/
_/
_/_/_/
_/ _/ _/ _/
_/ _/
_/_/_/_/ _/ _/
_/
_/_/ _/ _/ _/_/_/_/
http://www.geocities.com/CollegePark/lab/2276/
e-mail: yehuka@beitberl.ac.il
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