From bda829817404df28abe1327c570de784678da235 Mon Sep 17 00:00:00 2001 From: Huy Vo Date: Thu, 3 Oct 2019 13:53:59 +0700 Subject: [PATCH 1/2] Add sum of odd elements solution in Scala --- .../9 - Sum of Odd Elements/sum_of_odd_elements.scala | 1 + 1 file changed, 1 insertion(+) create mode 100644 1 - Introduction/9 - Sum of Odd Elements/sum_of_odd_elements.scala diff --git a/1 - Introduction/9 - Sum of Odd Elements/sum_of_odd_elements.scala b/1 - Introduction/9 - Sum of Odd Elements/sum_of_odd_elements.scala new file mode 100644 index 0000000..6f32160 --- /dev/null +++ b/1 - Introduction/9 - Sum of Odd Elements/sum_of_odd_elements.scala @@ -0,0 +1 @@ +def f(arr:List[Int]):Int = arr.filter(_%2!=0).sum From 927fd26779f04f9fc480d28d900890e623614f0d Mon Sep 17 00:00:00 2001 From: Vinicius Ferreira Date: Thu, 31 Oct 2019 23:04:36 -0300 Subject: [PATCH 2/2] Add haskell solution to Compute the Area of a Polygon --- .../25 - Compute the Area of a Polygon/viniciusfk9.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 1 - Introduction/25 - Compute the Area of a Polygon/viniciusfk9.hs diff --git a/1 - Introduction/25 - Compute the Area of a Polygon/viniciusfk9.hs b/1 - Introduction/25 - Compute the Area of a Polygon/viniciusfk9.hs new file mode 100644 index 0000000..f29246e --- /dev/null +++ b/1 - Introduction/25 - Compute the Area of a Polygon/viniciusfk9.hs @@ -0,0 +1,11 @@ +import Control.Monad + +f (p1, p2) (q1, q2) = fromIntegral (p1 * q2 - q1 * p2) + +area lst = 0.5 * fromIntegral (abs . sum $ zipWith f lst (tail lst)) + +main = do + n <- fmap (read::String->Int) getLine + func <- forM [1..n] (\_->do + fmap ((\[a, b]->(a,b)) . map (read::String->Int).words) getLine :: IO (Int, Int)) + putStrLn $ show (area (func ++ take 1 func))