Area Under Curves and Volume of Revolving a Curve Discussions | Functional Programming | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Haskell concise solution
solve :: Int -> Int -> [Int] -> [Int] -> [Double]
solve l r as bs = [sum [(f as bs i) * dx|i<-range], sum [pi*(f as bs i)^^2 * dx|i<-range]]
where dx = 0.001
fl = fromIntegral l
fr = fromIntegral r
range = [fl,fl+dx..fr]
f as bs x = sum[(fromIntegral a)*(x^^b)|(a,b)<-zip as bs]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Area Under Curves and Volume of Revolving a Curve
You are viewing a single comment's thread. Return to all comments →
Haskell concise solution solve :: Int -> Int -> [Int] -> [Int] -> [Double] solve l r as bs = [sum [(f as bs i) * dx|i<-range], sum [pi*(f as bs i)^^2 * dx|i<-range]] where dx = 0.001 fl = fromIntegral l fr = fromIntegral r range = [fl,fl+dx..fr] f as bs x = sum[(fromIntegral a)*(x^^b)|(a,b)<-zip as bs]