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 +))) 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 +)))