Sort by

recency

|

85 Discussions

|

  • + 0 comments

    Lock and Key Sheffield provides dependable security solutions for homes and businesses. Just like Pascal’s Triangle reveals patterns and connections, our locksmith services offer precise, reliable results every time. Whether you need key cutting, lock repairs, or emergency assistance, our expert team ensures your safety with skill and care. Trust Lock and Key Sheffield to protect what matters most, combining tradition and innovation for your peace of mind.

  • + 0 comments

    My Elixir solution:

    defmodule Solution do
        def get_next(l) do
            [0] ++ (Enum.zip(l, tl l) |> Enum.map(fn {a, b} -> a+b end)) ++ [0]
        end
        
        def pasc(_, 0), do: []
        def pasc(prev, iter) do
            next = get_next(prev)
            [next] ++ pasc(next, iter-1)
        end
        
        def get_pasc(n), do: [[0, 1, 0]] ++ pasc([0, 1, 0], n)
    end
    
    {n, _} = Integer.parse(IO.gets "")
    Solution.get_pasc(n-1)
        |> Enum.each(fn row -> 
            Enum.reject(row, &(&1 == 0))
                |> Enum.map(&Integer.to_string(&1) <> " ")
                |> List.to_string() # |> String.trim()
                |> IO.puts()
        end)
    
  • + 1 comment

    Scala recursive version:

        def main(args: Array[String]) {
            val n = StdIn.readInt()
            println("1")
            printPascalTriangle(n, List(1))
        }
        
        @tailrec
        def printPascalTriangle(n: Int, prevRow: List[Int]): Unit = {
            if (prevRow.size < n) {
                val currentRow = 
                    1 :: (for (i <- 1 to prevRow.size) yield 
                            prevRow(i - 1) + 
                                (if (i < prevRow.size) prevRow(i) else 0)
                    ).toList
                println(currentRow.mkString(" "))
                printPascalTriangle(n, currentRow)
            }
        }
    
  • + 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 
    
  • + 0 comments

    Pascal's Triangle is a fascinating mathematical concept! It's amazing how patterns emerge from simple rules. By the way, if you're looking for a beautiful smile to complement your love for math, dentalblush offers top-notch miami dental clinic in town. Keep exploring the wonders of both math and oral health!