module Laziness where import Prelude import CFrac import Ratio depth :: Integer -> Integer -> Integer -- depth p q is the depth of the regular tunnel -- of the (p,q) torus knot depth pp qq | pp == 0 && qq == 0 = 0 | abs pp < 3 = 0 | abs qq == 1 = 0 | gcd pp qq /= 1 = 0 | otherwise = count ( tail expansion) where expansion = cFrac (abs pp % abs qq) count [ ] = 0 count [n] = 1 count (1:n:ns) = 1 + (count ns) count (m:n:ns) = 1 + (count (n:ns)) depths :: Integer -> [Integer] -- a list of the depths of the (p,*) torus knot tunnels, p > q depths p = map (depth p) [2..p-1] firstDepthN :: Integer -> Integer -- the first p for which there is a tunnel of depth n for -- some (p,q) torus knot firstDepthN n = head [ p | p <- [2..], maximum ( depths p ) >= n ] {- Sample output: Laziness> firstDepthN 1 3 Laziness> firstDepthN 2 7 Laziness> firstDepthN 3 17 Laziness> firstDepthN 4 41 Laziness> firstDepthN 5 99 Laziness> firstDepthN 6 239 Laziness> firstDepthN 7 577 -}