| import Data.Ratio
|
| import Numeric (floatToDigits)
|
|
|
| fracs :: [Ratio Int]
|
| fracs = [
|
| 17 % 91,
|
| 78 % 85,
|
| 19 % 51,
|
| 23 % 38,
|
| 29 % 33,
|
| 77 % 29,
|
| 95 % 23,
|
| 77 % 19,
|
| 1 % 17,
|
| 11 % 13,
|
| 13 % 11,
|
| 15 % 2,
|
| 1 % 7,
|
| 55 % 1]
|
|
|
| start :: Int
|
| start = 2
|
|
|
| isInt :: Float -> Bool
|
| isInt n =
|
| let (digs, p) = floatToDigits 10 n in
|
| length digs == p
|
|
|
| ri2r :: Ratio Int -> Rational
|
| ri2r r =
|
| let n = toInteger $ numerator r in
|
| let d = toInteger $ denominator r in
|
| n % d
|
|
|
| foo
|
| :: [Ratio Int] -- fractions (ie, program)
|
| -> Int -- seed integer (ie, pc)
|
| -> [Int]
|
| foo fs s =
|
| let ss = toInteger s % 1 in
|
| let mfn = (\f -> let v = fromRational $ ss * (ri2r f) in (isInt v, v)) in
|
| let bs = map mfn fs in
|
| let bb = dropWhile (\x -> fst x == False) bs in
|
| if null bb then [s]
|
| else
|
| let nxt = round $ snd $ head bb in
|
| s : foo fs nxt
|