Skip to content

Instantly share code, notes, and snippets.

@monoid
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save monoid/11111100 to your computer and use it in GitHub Desktop.

Select an option

Save monoid/11111100 to your computer and use it in GitHub Desktop.
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