I wrote an answer to this problem in Haskell https://rosettacode.org/w/index.php?title=9_billion_names_of_God_the_integer My version is probably less performant than the Haskell one on that page, but takes fewer lines. In any case, I am astonished and thoroughly impressed by how elegantly the problem can be solved, even with my limited knowledge of the language. Before this, I've dabbled in scheme. I don't get it anymore. If you want to do functional programming and you don't care about industry adoption, just use Haskell. Stop torturing yourself with pointless parentheses. [code] --9 billion names of God input :: Int -> [[Int]] process :: Int -> Int -> [[Int]] -> [[Int]] g :: Int -> Int input maxr = process maxr 3 [[1], [1,1]] process maxr crow blist | maxr < crow = blist | otherwise = process maxr (crow + 1) $ blist ++ [map (\c -> colproc c) [1..crow]] where colproc :: Int -> Int colproc col | (col == 1 || col == crow) = 1 | col > diff = sum . take diff $ blist !! (diff - 1) | otherwise = sum . take col $ blist !! (diff - 1) where diff = (crow - col) g maxr = sum . last $ input maxr [/code]