From eed457ef4bac2106090deae9fbbd80f22ef291bd Mon Sep 17 00:00:00 2001 From: fabriciorby Date: Fri, 13 Sep 2024 23:59:31 +0200 Subject: [PATCH 1/2] calculate perimeter in clj --- .../fabriciorby.clj | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 1 - Introduction/24 - Compute the Perimeter of a Polygon/fabriciorby.clj diff --git a/1 - Introduction/24 - Compute the Perimeter of a Polygon/fabriciorby.clj b/1 - Introduction/24 - Compute the Perimeter of a Polygon/fabriciorby.clj new file mode 100644 index 0000000..56f5127 --- /dev/null +++ b/1 - Introduction/24 - Compute the Perimeter of a Polygon/fabriciorby.clj @@ -0,0 +1,9 @@ +(defn euclidian-distance [[[x1 y1] [x2 y2]]] + (Math/sqrt (+ (Math/pow (- x1 x2) 2) (Math/pow (- y1 y2) 2)))) + +(def points (repeatedly (read-string (read-line)) + #(map read-string (.split (read-line) " ")))) + +(println (->> (partition 2 1 points points) + (map euclidian-distance) + (reduce +))) From d400618252eaaa27f45d8076ec74c6a191f3866b Mon Sep 17 00:00:00 2001 From: fabriciorby Date: Sat, 14 Sep 2024 00:13:43 +0200 Subject: [PATCH 2/2] calculate area in clj --- .../25 - Compute the Area of a Polygon/fabriciorby.clj | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 1 - Introduction/25 - Compute the Area of a Polygon/fabriciorby.clj diff --git a/1 - Introduction/25 - Compute the Area of a Polygon/fabriciorby.clj b/1 - Introduction/25 - Compute the Area of a Polygon/fabriciorby.clj new file mode 100644 index 0000000..9d9460f --- /dev/null +++ b/1 - Introduction/25 - Compute the Area of a Polygon/fabriciorby.clj @@ -0,0 +1,9 @@ +(defn quadrilateral-area [[[x1 y1] [x2 y2]]] + (* (- (* x1 y2) (* x2 y1)) 0.5)) + +(def points (repeatedly (read-string (read-line)) + #(map read-string (.split (read-line) " ")))) + +(println (->> (partition 2 1 points points) + (map quadrilateral-area) + (reduce +)))