Last active
August 29, 2015 14:00
-
-
Save monoid/11111100 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sp :: (Double, Double) -> (Integer, Double, Double) | |
| sp (x, p) = (floor x, x - (fromIntegral $ floor x), p) | |
| ch (f, r, p) = (1.0 / r, r) | |
| fst' (x, _, _) = x | |
| thd' (_, _, x) = x | |
| -- TODO зипать список с самим собой вместо третьего элемента тупла. Или unfold... | |
| chain x = map fst' $ takeWhile ((/= 0.0) . thd') $ iterate (sp . ch) $ sp (x,x) | |
| unchain [] = 0 | |
| unchain [x] = toRational x | |
| unchain (x:r) = toRational x + 1/(unchain r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment