diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2024-06-04 02:33:34 -0400 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2024-06-04 02:33:34 -0400 |
| commit | da49573769684a6facb64cdb6cb267b59086e76d (patch) | |
| tree | da1903fb0c227571afbd14329285c037c045b868 | |
| parent | 6b1c67381886ee30e0dd9f9356340350101139b8 (diff) | |
| download | perlweeklychallenge-club-da49573769684a6facb64cdb6cb267b59086e76d.tar.gz perlweeklychallenge-club-da49573769684a6facb64cdb6cb267b59086e76d.tar.bz2 perlweeklychallenge-club-da49573769684a6facb64cdb6cb267b59086e76d.zip | |
TWC272
| -rw-r--r-- | challenge-272/deadmarshal/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/java/Ch1.java | 7 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/java/Ch2.java | 16 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/lua/ch-1.lua | 10 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/lua/ch-2.lua | 16 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/modula-3/ch1/src/Ch1.m3 | 30 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/modula-3/ch1/src/m3makefile | 5 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/modula-3/ch2/src/Ch2.m3 | 19 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/modula-3/ch2/src/m3makefile | 5 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/perl/ch-1.pl | 11 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/perl/ch-2.pl | 14 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-272/deadmarshal/raku/ch-2.raku | 16 |
13 files changed, 160 insertions, 0 deletions
diff --git a/challenge-272/deadmarshal/blog.txt b/challenge-272/deadmarshal/blog.txt new file mode 100644 index 0000000000..dbb200ed12 --- /dev/null +++ b/challenge-272/deadmarshal/blog.txt @@ -0,0 +1 @@ +https://deadmarshal.blogspot.com/2024/06/twc272.html diff --git a/challenge-272/deadmarshal/java/Ch1.java b/challenge-272/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..6f589b0407 --- /dev/null +++ b/challenge-272/deadmarshal/java/Ch1.java @@ -0,0 +1,7 @@ +public class Ch1 { + public static void main(String[] args) { + System.out.println("1.1.1.1".replaceAll("\\.", "[.]")); + System.out.println("255.101.1.0".replaceAll("\\.", "[.]")); + } +} + diff --git a/challenge-272/deadmarshal/java/Ch2.java b/challenge-272/deadmarshal/java/Ch2.java new file mode 100644 index 0000000000..91614ab462 --- /dev/null +++ b/challenge-272/deadmarshal/java/Ch2.java @@ -0,0 +1,16 @@ +public class Ch2 { + public static void main(String[] args) { + System.out.println(string_score("hello")); + System.out.println(string_score("perl")); + System.out.println(string_score("raku")); + } + + private static int string_score(String str) { + int sum = 0; + for (int i = 0; i < str.length() - 1; ++i) { + sum += Math.abs(str.charAt(i + 1) - str.charAt(i)); + } + return sum; + } +} + diff --git a/challenge-272/deadmarshal/lua/ch-1.lua b/challenge-272/deadmarshal/lua/ch-1.lua new file mode 100644 index 0000000000..0269798b42 --- /dev/null +++ b/challenge-272/deadmarshal/lua/ch-1.lua @@ -0,0 +1,10 @@ +#!/usr/bin/env lua + +local function defrag_ip_address(str) + assert(type(str) == 'string','str must be a string!') + return (str:gsub("%.","[.]")) +end + +print(defrag_ip_address('1.1.1.1')) +print(defrag_ip_address('255.101.1.0')) + diff --git a/challenge-272/deadmarshal/lua/ch-2.lua b/challenge-272/deadmarshal/lua/ch-2.lua new file mode 100644 index 0000000000..059197dbfd --- /dev/null +++ b/challenge-272/deadmarshal/lua/ch-2.lua @@ -0,0 +1,16 @@ +#!/usr/bin/env lua + +local function string_score(str) + assert(type(str) == 'string','str must be a string!') + local sum = 0 + for i=1,#str-1 do + sum = sum + math.abs(string.byte(str:sub(i+1,i+1)) + - string.byte(str:sub(i,i))) + end + return sum +end + +print(string_score('hello')) +print(string_score('perl')) +print(string_score('raku')) + diff --git a/challenge-272/deadmarshal/modula-3/ch1/src/Ch1.m3 b/challenge-272/deadmarshal/modula-3/ch1/src/Ch1.m3 new file mode 100644 index 0000000000..57909c2830 --- /dev/null +++ b/challenge-272/deadmarshal/modula-3/ch1/src/Ch1.m3 @@ -0,0 +1,30 @@ +MODULE Ch1 EXPORTS Main; + +IMPORT SIO,Text,CharSeq; + +PROCEDURE DefragIpAddress(READONLY t:TEXT):TEXT = + VAR + Seq:CharSeq.T := NEW(CharSeq.T).init(Text.Length(t)); + A:REF ARRAY OF CHAR; + C:CHAR; + BEGIN + FOR I := 0 TO Text.Length(t)-1 DO + C := Text.GetChar(t,I); + IF C = '.' THEN + Seq.addhi('['); + Seq.addhi(C); + Seq.addhi(']') + ELSE + Seq.addhi(C) + END; + END; + A := NEW(REF ARRAY OF CHAR,Seq.size()); + FOR I := 0 TO Seq.size()-1 DO A[I] := Seq.get(I) END; + RETURN Text.FromChars(A^) + END DefragIpAddress; + +BEGIN + SIO.PutText(DefragIpAddress("1.1.1.1") & "\n"); + SIO.PutText(DefragIpAddress("255.101.1.0") & "\n"); +END Ch1. + diff --git a/challenge-272/deadmarshal/modula-3/ch1/src/m3makefile b/challenge-272/deadmarshal/modula-3/ch1/src/m3makefile new file mode 100644 index 0000000000..9f66e4a51f --- /dev/null +++ b/challenge-272/deadmarshal/modula-3/ch1/src/m3makefile @@ -0,0 +1,5 @@ +import("libm3") +import("libsio") +implementation("Ch1") +program("ch1") + diff --git a/challenge-272/deadmarshal/modula-3/ch2/src/Ch2.m3 b/challenge-272/deadmarshal/modula-3/ch2/src/Ch2.m3 new file mode 100644 index 0000000000..d59307e562 --- /dev/null +++ b/challenge-272/deadmarshal/modula-3/ch2/src/Ch2.m3 @@ -0,0 +1,19 @@ +MODULE Ch2 EXPORTS Main; + +IMPORT SIO,Text; + +PROCEDURE StringScore(READONLY t:TEXT):INTEGER = + VAR Sum:INTEGER := 0; + BEGIN + FOR I := 0 TO Text.Length(t)-2 DO + INC(Sum,ABS(ORD(Text.GetChar(t,I+1)) - ORD(Text.GetChar(t,I)))) + END; + RETURN Sum + END StringScore; + +BEGIN + SIO.PutInt(StringScore("hello")); SIO.Nl(); + SIO.PutInt(StringScore("perl")); SIO.Nl(); + SIO.PutInt(StringScore("raku")); SIO.Nl() +END Ch2. + diff --git a/challenge-272/deadmarshal/modula-3/ch2/src/m3makefile b/challenge-272/deadmarshal/modula-3/ch2/src/m3makefile new file mode 100644 index 0000000000..798c627ef3 --- /dev/null +++ b/challenge-272/deadmarshal/modula-3/ch2/src/m3makefile @@ -0,0 +1,5 @@ +import("libm3") +import("libsio") +implementation("Ch2") +program("ch2") + diff --git a/challenge-272/deadmarshal/perl/ch-1.pl b/challenge-272/deadmarshal/perl/ch-1.pl new file mode 100644 index 0000000000..cd1f537594 --- /dev/null +++ b/challenge-272/deadmarshal/perl/ch-1.pl @@ -0,0 +1,11 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +sub defrag_ip_address{ + $_[0] =~ s/\./\[\.\]/gr +} + +printf "%s\n",defrag_ip_address('1.1.1.1'); +printf "%s\n",defrag_ip_address('255.101.1.0'); + diff --git a/challenge-272/deadmarshal/perl/ch-2.pl b/challenge-272/deadmarshal/perl/ch-2.pl new file mode 100644 index 0000000000..bc0e36b06c --- /dev/null +++ b/challenge-272/deadmarshal/perl/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util qw(sum0); +use List::MoreUtils qw(slide); + +sub string_score{ + sum0 slide {abs(ord($b) - ord($a))} split '',$_[0] +} + +printf "%d\n",string_score('hello'); +printf "%d\n",string_score('perl'); +printf "%d\n",string_score('raku'); + diff --git a/challenge-272/deadmarshal/raku/ch-1.raku b/challenge-272/deadmarshal/raku/ch-1.raku new file mode 100644 index 0000000000..1017df67ae --- /dev/null +++ b/challenge-272/deadmarshal/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku + +sub defrag-ip-address($str) +{ + $str.subst('.','[.]',:g) +} + +say defrag-ip-address('1.1.1.1'); +say defrag-ip-address('255.101.1.0'); + diff --git a/challenge-272/deadmarshal/raku/ch-2.raku b/challenge-272/deadmarshal/raku/ch-2.raku new file mode 100644 index 0000000000..1760ab24a7 --- /dev/null +++ b/challenge-272/deadmarshal/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +sub string-score($str) +{ + my @arr = $str.ords; + my $sum = 0; + for 0..^@arr.end -> $i { + $sum += abs(@arr[$i+1] - @arr[$i]) + } + $sum +} + +say string-score('hello'); +say string-score('perl'); +say string-score('raku'); + |
