Sort by

recency

|

209 Discussions

|

  • + 0 comments

    Be sure to handle empty lines on the input!

  • + 0 comments

    Haskel code

    calcex :: Int -> Double -> Double
    calcex 10 _ = 1.0
    calcex n x = 1.0 + x / fromIntegral n * calcex (n + 1) x
    
    evaluateSeries :: Double -> Double
    evaluateSeries x = calcex 1 x
    
    main :: IO ()
    main = do
        n <- readLn :: IO Int
        inputs <- mapM (\_ -> readLn :: IO Double) [1..n]
        let outputs = map evaluateSeries inputs
        mapM_ print outputs
    
  • + 0 comments

    clojure code

    (defn nth-term 
        [x n]
        (reduce (fn [acc el]
            (/ (* acc x) el)) 1 (range 1 (inc n))))
    
    (defn exponential 
        [x]
        (reduce (fn [acc el]
            (+ acc (nth-term x el))) 1 (range 1 10)))
    
  • + 0 comments

    Body flanges play an important role in industries such as oil and gas, petrochemicals, power generation, and more. Their primary function is to connect different parts of a piping system, facilitating the flow of fluids and gases in the shells of tanks, pressure vessels, and heat exchangers.

  • + 2 comments

    My working scala code :

    object Solution { def main(args: Array[String]):Unit = { val stdin = scala.io.StdIn val n = stdin.readLine.trim.toInt for (nItr <- 1 to n) { val x = stdin.readLine.trim.toDouble println(((make(x) * 10000).round).toDouble / 10000.toDouble) } }

    def sum(a: Double, b: Double): Double = return a + b;

    def make(x: Double): Double = { return Range(0, 10).map(number => Math.pow(x, number) / factorial(number)).sum

    }

    def factorial(x: Double): Double = { if (x == 0) return 1 else return x * factorial(x - 1) } }