• + 0 comments

    Haskell | Easy to Understand | Brute-force

    facto n = product [1..n]
    
    printLine :: Int -> Int -> IO ()
    printLine vari n
        | vari == 0 = putStr "1 "
        | otherwise = do
            printLine (vari-1) n
            putStr $ (show (facto n `div` ((facto vari) * facto (n-vari)))) ++ " " 
    
    solve_ :: Int -> Int -> IO ()
    solve_ k n
        | n == k = return ()
        | otherwise = do
            printLine n n
            putStr "\n"
            solve_ k (n+1)
    
    solve :: Int -> IO ()
    solve k = solve_ k 0
    
    main :: IO ()
    main = do
        k_ <- getLine
        let k = read k_ :: Int
        solve k