(do ;;; Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even ;;; = floor(sqrt(a[k]))*a[k] otherwise ; find the number of terms required to reach a[n] = 1, the maximum value of the sequence ; before it reaches 1 and the index at which the maximum was first reached (print " n l[n] h[n] i[n]") (print "=============================") (for [a0 20 39] (var (ak amax aindex mindex) (values a0 0 0 0)) (while (not= ak 1) (when (< amax ak) (set (amax mindex) (values ak aindex)) ) (set aindex (+ aindex 1)) (local root-ak (math.sqrt ak)) (set ak (math.floor (if (= 1 (% ak 2)) (* root-ak ak) ;else root-ak ) ) ) ) (print (string.format "%2d%5d%16d%5d" a0 aindex amax mindex)) ) )