diff options
| author | Ali <adeadmarshal@gmail.com> | 2025-07-30 11:15:03 +0330 |
|---|---|---|
| committer | Ali <adeadmarshal@gmail.com> | 2025-07-30 11:15:03 +0330 |
| commit | 13beee7dd987b2f1020e789b3d327fe3e21cf863 (patch) | |
| tree | 663e0e7d3b9fb94388b6b0dd10b8e262e5fb49a4 | |
| parent | 1ff2c9796a511d63231d3757acb27e4046a91fb2 (diff) | |
| download | perlweeklychallenge-club-13beee7dd987b2f1020e789b3d327fe3e21cf863.tar.gz perlweeklychallenge-club-13beee7dd987b2f1020e789b3d327fe3e21cf863.tar.bz2 perlweeklychallenge-club-13beee7dd987b2f1020e789b3d327fe3e21cf863.zip | |
TWC332
| -rw-r--r-- | challenge-332/deadmarshal/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/java/Ch1.java | 19 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/java/Ch2.java | 16 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/modula-3/Ch1/src/Ch1.m3 | 31 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/modula-3/Ch1/src/m3makefile | 5 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/modula-3/Ch2/src/Ch2.m3 | 30 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/modula-3/Ch2/src/m3makefile | 6 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/perl/ch-1.pl | 12 | ||||
| -rw-r--r-- | challenge-332/deadmarshal/perl/ch-2.pl | 15 |
9 files changed, 135 insertions, 0 deletions
diff --git a/challenge-332/deadmarshal/blog.txt b/challenge-332/deadmarshal/blog.txt new file mode 100644 index 0000000000..2f7784bfdb --- /dev/null +++ b/challenge-332/deadmarshal/blog.txt @@ -0,0 +1 @@ +https://deadmarshal.blogspot.com/2025/07/twc332.html diff --git a/challenge-332/deadmarshal/java/Ch1.java b/challenge-332/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..ec80284c69 --- /dev/null +++ b/challenge-332/deadmarshal/java/Ch1.java @@ -0,0 +1,19 @@ +import java.util.ArrayList; +import java.util.List; + +public class Ch1 { + public static void main(String[] args) { + System.out.println(binary_date("2025-07-26")); + System.out.println(binary_date("2000-02-02")); + System.out.println(binary_date("2024-12-31")); + } + + private static String binary_date(String date) { + List<String> res = new ArrayList<>(); + for (var s : date.split("-")) { + int e = Integer.parseInt(s); + res.add(Integer.toBinaryString(e)); + } + return String.join("-", res); + } +} diff --git a/challenge-332/deadmarshal/java/Ch2.java b/challenge-332/deadmarshal/java/Ch2.java new file mode 100644 index 0000000000..ba0eeb0fa3 --- /dev/null +++ b/challenge-332/deadmarshal/java/Ch2.java @@ -0,0 +1,16 @@ +import java.util.HashMap; +import java.util.Map; + +public class Ch2 { + public static void main(String[] args) { + System.out.println(odd_letters("weekly")); + System.out.println(odd_letters("perl")); + System.out.println(odd_letters("challenge")); + } + + private static boolean odd_letters(String s) { + Map<Character, Integer> h = new HashMap<>(); + for (var c : s.toCharArray()) h.merge(c, 1, Integer::sum); + return h.values().stream().allMatch(a -> a % 2 != 0); + } +} diff --git a/challenge-332/deadmarshal/modula-3/Ch1/src/Ch1.m3 b/challenge-332/deadmarshal/modula-3/Ch1/src/Ch1.m3 new file mode 100644 index 0000000000..d96944a1f2 --- /dev/null +++ b/challenge-332/deadmarshal/modula-3/Ch1/src/Ch1.m3 @@ -0,0 +1,31 @@ +MODULE Ch1 EXPORTS Main; + +IMPORT SIO,Text,TextConv,Fmt,Scan,Lex,FloatMode; +FROM StableError IMPORT Halt; + +PROCEDURE BinaryDate(READONLY S:TEXT):TEXT + RAISES{Lex.Error,FloatMode.Trap} = + VAR A := ARRAY[0..2] OF TEXT{"",..}; + BEGIN + A[0] := Text.Sub(S,0,4); + A[1] := Text.Sub(S,5,2); + A[2] := Text.Sub(S,8,2); + FOR I := FIRST(A) TO LAST(A) DO + A[I] := Fmt.Int(Scan.Int(A[I]),2) + END; + RETURN TextConv.Implode(A,'-') + END BinaryDate; + +BEGIN + TRY + SIO.PutText(BinaryDate("2025-07-26")); SIO.Nl(); + SIO.PutText(BinaryDate("2000-02-02")); SIO.Nl(); + SIO.PutText(BinaryDate("2024-12-31")); SIO.Nl() + EXCEPT + Lex.Error => Halt("Lex.Error") + | FloatMode.Trap => Halt("FloatMode.Trap") + ELSE + Halt("Some other exception!") + END; +END Ch1. + diff --git a/challenge-332/deadmarshal/modula-3/Ch1/src/m3makefile b/challenge-332/deadmarshal/modula-3/Ch1/src/m3makefile new file mode 100644 index 0000000000..4182be12b1 --- /dev/null +++ b/challenge-332/deadmarshal/modula-3/Ch1/src/m3makefile @@ -0,0 +1,5 @@ +import("libm3") +import("libsio") +import("stable") +implementation("Ch1") +program("Ch1") diff --git a/challenge-332/deadmarshal/modula-3/Ch2/src/Ch2.m3 b/challenge-332/deadmarshal/modula-3/Ch2/src/Ch2.m3 new file mode 100644 index 0000000000..69b0ee199b --- /dev/null +++ b/challenge-332/deadmarshal/modula-3/Ch2/src/Ch2.m3 @@ -0,0 +1,30 @@ +MODULE Ch2 EXPORTS Main; + +IMPORT SIO,Text,CharIntTbl; + +PROCEDURE OddLetters(READONLY S:TEXT):BOOLEAN = + VAR + H := NEW(CharIntTbl.Default).init(Text.Length(S)); + It:CharIntTbl.Iterator; + K:CHAR; + V:INTEGER; + BEGIN + FOR I := 0 TO Text.Length(S)-1 DO + K := Text.GetChar(S,I); + IF NOT H.get(K,V) THEN EVAL H.put(K,1) + ELSE EVAL H.put(K,V+1) + END + END; + It := H.iterate(); + WHILE It.next(K,V) DO + IF V MOD 2 = 0 THEN RETURN FALSE END + END; + RETURN TRUE + END OddLetters; + +BEGIN + SIO.PutBool(OddLetters("weekly")); SIO.Nl(); + SIO.PutBool(OddLetters("perl")); SIO.Nl(); + SIO.PutBool(OddLetters("challenge")); SIO.Nl() +END Ch2. + diff --git a/challenge-332/deadmarshal/modula-3/Ch2/src/m3makefile b/challenge-332/deadmarshal/modula-3/Ch2/src/m3makefile new file mode 100644 index 0000000000..8a1e1d9bf5 --- /dev/null +++ b/challenge-332/deadmarshal/modula-3/Ch2/src/m3makefile @@ -0,0 +1,6 @@ +import("libm3") +import("libsio") +table("CharInt","Char","Integer") +implementation("Ch2") +program("Ch2") + diff --git a/challenge-332/deadmarshal/perl/ch-1.pl b/challenge-332/deadmarshal/perl/ch-1.pl new file mode 100644 index 0000000000..4c2c1d89e4 --- /dev/null +++ b/challenge-332/deadmarshal/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +sub binary_date{ + $_[0] =~ s/(\d+)/{sprintf "%b",$1}/rge +} + +printf "%s\n",binary_date('2025-07-26'); +printf "%s\n",binary_date('2000-02-02'); +printf "%s\n",binary_date('2024-12-31'); + diff --git a/challenge-332/deadmarshal/perl/ch-2.pl b/challenge-332/deadmarshal/perl/ch-2.pl new file mode 100644 index 0000000000..f115f6bf6d --- /dev/null +++ b/challenge-332/deadmarshal/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util qw(all); + +sub odd_letters{ + my %h; + $h{$_}++ foreach split '',$_[0]; + all{$h{$_} & 1} keys %h +} + +printf "%d\n",odd_letters('weekly'); +printf "%d\n",odd_letters('perl'); +printf "%d\n",odd_letters('challenge'); + |
