aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-10 12:35:44 +0100
committerGitHub <noreply@github.com>2025-08-10 12:35:44 +0100
commit122f7cbb3e566c9b3bbb92566430050bb0b660f5 (patch)
tree4f35adb8fc5953b9eb00b35e4dec32b1f3a99866
parent0aff9ae799c2ca1cc668f62aa0a8f24689ca906e (diff)
parent2f39da2aa6a6fc31dd7da0db19f0bf690a76c48d (diff)
downloadperlweeklychallenge-club-122f7cbb3e566c9b3bbb92566430050bb0b660f5.tar.gz
perlweeklychallenge-club-122f7cbb3e566c9b3bbb92566430050bb0b660f5.tar.bz2
perlweeklychallenge-club-122f7cbb3e566c9b3bbb92566430050bb0b660f5.zip
Merge pull request #12485 from HVukman/branch-for-challenge-333
Branch for challenge 333
-rw-r--r--challenge-333/hvukman/f#/333_p1.fs18
-rw-r--r--challenge-333/hvukman/f#/333_p2.fs18
-rw-r--r--challenge-333/hvukman/lua/333_p1.lua18
-rw-r--r--challenge-333/hvukman/lua/333_p2.lua27
-rw-r--r--challenge-333/hvukman/picolisp/333_p1.l39
-rw-r--r--challenge-333/hvukman/picolisp/333_p2.l31
6 files changed, 151 insertions, 0 deletions
diff --git a/challenge-333/hvukman/f#/333_p1.fs b/challenge-333/hvukman/f#/333_p1.fs
new file mode 100644
index 0000000000..cc2b153ebb
--- /dev/null
+++ b/challenge-333/hvukman/f#/333_p1.fs
@@ -0,0 +1,18 @@
+// 333 part 1
+
+let input = [ [|2;1|] ; [|2;3|] ; [|2;5|] ];
+let input2 = [ [|1;4|] ; [|3;4|] ; [|10;4|] ];
+let input3 = [ [|0;0|] ; [|1;1|] ; [|2;3|] ];
+let input4 = [ [|10000;10000|] ; [|20000;20000|] ; [|30000;30000|] ];
+let inputs_1 = [ input; input2 ; input3; input4]
+// -- calculated the determinant
+// -- https://de.wikipedia.org/wiki/Kollinearität#Analytische_Geometrie
+let det (x:int array list) = let x1,x2,x3 = x[0].[0],x[1].[0],x[2].[0]
+ let y1,y2,y3 = x[0].[1],x[1].[1],x[2].[1]
+ let det = x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2
+ if det =0 then printf "%s\n" "true" else printf "%s\n" "false"
+
+for x in inputs_1 do
+ det (x)
+
+
diff --git a/challenge-333/hvukman/f#/333_p2.fs b/challenge-333/hvukman/f#/333_p2.fs
new file mode 100644
index 0000000000..1b6209313d
--- /dev/null
+++ b/challenge-333/hvukman/f#/333_p2.fs
@@ -0,0 +1,18 @@
+// 333 part 2
+
+let input_1 = [| 1;0; 2; 3; 0; 4; 5; 0 |]
+let input_2 = [| 1; 2; 3 |]
+let input_3 = [| 1; 2; 3; 0 |]
+let input_4 = [| 0; 0; 0; 0 |]
+let input_5 = [| 1; 2; 0; 3; 4 |]
+let inputs_2 = [ input_1; input_2; input_3; input_4; input_5 ]
+
+// if 0 double else x; then truncuate to length of x
+let dup (x:int array) = Array.collect (fun x -> match x with
+ |0 -> [|0;0|]
+ |_ -> [|x|] ) x |> Array.take (Array.length x)
+
+for i in (inputs_2) do
+ for j in dup(i) do
+ printf "%i " j
+ printf "%s\n" ""
diff --git a/challenge-333/hvukman/lua/333_p1.lua b/challenge-333/hvukman/lua/333_p1.lua
new file mode 100644
index 0000000000..af59673a14
--- /dev/null
+++ b/challenge-333/hvukman/lua/333_p1.lua
@@ -0,0 +1,18 @@
+
+function Straight(x)
+ local dummy = true
+ -- calculated the determinant
+ -- https://de.wikipedia.org/wiki/Kollinearität#Analytische_Geometrie
+ local det = x[1][1]*x[2][2] + x[2][1]*x[3][2]+
+ x[3][1]*x[1][2] - x[1][1]*x[3][2] - x[2][1]*x[1][2]
+ - x[3][1]*x[2][2]
+ print( det == 0)
+
+
+end
+
+Straight({ {2,1},{2,3},{2,5},{2,3}})
+Straight({ {1,4},{3,4},{10,4}})
+Straight({ {0,0},{1,1},{2,3}})
+Straight({ {1,1},{1,1},{1,1}} )
+Straight({ {1000000, 1000000} , {2000000, 2000000}, {3000000, 3000000}})
diff --git a/challenge-333/hvukman/lua/333_p2.lua b/challenge-333/hvukman/lua/333_p2.lua
new file mode 100644
index 0000000000..7fe02a96b7
--- /dev/null
+++ b/challenge-333/hvukman/lua/333_p2.lua
@@ -0,0 +1,27 @@
+-- insert in res while res<=x
+function Dup2(x)
+ local len = #x
+ local res = {}
+ for l,v in ipairs(x) do
+
+ if v == 0 then
+ table.insert(res,0)
+ if #res >= len then break end
+ table.insert(res,0)
+ else
+ table.insert(res,v)
+ end
+ if #res >= len then break end
+ end
+
+ for k,m in ipairs(res) do
+ io.write (m," ")
+ end
+ io.write ("\n")
+end
+
+Dup2({ 1; 0; 2; 3; 0; 4; 5; 0})
+Dup2({ 1;2;3})
+Dup2({ 1;2;3;0})
+Dup2({ 0;0;1;2})
+Dup2({ 1;2;0;3;4})
diff --git a/challenge-333/hvukman/picolisp/333_p1.l b/challenge-333/hvukman/picolisp/333_p1.l
new file mode 100644
index 0000000000..d8b55fc403
--- /dev/null
+++ b/challenge-333/hvukman/picolisp/333_p1.l
@@ -0,0 +1,39 @@
+(de dummy (X)
+ (mapcar * X 100000)
+)
+
+(setq inp
+ (list (list (2 1) (2 3) (2 5) ) (list (1 4) (3 4) (10 4) )
+ (list (0 0) (1 1) (2 3) )
+ (list (1 1) (1 1) (1 1) )
+ (mapcar dummy (list (1 1) (2 2) (3 3) ))
+ )
+)
+
+## caluclated the determinant between line 1, line 2 and 1 1 1
+(de straight (X)
+(let
+ (P1 (get X 1) P2 (get X 2) P3 (get X 3)
+ x1 (get P1 1) x2 (get P2 1)
+ x3 (get P3 1)
+ y1 (get P1 2) y2 (get P2 2)
+ y3 (get P3 2)
+ )
+ (if (= 0
+ ( + (sum + (mapcar (quote (X) (apply * X ))
+ (list (list x1 y2 ) (list x2 y3 ) (list x3 y1 ))))
+ (sum - (mapcar (quote (X) (apply * X ))
+ (list (list x1 y3 ) (list x2 y1 ) (list x3 y2 )))))
+ )
+ (println 'true)
+ (println 'false)
+ )
+)
+)
+
+
+(for X inp
+ (straight X)
+)
+
+#(load "perlpico/333_p1.l")
diff --git a/challenge-333/hvukman/picolisp/333_p2.l b/challenge-333/hvukman/picolisp/333_p2.l
new file mode 100644
index 0000000000..112fbb4807
--- /dev/null
+++ b/challenge-333/hvukman/picolisp/333_p2.l
@@ -0,0 +1,31 @@
+
+(de dup (Z)
+# link with made until length of z
+(make
+(for X (size Z)
+ (T (< (- (size Z) 1) (size (made)) ) (println (made)) )
+ (cond
+ (
+ (= 0 (get Z X))
+ # insert 0 twice if 0 and does not excede length og input z
+ (link 0)
+ (if (> (size Z) (size (made)) )
+ (link 0)
+ )
+ )
+ (T
+ (link (get Z X))
+ )
+ )
+)
+ (println (made))
+)
+)
+
+(setq inp (list '(1 2 3) '(1 2 3 0) '(0 0 1 2) '(1 2 0 0 3)))
+
+(for X inp
+ (dup X)
+)
+
+# (load "perlpico/333_p2.l")