Last active
August 27, 2020 17:29
-
-
Save markroxor/aed9af671ea18364a9c31f24e1522c8c to your computer and use it in GitHub Desktop.
Revisions
-
markroxor revised this gist
Aug 27, 2020 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,9 @@ integrate l = [(n,p+1,(p+1)*d) | (n,p,d) <- l] sq l = [(n*n', p+p', d*d') | (n,p,d) <- l, (n',p',d') <- l ] -- evaluates the expr for a value solve_ l v = sum ([( fromIntegral n)*(( fromIntegral v)^p) / (fromIntegral d) | (n, p, d) <- l, p >= 0]) + ( sum [( fromIntegral n)/(( fromIntegral v)^(-p) * (fromIntegral d)) | (n, p, d) <- l, p < 0]) solve :: Int -> Int -> [Int] -> [Int] -> [Double] solve l r a b -
markroxor revised this gist
Aug 27, 2020 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,17 @@ import Text.Printf (printf) -- (n,p,d) represents coefficient, power, denominator of a algebric term. -- (4,2,3) == 4 * (x ^ 2) /3 -- f(x) == n1 * (x ^ p1) / d1 + n2 * (x ^ p2) / d2 .... -- integrates f(x) integrate l = [(n,p+1,(p+1)*d) | (n,p,d) <- l] -- squares a function - f^2(x) -- f(x) = (x+1) -- f^2(x) = (x+1)^2 sq l = [(n*n', p+p', d*d') | (n,p,d) <- l, (n',p',d') <- l ] -- evaluates the expr for a value solve_ l v = sum $ [( fromIntegral n)*(( fromIntegral v)^p) / (fromIntegral d) | (n, p, d) <- l] solve :: Int -> Int -> [Int] -> [Int] -> [Double] @@ -14,6 +21,7 @@ solve l r a b where c = [1,1 ..] f = zip3 a b c f_area = integrate f f_volume = integrate $ sq f -
markroxor revised this gist
Aug 27, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,8 @@ import Text.Printf (printf) -- (n,p,d) represents coefficient, power, denominator of a algebric term. -- (4,2,3) == 4 * (x ^ 2) /3 integrate l = [(n,p+1,(p+1)*d) | (n,p,d) <- l] sq l = [(n*n', p+p', d*d') | (n,p,d) <- l, (n',p',d') <- l ] -
markroxor created this gist
Aug 27, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import Text.Printf (printf) integrate l = [(n,p+1,(p+1)*d) | (n,p,d) <- l] sq l = [(n*n', p+p', d*d') | (n,p,d) <- l, (n',p',d') <- l ] solve_ l v = sum $ [( fromIntegral n)*(( fromIntegral v)^p) / (fromIntegral d) | (n, p, d) <- l] solve :: Int -> Int -> [Int] -> [Int] -> [Double] solve l r a b | otherwise = [area, vol] where c = [1,1 ..] f = zip3 a b c f_area = integrate f f_volume = integrate $ sq f area = (solve_ f_area r) - (solve_ f_area l) vol = pi * ((solve_ f_volume r) - (solve_ f_volume l)) main :: IO () main = getContents >>= mapM_ (printf "%.1f\n"). (\[a, b, [l, r]] -> solve l r a b). map (map read. words). lines