module eloadas import StdEnv //Start = sqrt (6.0*pi_26) // where (pi_26,_) = pi26 pi26 :: (Real, Int) pi26 = until goodEnough improve (0.0, 1) goodEnough:: (Real, Int) -> Bool goodEnough (_, k) = k>10000 improve:: (Real, Int) -> (Real, Int) improve (s, k) = (s + 1.0/(k2),k+1) where k2 = toReal (k*k) //Start = (mkQ -2 2) + (mkQ 2 3) //Start = take 10 [(mkQ 1 3),(mkQ 13 30)..] instance + Q where (+):: Q Q -> Q (+) {szamlal=sz1, nevez = n1} {szamlal=sz2, nevez=n2} = simplify {szamlal=sz1*n2+sz2*n1, nevez=n1*n2} instance - Q where (-):: Q Q -> Q (-) {szamlal=sz1, nevez = n1} {szamlal=sz2, nevez=n2} = simplify {szamlal=sz1*n2-sz2*n1, nevez=n1*n2} instance one Q where one = (mkQ 1 1) instance zero Q where zero = (mkQ 0 1) instance < Q where (<):: Q Q -> Bool (<) {szamlal=sz1, nevez = n1} {szamlal=sz2, nevez=n2} = sz1*n2 Q mkQ a b = simplify {szamlal=a, nevez=b} simplify:: Q -> Q simplify {szamlal=sz, nevez=nev} | nev<0 = {szamlal= ~sz/g, nevez= ~nev/g} |otherwise = {szamlal=sz/g, nevez=nev/g} where g = gcd (abs sz) (abs nev) //Start = sum (iterate ((*) 0.75) 1.0) //Start = foldl (~~) 0 [1, 2, 3, 4] (~~):: Int Int -> Int (~~) x y = 6*x + y // Start = ikerprim 200 ikerprim:: Int -> [(Int,Int)] ikerprim n = [(6*k-1,6*k+1) \\ k<-[1..((n-1)/6)] | prim (6*k-1) && prim(6*k+1) ] prim:: Int -> Bool prim x = (length(osztok x))==0 osztok:: Int -> [Int] osztok x = [k \\ k<-[2..(x/2)] | x rem k == 0]