From 501d337689357936eba691cb4e2ae5f83fd1f70b Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 26 Oct 2025 22:08:50 +0100 Subject: Create 344_p1.lua --- challenge-344/hvukman/lua/344_p1.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-344/hvukman/lua/344_p1.lua diff --git a/challenge-344/hvukman/lua/344_p1.lua b/challenge-344/hvukman/lua/344_p1.lua new file mode 100644 index 0000000000..353d44ba6c --- /dev/null +++ b/challenge-344/hvukman/lua/344_p1.lua @@ -0,0 +1,29 @@ + +local function arrayfromcompute(ints,x) + + local str = "" + + for i,v in ipairs(ints) do + str = str .. v + end + + str = tostring(tonumber(str) + x ) + local empty = {} + + for i=1,#str do + table.insert(empty,string.sub(str,i,i)) + end + + for i,v in ipairs(empty) do + io.write(v," ") + end + io.write('\n') +end + + +arrayfromcompute({1,2,3,4},12) +arrayfromcompute({2,7,4},181) +arrayfromcompute({9,9,9},1) +arrayfromcompute({1,0,0,0,0},9999) +arrayfromcompute({0},1000) + -- cgit From 3569563568323232874b5e32736dbf821eee0c8d Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 26 Oct 2025 22:09:14 +0100 Subject: Create 344_p2.lua --- challenge-344/hvukman/lua/344_p2.lua | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 challenge-344/hvukman/lua/344_p2.lua diff --git a/challenge-344/hvukman/lua/344_p2.lua b/challenge-344/hvukman/lua/344_p2.lua new file mode 100644 index 0000000000..64a78a55eb --- /dev/null +++ b/challenge-344/hvukman/lua/344_p2.lua @@ -0,0 +1,73 @@ + + local function permgen (a, n) + if n == 0 then + coroutine.yield(a) + else + for i=1,n do + -- put i-th element as the last one + a[n], a[i] = a[i], a[n] + -- generate all permutations of the other elements + permgen(a, n - 1) + -- restore i-th element + a[n], a[i] = a[i], a[n] + + end + end + end + + + local function result (a,t) + local found = {} + local count = 0 + + -- a is permutation + for _,v in ipairs(a) do + for _,k in ipairs(v) do + table.insert(found,k) + end + end + + for i=1,#found do + + -- if key=value add up + if found[i]==t[i] then + count = count + 1 + end + end + -- true if all keys equals values + return count==#t + end + + + + local function perm (a) + local n = #a + local co = coroutine.create(function () permgen(a, n) end) + return function () -- iterator + local code, res = coroutine.resume(co) + return res + end + end + + + +local function arrayform(t,x) + + local search = false + + for p in perm(x) do + search=(result (p,t)) + if result (p,t)==true then break end + end + + print(search) + +end + + +arrayform({1,2,3,4},{{2, 3},{1},{4}}) +arrayform({1,2,3,4},{{1, 3},{2,4}}) +arrayform({5, 8, 2, 9, 1},{{9,1},{5,8},{2}}) +arrayform({1,2,3},{{1},{3}}) +arrayform({7,4,6},{{7,4,6}}) +-- permute dummy -- cgit From 2c0ca222d3d521b230234ce68182d8a23a5605d3 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 26 Oct 2025 22:09:44 +0100 Subject: Create 344_p1.l --- challenge-344/hvukman/picolisp/344_p1.l | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 challenge-344/hvukman/picolisp/344_p1.l diff --git a/challenge-344/hvukman/picolisp/344_p1.l b/challenge-344/hvukman/picolisp/344_p1.l new file mode 100644 index 0000000000..17fa1208df --- /dev/null +++ b/challenge-344/hvukman/picolisp/344_p1.l @@ -0,0 +1,11 @@ + +(de array_from_compute (X Y ) + (mapcar '((Z) (prin Z " , ")) (mapcar format (chop (format (+ (format (pack (mapcar format X))) Y ))))) + (prinl "^J") +) + +(array_from_compute '(1 2 3 4) 12) +(array_from_compute '(2 7 4) 181) +(array_from_compute '(9 9 9) 1) +(array_from_compute '(1, 0, 0, 0, 0) 9999) +(array_from_compute '(0) 1000) -- cgit From 8b86e6c81baf0bd9e19fad2a90b2ce5c11deda31 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 26 Oct 2025 22:10:18 +0100 Subject: Create 344_p2.l --- challenge-344/hvukman/picolisp/344_p2.l | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-344/hvukman/picolisp/344_p2.l diff --git a/challenge-344/hvukman/picolisp/344_p2.l b/challenge-344/hvukman/picolisp/344_p2.l new file mode 100644 index 0000000000..fdc57466bc --- /dev/null +++ b/challenge-344/hvukman/picolisp/344_p2.l @@ -0,0 +1,35 @@ +# for permutations +(load "@lib/simul.l") + +(de flatten (Lst) + (fish atom Lst) +) + +# map get over flattened permutations +# see if target is member +(de arrayformation (X Y) + (if + (member X + (make + (for Y (mapcar flatten (permute Y)) + (link + (make (for Z (length Y) + (link (get Y Z)) + ) + ) + ) + ) + ) + ) + 'true + 'false + ) +) + +(arrayformation '(1 2 3 4) '( (2 3 ) (1) (4))) +(arrayformation '(1 2 3 4) '( (1 3 ) ( 2 4) )) +(arrayformation '(5 8 2 9 1) '( (9 1 ) ( 5 8 ) (2) )) +(arrayformation '(1 2 3) '( ( 1 ) (3 ) )) +(arrayformation '(7 4 6) '( ( 7 4 6 ) )) + + -- cgit From bf1573a3b7ddd48d6c82bac798923235f9c19d42 Mon Sep 17 00:00:00 2001 From: HVukman Date: Sun, 26 Oct 2025 22:10:55 +0100 Subject: Create 344_p2.k --- challenge-344/hvukman/k/344_p2.k | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 challenge-344/hvukman/k/344_p2.k diff --git a/challenge-344/hvukman/k/344_p2.k b/challenge-344/hvukman/k/344_p2.k new file mode 100644 index 0000000000..404d1036e4 --- /dev/null +++ b/challenge-344/hvukman/k/344_p2.k @@ -0,0 +1,8 @@ +prm:{$[0=x;,!0;,/(prm x-1){?[1+x;y;0]}/:\:!x]} +perm:{x[prm[#x]]} +/ returns 0! if no permutation equals target +{target::x;source::y; &1=*/'{x=target}'(,//'perm(source))}[1 2 3 4;((2;3);(1);(4)) ] +{target::x;source::y; &1=*/'{x=target}'(,//'perm(source))}[1 2 3 4;((1;3);(2;4))] +{target::x;source::y; &1=*/'{$[(#x)=#target;x=target;0 ]}'(,//'perm(source))}[5 8 2 9 1;((9;1);(5;8);(2))] +{target::x;source::y; &1=*/'{$[(#x)=#target;x=target;0 ]}'(,//'perm(source))}[1 2 3;((1);(3))] +{target::x;source::y; &1=*/'{x=target}'(,//'perm(source))}[7 4 6;((7;4;6))] -- cgit