\begin{Verbatim}[commandchars=\\\{\}] I wrote an answer to this problem in Haskell https://rosettacode.org/w/index.php?title=9\PYZus{}billion\PYZus{}names\PYZus{}of\PYZus{}God\PYZus{}the\PYZus{}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\PYZsq{}ve dabbled in scheme. I don\PYZsq{}t get it anymore. If you want to do functional programming and you don\PYZsq{}t care about industry adoption, just use Haskell. Stop torturing yourself with pointless parentheses. [code] \PYZhy{}\PYZhy{}9 billion names of God input :: Int \PYZhy{}\PYZgt{} [[Int]] process :: Int \PYZhy{}\PYZgt{} Int \PYZhy{}\PYZgt{} [[Int]] \PYZhy{}\PYZgt{} [[Int]] g :: Int \PYZhy{}\PYZgt{} Int input maxr = process maxr 3 [[1], [1,1]] process maxr crow blist | maxr \PYZlt{} crow = blist | otherwise = process maxr (crow + 1) \PYZdl{} blist ++ [map (\PYZbs{}c \PYZhy{}\PYZgt{} colproc c) [1..crow]] where colproc :: Int \PYZhy{}\PYZgt{} Int colproc col | (col == 1 || col == crow) = 1 | col \PYZgt{} diff = sum . take diff \PYZdl{} blist !! (diff \PYZhy{} 1) | otherwise = sum . take col \PYZdl{} blist !! (diff \PYZhy{} 1) where diff = (crow \PYZhy{} col) g maxr = sum . last \PYZdl{} input maxr [/code] \end{Verbatim}