module Previous where import Data.Tree import Data.List (nubBy) bfs (Node root children) = bfs' root children where bfs' v [] = [v] bfs' v ((Node y ys):xs) = v:bfs' y (xs ++ ys) binFracTree = unfoldTree make $ (1,1) where make v@(vn, vd) = (v, [ (2*vn - 1, 2*vd), (2*vn + 1, 2*vd) ]) sternBrocot = unfoldTree make $ ((1,1), (0,1), (1,0)) where make (v@(vn, vd), l@(ln, ld), r@(rn, rd)) = (v, [ (((ln + vn), (ld + vd)), l, v), (((vn + rn), (vd + rd)), v, r) ]) listPairs n = [ (k, n - k) | k <- [0..n] ] allPairs = concat $ map listPairs [0..] ratEqual (a, b) (c, d) = a * d == b * c allRationals = nubBy ratEqual $ map (\(a,b) -> (a+1, b+1)) allPairs