aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli <adeadmarshal@gmail.com>2025-10-26 19:49:14 +0330
committerAli <adeadmarshal@gmail.com>2025-10-26 19:49:14 +0330
commit0df8b5a4a3a9d91f285c5b1e5dd8a27e478df1e6 (patch)
tree02a34c93ca199554a3266097bf9d20df866fbc6d
parent9a7dd06fe8851783b7ffbdc45c2e8ea9b6f08824 (diff)
downloadperlweeklychallenge-club-0df8b5a4a3a9d91f285c5b1e5dd8a27e478df1e6.tar.gz
perlweeklychallenge-club-0df8b5a4a3a9d91f285c5b1e5dd8a27e478df1e6.tar.bz2
perlweeklychallenge-club-0df8b5a4a3a9d91f285c5b1e5dd8a27e478df1e6.zip
TWC344
-rw-r--r--challenge-344/deadmarshal/blog.txt1
-rw-r--r--challenge-344/deadmarshal/go/ch1.go30
-rw-r--r--challenge-344/deadmarshal/go/ch2.go31
-rw-r--r--challenge-344/deadmarshal/java/Ch1.java25
-rw-r--r--challenge-344/deadmarshal/java/Ch2.java30
-rw-r--r--challenge-344/deadmarshal/tcl/ch1.tcl25
-rw-r--r--challenge-344/deadmarshal/tcl/ch2.tcl42
7 files changed, 184 insertions, 0 deletions
diff --git a/challenge-344/deadmarshal/blog.txt b/challenge-344/deadmarshal/blog.txt
new file mode 100644
index 0000000000..e58799aee4
--- /dev/null
+++ b/challenge-344/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2025/10/twc344.html
diff --git a/challenge-344/deadmarshal/go/ch1.go b/challenge-344/deadmarshal/go/ch1.go
new file mode 100644
index 0000000000..a5526c6ff1
--- /dev/null
+++ b/challenge-344/deadmarshal/go/ch1.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "fmt"
+)
+
+func arrayFromCompute(arr []int, k int) []int {
+ i, carry := len(arr)-1, 0
+ res := []int{}
+ for i >= 0 || k > 0 || carry > 0 {
+ if i < 0 {
+ carry += k % 10
+ } else {
+ carry += arr[i] + k%10
+ i--
+ }
+ res = append([]int{carry % 10}, res...)
+ carry /= 10
+ k /= 10
+ }
+ return res
+}
+
+func main() {
+ fmt.Println(arrayFromCompute([]int{1, 2, 3, 4}, 12))
+ fmt.Println(arrayFromCompute([]int{2, 7, 4}, 181))
+ fmt.Println(arrayFromCompute([]int{9, 9, 9}, 1))
+ fmt.Println(arrayFromCompute([]int{1, 0, 0, 0, 0}, 9999))
+ fmt.Println(arrayFromCompute([]int{0}, 1000))
+}
diff --git a/challenge-344/deadmarshal/go/ch2.go b/challenge-344/deadmarshal/go/ch2.go
new file mode 100644
index 0000000000..2a1abbe149
--- /dev/null
+++ b/challenge-344/deadmarshal/go/ch2.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "fmt"
+)
+
+func arrayFormation(source [][]int, target []int) bool {
+ for i := 0; i < len(target); {
+ k := 0
+ for k < len(source) && source[k][0] != target[i] {
+ k++
+ }
+ if k == len(source) {
+ return false
+ }
+ j := 0
+ for j < len(source[k]) && target[i] == source[k][j] {
+ i++
+ j++
+ }
+ }
+ return true
+}
+
+func main() {
+ fmt.Println(arrayFormation([][]int{{2, 3}, {1}, {4}}, []int{1, 2, 3, 4}))
+ fmt.Println(arrayFormation([][]int{{1, 3}, {2, 4}}, []int{1, 2, 3, 4}))
+ fmt.Println(arrayFormation([][]int{{9, 1}, {5, 8}, {2}}, []int{5, 8, 2, 9, 1}))
+ fmt.Println(arrayFormation([][]int{{1}, {3}}, []int{1, 2, 3}))
+ fmt.Println(arrayFormation([][]int{{7, 4, 6}}, []int{7, 4, 6}))
+}
diff --git a/challenge-344/deadmarshal/java/Ch1.java b/challenge-344/deadmarshal/java/Ch1.java
new file mode 100644
index 0000000000..9fc552ef2a
--- /dev/null
+++ b/challenge-344/deadmarshal/java/Ch1.java
@@ -0,0 +1,25 @@
+import java.util.List;
+import java.util.LinkedList;
+
+public class Ch1 {
+ public static void main(String[] args) {
+ System.out.println(array_form_compute(new int[]{1,2,3,4},12));
+ System.out.println(array_form_compute(new int[]{2,7,4},181));
+ System.out.println(array_form_compute(new int[]{9,9,9},1));
+ System.out.println(array_form_compute(new int[]{1,0,0,0,0},9999));
+ System.out.println(array_form_compute(new int[]{0},1000));
+ }
+
+ private static List<Integer> array_form_compute(int[] arr,int k) {
+ int i = arr.length-1,carry = 0;
+ List<Integer> res = new LinkedList<>();
+ while(i >= 0 || k > 0 || carry > 0) {
+ carry += (i < 0 ? 0 : arr[i--]) + k % 10;
+ res.addFirst(carry % 10);
+ carry /= 10;
+ k /= 10;
+ }
+ return res;
+ }
+}
+
diff --git a/challenge-344/deadmarshal/java/Ch2.java b/challenge-344/deadmarshal/java/Ch2.java
new file mode 100644
index 0000000000..fa2b289bd5
--- /dev/null
+++ b/challenge-344/deadmarshal/java/Ch2.java
@@ -0,0 +1,30 @@
+public class Ch2 {
+ public static void main(String[] args) {
+ System.out.println(array_formation(new int[][]{{2,3},{1},{4}},
+ new int[]{1,2,3,4}));
+ System.out.println(array_formation(new int[][]{{1,3},{2,4}},
+ new int[]{1,2,3,4}));
+ System.out.println(array_formation(new int[][]{{9,1},{5,8},{2}},
+ new int[]{5,8,2,9,1}));
+ System.out.println(array_formation(new int[][]{{1},{3}},
+ new int[]{1,2,3}));
+ System.out.println(array_formation(new int[][]{{7,4,6}},
+ new int[]{7,4,6}));
+ }
+
+ private static boolean array_formation(int[][]source,
+ int[] target) {
+ for(int i = 0; i < target.length;) {
+ int k = 0;
+ while(k < source.length && source[k][0] != target[i]) ++k;
+ if(k == source.length) return false;
+ int j = 0;
+ while(j < source[k].length && target[i] == source[k][j]) {
+ ++i;
+ ++j;
+ }
+ }
+ return true;
+ }
+}
+
diff --git a/challenge-344/deadmarshal/tcl/ch1.tcl b/challenge-344/deadmarshal/tcl/ch1.tcl
new file mode 100644
index 0000000000..e3d2feeed6
--- /dev/null
+++ b/challenge-344/deadmarshal/tcl/ch1.tcl
@@ -0,0 +1,25 @@
+proc array_form_compute {arr k} {
+ set i [expr {[llength $arr] - 1}]
+ set carry 0
+ set res {}
+ while {$i >= 0 || $k > 0 || $carry > 0} {
+ if {$i >= 0} {
+ set d [lindex $arr $i]
+ incr i -1
+ } else {
+ set d 0
+ }
+ set carry [expr {$carry + $d + $k % 10}]
+ set res [linsert $res 0 [expr {$carry % 10}]]
+ set carry [expr {$carry / 10}]
+ set k [expr {$k / 10}]
+ }
+ return $res
+}
+
+puts [array_form_compute {1 2 3 4} 12]
+puts [array_form_compute {2 7 4} 181]
+puts [array_form_compute {9 9 9} 1]
+puts [array_form_compute {1 0 0 0 0} 9999]
+puts [array_form_compute {0} 1000]
+
diff --git a/challenge-344/deadmarshal/tcl/ch2.tcl b/challenge-344/deadmarshal/tcl/ch2.tcl
new file mode 100644
index 0000000000..e88a14c5f8
--- /dev/null
+++ b/challenge-344/deadmarshal/tcl/ch2.tcl
@@ -0,0 +1,42 @@
+proc array_formation {source target} {
+ set i 0
+ set target_len [llength $target]
+
+ while {$i < $target_len} {
+ set k 0
+ set found 0
+ set source_len [llength $source]
+
+ while {$k < $source_len} {
+ set sublist [lindex $source $k]
+ if {[lindex $sublist 0] == [lindex $target $i]} {
+ set found 1
+ break
+ }
+ incr k
+ }
+
+ if {!$found} {
+ return false
+ }
+
+ set sublist [lindex $source $k]
+ set j 0
+ set sublist_len [llength $sublist]
+
+ while {$j < $sublist_len && $i < $target_len && \
+ [lindex $sublist $j] == [lindex $target $i]} {
+ incr i
+ incr j
+ }
+ }
+
+ return true
+}
+
+puts [array_formation {{2 3} {1} {4}} {1 2 3 4}]
+puts [array_formation {{1 3} {2 4}} {1 2 3 4}]
+puts [array_formation {{9 1} {5 8} {2}} {5 8 2 9 1}]
+puts [array_formation {{1} {3}} {1 2 3}]
+puts [array_formation {{7 4 6}} {7 4 6}]
+