Skip to content

Instantly share code, notes, and snippets.

@jfredett
Created July 1, 2011 02:30
Show Gist options
  • Save jfredett/1057762 to your computer and use it in GitHub Desktop.
Save jfredett/1057762 to your computer and use it in GitHub Desktop.
Boustrophedon Transform in Haskell
-- Boustrophedon Transform in 1 line of haskell. Shove this in your GHCI, it will give you a function `pp`
-- which takes a function f :: Num a => (Integer -> a) and a depth v :: Num a => a, the former is the
-- sequence to transform, the latter is the depth of the tree to create.
-- I suggest running the results through mapM_ (putStrLn.show), it'll pretty print each level of the tree
-- in order.
let pp f v = let b s k n = if n==0 then s k else (b s k (n-1)) + (b s (k-1) (k-n)) in (\s k -> [[b s n' k' | k<-[1..n']]|n'<-[1..l]]) f v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment