% $Id: Hailstone.oz,v 1.1 2007/10/29 19:52:10 leavens Exp leavens $ % AUTHOR: Gary T. Leavens declare % The following is really the T function from the 3x+1 problem % since it divides by 2 in both cases. fun {Hailstone N} if {IsOdd N} then (3*N+1) div 2 else N div 2 end end % Return a list of the iterates of N. % This is partially desugared to show the undetermined variable (Z) proc {IterHailstone N ?R} if N == 1 then R=1|nil else local Z in R=N|Z {IterHailstone {Hailstone N} Z} end end end