\newif\ifprint
\newcount\itercount
\newcount\currentnum
\def\hailstone#1{\itercount=0 \currentnum=#1 \hailstoneaux}
\def\hailstoneaux{%
	\advance\itercount1
	\ifprint\number\currentnum\space\space\fi
	\ifnum\currentnum>1
		\ifodd\currentnum
			\multiply\currentnum3 \advance\currentnum1
		\else
			\divide\currentnum2
		\fi
		\expandafter\hailstoneaux
	\fi
}

\parindent=0pt
\printtrue\hailstone{27}
Length = \number\itercount
\bigbreak

\newcount\ii \ii=1
\printfalse
\def\lenmax{0}
\def\seed{0}
\loop
	\ifnum\ii<100000
		\hailstone\ii
		\ifnum\itercount>\lenmax\relax
			\edef\lenmax{\number\itercount}%
			\edef\seed{\number\ii}%
		\fi
		\advance\ii1
\repeat
Seed max = \seed, length = \lenmax
\bye
