import Data.Array
import Data.Word
import Data.List
collatz_array =
let
upperbound = 1000000
a
= array
(1, upperbound
) [(i
:: Word64
, f i
:: Int) | i
<- [1..upperbound
]] let
check
_f i
= i `
seq`
if i
<= upperbound
then a
! i
else f i
in
if (i
== 1) then 0 else (check
_f
((if (even i
) then i
else 3 * i
+ 1) `
div`
2)) + 1 in a
main =
foldl1' (\(x1,x2) (y1,y2) -> if (x2 >= y2) then (x1, x2) else (y1, y2)) $! (assocs collatz_array)
aW1wb3J0IERhdGEuQXJyYXkKaW1wb3J0IERhdGEuV29yZAppbXBvcnQgRGF0YS5MaXN0Cgpjb2xsYXR6X2FycmF5ID0gCiAgbGV0CiAgICB1cHBlcmJvdW5kID0gMTAwMDAwMAogICAgYSA9IGFycmF5ICgxLCB1cHBlcmJvdW5kKSBbKGkgOjogV29yZDY0LCBmIGkgOjogSW50KSB8IGkgPC0gWzEuLnVwcGVyYm91bmRdXQogICAgZiBpID0gaSBgc2VxYAogICAgICBsZXQKICAgICAgICBjaGVja19mIGkgPSBpIGBzZXFgIGlmIGkgPD0gdXBwZXJib3VuZCB0aGVuIGEgISBpIGVsc2UgZiBpCiAgICAgIGluCiAgICAgICAgaWYgKGkgPT0gMSkgdGhlbiAwIGVsc2UgKGNoZWNrX2YgKChpZiAoZXZlbiBpKSB0aGVuIGkgZWxzZSAzICogaSArIDEpIGBkaXZgIDIpKSArIDEKICBpbiBhCiAgICAgICAgCm1haW4gPSAKICBwdXRTdHJMbiAkIHNob3cgJCAKICAgZm9sZGwxJyAoXCh4MSx4MikgKHkxLHkyKSAtPiBpZiAoeDIgPj0geTIpIHRoZW4gKHgxLCB4MikgZWxzZSAoeTEsIHkyKSkgJCEgKGFzc29jcyBjb2xsYXR6X2FycmF5KQo=