{"id":"ojjdtr","deleted":false,"future_paste":false,"expired":false,"language":"text","created_at":"2022-10-27 18:29:00","expires_at":null,"content":"I wrote an answer to this problem in Haskell\r\nhttps:\/\/rosettacode.org\/w\/index.php?title=9_billion_names_of_God_the_integer\r\n\r\nMy 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. \r\n\r\n[code]\r\n--9 billion names of God\r\n\r\ninput :: Int -> [[Int]]\r\nprocess :: Int -> Int -> [[Int]] -> [[Int]]\r\ng :: Int -> Int\r\n\r\ninput maxr = process maxr 3 [[1], [1,1]]\r\nprocess maxr crow blist \r\n    | maxr < crow = blist\r\n    | otherwise  = process maxr (crow + 1) $ blist ++ [map (\\c -> colproc c) [1..crow]]\r\n    where colproc :: Int -> Int\r\n          colproc col\r\n              | (col == 1 || col == crow) = 1\r\n              | col > diff = sum . take diff $ blist !! (diff - 1)\r\n              | otherwise  = sum . take col $ blist !! (diff - 1)\r\n              where diff = (crow - col)\r\n\r\ng maxr = sum . last $ input maxr \r\n[\/code]"}