Sort by

recency

|

210 Discussions

|

  • + 0 comments

    Here's a quick way from fapello to implement the solution in Python:

    python Copy Edit import math

    Function to calculate e^x using a series expansion

    def calculate_exp(x, n_terms=100): result = 0 for i in range(n_terms): result += (x ** i) / math.factorial(i) return result

    Input reading

    t = int(input()) for _ in range(t): x = float(input()) print(f"{calculate_exp(x):.4f}") This computes 𝑒 𝑥 e x using the series expansion up to 100 terms, ensuring high accuracy within the tolerance limits provided.

  • + 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.