From d1fc876cc99e0d6cb2cfa41377d2098b3a5aecbf Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 24 Aug 2025 11:19:53 +0200 Subject: Create 335_p1.lua --- challenge-335/hvukman/lua/335_p1.lua | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 challenge-335/hvukman/lua/335_p1.lua diff --git a/challenge-335/hvukman/lua/335_p1.lua b/challenge-335/hvukman/lua/335_p1.lua new file mode 100644 index 0000000000..fae6ac2a3a --- /dev/null +++ b/challenge-335/hvukman/lua/335_p1.lua @@ -0,0 +1,50 @@ +local inp = {{ "bella", "label", "roller" }, { "cool", "lock", "cook" } , { "hello", "world", "pole"} + , { "abc", "def", "ghi" }, { "aab", "aac", "aaa"}} + + +function Common(X) + local unique = {} + + + for i,v in ipairs(X) do + for j=1,#v do + local sub = string.sub(v,j,j) + unique[sub] = true + end + end + + + local res = {} + io.write ("Output: ") + -- check each unique character + for i,_ in pairs(unique) do + local res = {} + for _,v in ipairs(X) do + + local sum =0 + for index in (v):gmatch(i) do + sum = sum + 1 + -- print("index ", index) + end + if sum>0 then + table.insert(res,sum) + end + end + + if #res==3 then + table.sort(res) + + for jj=1,res[1] do + io.write (i," ") + end + + end + + end + print("") +end + +for i,v in ipairs(inp) do + Common(v) + +end -- cgit From 2469d3089a37f6a41bce2906a59319c1e1866f83 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 24 Aug 2025 11:20:06 +0200 Subject: Add files via upload --- challenge-335/hvukman/lua/335_p2.lua | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 challenge-335/hvukman/lua/335_p2.lua diff --git a/challenge-335/hvukman/lua/335_p2.lua b/challenge-335/hvukman/lua/335_p2.lua new file mode 100644 index 0000000000..d60e13baff --- /dev/null +++ b/challenge-335/hvukman/lua/335_p2.lua @@ -0,0 +1,49 @@ +local moves = { {{0, 0} , {2, 0} , {1, 1} , {2, 1} , {2 ,2} } + , { {0, 0} , {1,1} , {0, 1} , {0, 2} , {1 ,0}, {2,0} } + , { {0, 0} , {1,1} , {2, 0} , {1, 0} , {1 ,2}, {2,1}, {0, 1} , {0 ,2}, {2,2} } + , { {0, 0} , {1,1 } } + , { {1,1} , {0,0} , {2,2} , {0, 1} , {1 ,0}, {0,2} } +} +local magic_square = { {4,9,2}, {3,5,7},{8,1,6}} +-- https://en.wikipedia.org/wiki/Magic_square +-- any winning combination is 15 + +function Winner(X) + -- a game with less than 3 moves cannot be won + if #X>=3 then + + local score_a = 0 + local score_b = 0 + + for j=1,#X do + + if j%2==0 then -- move b + score_b = score_b + magic_square[1+X[j][1]] [1+X[j][2]] + else -- move a + score_a = score_a + magic_square[1+X[j][1]] [1+X[j][2]] + end + -- winning score is 15 + if score_a == 15 then + print ("Winner A") + else if score_b == 15 then + print ("winner B") + end + -- if at the end no score is 15 => draw + if j==#X and score_a~=15 and score_b~=15 then + print("draw") + end + + end + end + else + print("pending") + end + +end + +for _,v in ipairs(moves) do + Winner(v) +end + + + -- cgit From fcbb28dd599241251845b5458337c280c0f38ec7 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 24 Aug 2025 11:21:01 +0200 Subject: Create 335_p1.l --- challenge-335/hvukman/picolisp/335_p1.l | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 challenge-335/hvukman/picolisp/335_p1.l diff --git a/challenge-335/hvukman/picolisp/335_p1.l b/challenge-335/hvukman/picolisp/335_p1.l new file mode 100644 index 0000000000..d2928449c5 --- /dev/null +++ b/challenge-335/hvukman/picolisp/335_p1.l @@ -0,0 +1,38 @@ +(setq words '( '("bella" "label" "roller") '("cool" "lock" "cook") )) + +(de flatten (Lst) + (fish atom Lst) ) + +(de common (XX) +(setq chars (uniq (flatten (mapcar chop XX)))) + (for Y chars + # (println "char " Y) + (make + (for X XX + (let dummy (filter (quote (Z) (= Z Y )) (chop X)) + (if dummy + (link (size dummy)) + ) + ) + ) + + (cond + ( (= (size (made)) (size XX)) + (for Z (car (made)) + (print Y " ") + ) + (println "") + ) + ) + + ) + +) +) + +(for X words + (common X) +) + + +# (load "perlpico/335_p1.l") -- cgit From e3fbd1fea4f9be222d42c378822cabc71d5f0ac0 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 24 Aug 2025 11:21:21 +0200 Subject: Add files via upload --- challenge-335/hvukman/picolisp/335_p2.l | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 challenge-335/hvukman/picolisp/335_p2.l diff --git a/challenge-335/hvukman/picolisp/335_p2.l b/challenge-335/hvukman/picolisp/335_p2.l new file mode 100644 index 0000000000..6c2f0ff0b1 --- /dev/null +++ b/challenge-335/hvukman/picolisp/335_p2.l @@ -0,0 +1,65 @@ + +(setq magic_square '( (4 9 2) (3 5 7) (8 1 6)) ) + +(de Winner (X) + (if (<= 3 (length X)) + (let (score_a 0 score_b 0) + + (for Y (length X) + + (let (point (get X Y) point_x (get point 1) point_y (get point 2) + magic_square_x (get magic_square (+ 1 point_x)) + magic_square_y (get magic_square_x (+ 1 point_y)) + ) + # magic_square_y as point to get from magic_square + # (println "point " point) + # (println "mpoint " magic_square_y) + + + # every second move by b + (if (= 0 (% Y 2)) + (setq score_b (+ score_b magic_square_y)) + (setq score_a (+ score_a magic_square_y)) + ) + # (println "score_a " score_a) + # (println "score_b " score_b) + (cond + + ( + (= score_a 15) + 'winnerA + ) + ( + (= score_b 15) + 'winnerB + ) + ( + (= Y (length X)) + 'draw + ) + + + ) + + ) + + ) + + ) + 'pending + ) + +) + +(setq games '( ( (0 0) (2 0) (1 1) (2 1) (2 2) ) + ( (0 0) (1 1) (0 1) (0 2) (1 2) (2 0)) + ((0 0) (1 1) (2 0) (1 0) (1 2) (2 1) (0 1) (0 2) (2 2)) + ( (0 0 ) (1 1)) + ( (1 1) (0 0) (2 2) (0 1) (1 0) (0 2)) +) ) + +(for X games + (println (Winner X )) +) + +# (load "perlpico/335_p2.l") \ No newline at end of file -- cgit