never executed always true always false
1 reciprocal :: Int -> (String, Int)
2 reciprocal n | n > 1 = ('0' : '.' : digits, recur)
3 | otherwise = error
4 "attempting to compute reciprocal of number <= 1"
5 where
6 (digits, recur) = divide n 1 []
7 divide :: Int -> Int -> [Int] -> (String, Int)
8 divide n c cs | c `elem` cs = ([], position c cs)
9 | r == 0 = (show q, 0)
10 | r /= 0 = (show q ++ digits, recur)
11 where
12 (q, r) = (c*10) `quotRem` n
13 (digits, recur) = divide n r (c:cs)
14
15 position :: Int -> [Int] -> Int
16 position n (x:xs) | n==x = 1
17 | otherwise = 1 + position n xs
18
19 showRecip :: Int -> String
20 showRecip n =
21 "1/" ++ show n ++ " = " ++
22 if r==0 then d else take p d ++ "(" ++ drop p d ++ ")"
23 where
24 p = length d - r
25 (d, r) = reciprocal n
26
27 main = mainn 4
28 mainn 0 = return ()
29 mainn n = do
30 number <- readLn
31 putStrLn (showRecip number)
32 mainn (pred n)