(require 'calc-ext)
(defvar calc-command-flags nil)
(let ((limit (math-add (math-read-number (car argv)) 1))
(hash (make-hash-table))
(i 1) (max-i 1))
(while (math-lessp i limit)
(let ((n i) (len 0) found)
(while (not (math-equal n 1))
(if (gethash n hash)
(progn
(puthash i (math-add len (gethash n hash)) hash)
(setq found t)
(setq n 1))
(setq len (math-add len 1))
(setq n (if (math-equal (math-mod n 2) 0)
(math-div n 2)
(math-add (math-mul 3 n) 1)))))
(if found t
(setq len (math-add len 1))
(puthash i len hash)))
(setq i (math-add i 1)) )
(setq i 1)
(while (math-lessp i limit)
(if (math-lessp (gethash max-i hash) (gethash i hash))
(setq max-i i))
(setq i (math-add i 1)))
(princ (math-format-value max-i))
(princ "\n") )