\insert 'Hailstone.oz' \insert 'HailstoneMax.oz' \insert 'Graph.oz' declare fun {Count N} fun {Help I} if I == N then I|nil else I|{Help I+1} end end in {Help 1} end fun {Peaks List} fun {PeaksIter List MaxSoFar} case List of nil then nil [] (Arg#Val)|Ps then if Val > MaxSoFar then (Arg#Val) | {PeaksIter Ps Val} else {PeaksIter Ps MaxSoFar} end end end in {PeaksIter List 0} end fun {GraphMaxPeaks SearchLimit} Numbers InStream OutStream in thread Numbers = {Count SearchLimit} end thread InStream = {Graph Numbers HailstoneMax} end thread OutStream = {Peaks InStream} end OutStream end