Hailstone sequence: Difference between revisions

Content added Content deleted
(FALSE)
(Added C)
Line 54: Line 54:
MsgBox % "Number: " MaxNum "`nCount: " Max</lang>
MsgBox % "Number: " MaxNum "`nCount: " Max</lang>


=={{header|C}}==
<lang C>#include <stdio.h>
#include <stdlib.h>

int hailstone(int n)
{
int hs = 1;

while (n!=1) {
hs++;
n = (n&1) ? (3*n+1) : (n/2);
}
return hs;
}
int main()
{
int j, hmax = 0;
int jatmax, n;

for (j=1; j<100000; j++) {
n = hailstone(j);
if (hmax < n) {
hmax = n;
jatmax = j;
}
}
printf("Max %d at j= %d\n", hmax, jatmax);

return 0;
}</lang>
Output
<pre>Max 351 at j= 77031</pre>
=={{header|Clojure}}==
=={{header|Clojure}}==
<lang clojure>(defn hailstone-seq [n]
<lang clojure>(defn hailstone-seq [n]