aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-14 23:41:31 +0100
committerGitHub <noreply@github.com>2025-09-14 23:41:31 +0100
commit75159e6eb9d43079bb3bfe1e067e5fb68cb67ddf (patch)
tree363737de631966490ad2a2ee3b4d4fe3f2d4b9cd
parent652e42b40b5f364131a6e56757ac70e71e580b72 (diff)
parent93d8243b76fc2e42f88923938f5e5d53e826b7ef (diff)
downloadperlweeklychallenge-club-75159e6eb9d43079bb3bfe1e067e5fb68cb67ddf.tar.gz
perlweeklychallenge-club-75159e6eb9d43079bb3bfe1e067e5fb68cb67ddf.tar.bz2
perlweeklychallenge-club-75159e6eb9d43079bb3bfe1e067e5fb68cb67ddf.zip
Merge pull request #12673 from HVukman/branch-for-challenge-338
Branch for challenge 338
-rw-r--r--challenge-338/hvukman/lua/338_p1.lua31
-rw-r--r--challenge-338/hvukman/lua/338_p2.lua29
-rw-r--r--challenge-338/hvukman/racket/338_p1.rkt33
-rw-r--r--challenge-338/hvukman/racket/338_p2.rkt29
4 files changed, 122 insertions, 0 deletions
diff --git a/challenge-338/hvukman/lua/338_p1.lua b/challenge-338/hvukman/lua/338_p1.lua
new file mode 100644
index 0000000000..020be54f1d
--- /dev/null
+++ b/challenge-338/hvukman/lua/338_p1.lua
@@ -0,0 +1,31 @@
+
+local function highestrow(x)
+
+ local mat = x
+
+ local highest={}
+
+ for i=1,#mat do
+ local sum = 0
+ for _,v in ipairs(mat[i]) do
+ sum=sum+v
+ end
+ table.insert(highest,sum)
+ end
+
+ table.sort(highest)
+ print(highest[#highest])
+end
+
+local inputs = {{ {4,4,4,4},{10,0,0,0},{2,2,2,9} } ,
+ { {1, 5},{7, 3},{3, 5}},
+ { {1, 2, 3},{3,2,1}},
+ { {2, 8,7},{7,1,3},{1,9,5}},
+ {{10, 20,30},{5,5,5},{0,100,0},{25,25,25}}
+ }
+
+for i=1,#inputs do
+ highestrow(inputs[i])
+end
+
+
diff --git a/challenge-338/hvukman/lua/338_p2.lua b/challenge-338/hvukman/lua/338_p2.lua
new file mode 100644
index 0000000000..90290f3cf6
--- /dev/null
+++ b/challenge-338/hvukman/lua/338_p2.lua
@@ -0,0 +1,29 @@
+local function max_distance(x,y)
+
+ local distances = {}
+
+ for i=1,#x do
+ local distance_ = {}
+ for j=1,#y do
+ table.insert(distance_,math.abs(x[i]-y[j]))
+ end
+ table.sort(distance_)
+ table.insert(distances,distance_[#distance_])
+ end
+ table.sort(distances)
+ print(distances[#distances])
+end
+
+local inputs = {{{4, 5, 7},{9, 1, 3, 4}} ,
+ { {2, 3, 5, 4},{3, 2, 5, 5, 8, 7} },
+ { {2, 1, 11, 3} , {2, 5, 10, 2}},
+ {{1,2,3},{3,2,1}},
+ {{1,0,2,3},{5,0}}
+ }
+
+for _,v in ipairs(inputs) do
+ max_distance(v[1],v[2])
+end
+
+
+
diff --git a/challenge-338/hvukman/racket/338_p1.rkt b/challenge-338/hvukman/racket/338_p1.rkt
new file mode 100644
index 0000000000..e7833dc9db
--- /dev/null
+++ b/challenge-338/hvukman/racket/338_p1.rkt
@@ -0,0 +1,33 @@
+#lang racket
+
+(require rackunit)
+(require srfi/1) ; for fold
+
+(define input '((4 4 4 4) (10 0 0 0)
+ (2 2 2 9)))
+
+(define input2 '((1 5) (7 3)
+ (3 5) ))
+
+(define input3 '((1 2 3) (3 2 1)
+ ))
+
+(define input4 '((2 8 7) (7 1 3) (1 9 5)
+ ))
+
+(define input5 '((10 20 30) (5 5 5) (0 100 0) (25 25 25)
+ ))
+
+
+(check-equal? '(16 10 6 17 100)
+(for/list ( [i (list input input2 input3 input4 input5)]
+ )
+ (apply max (map (lambda (x) (fold + 0 x)) i))
+ ))
+
+(for/list ( [i (list input input2 input3 input4 input5)]
+ )
+ (apply max (map (lambda (x) (fold + 0 x)) i))
+ )
+
+
diff --git a/challenge-338/hvukman/racket/338_p2.rkt b/challenge-338/hvukman/racket/338_p2.rkt
new file mode 100644
index 0000000000..cb1be018c5
--- /dev/null
+++ b/challenge-338/hvukman/racket/338_p2.rkt
@@ -0,0 +1,29 @@
+#lang racket
+(require rackunit)
+
+(define (max_dist x y)
+(apply max
+ (map (lambda (z) (apply max z))
+ (for/list ([i x])
+ (for/list ([j (length y)])
+ (abs (- i (list-ref y j)))
+ )
+ )
+ )
+ )
+)
+
+(max_dist '(4 5 7) '(9 1 3 4))
+(check-equal? 6 (max_dist '(4 5 7) '(9 1 3 4)))
+
+(max_dist '(2 3 5 4) '(3 2 5 5 8 7))
+(check-equal? 6 (max_dist '(2 3 5 4) '(3 2 5 5 8 7)))
+
+(max_dist '(2 1 11 3) '(2 5 10 2))
+(check-equal? 9 (max_dist '(2 1 11 3) '(2 5 10 2)))
+
+(max_dist '(1 2 3) '(3 2 1))
+(check-equal? 2 (max_dist '(1 2 3) '(3 2 1)))
+
+(max_dist '(1 0 2 3) '(5 0))
+(check-equal? 5 (max_dist '(1 2 3) '(3 2 1)))