aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli <adeadmarshal@gmail.com>2025-06-24 16:21:08 +0330
committerAli <adeadmarshal@gmail.com>2025-06-24 16:21:08 +0330
commitb7fdac1ef6cbe21c23c0dac58f9cceaa7ed0189e (patch)
tree5e127aa0311d3590f8ccc9c028ff1792228b19bf
parent99d8fa43930abb471fac2b94b68c0785619b37fc (diff)
downloadperlweeklychallenge-club-b7fdac1ef6cbe21c23c0dac58f9cceaa7ed0189e.tar.gz
perlweeklychallenge-club-b7fdac1ef6cbe21c23c0dac58f9cceaa7ed0189e.tar.bz2
perlweeklychallenge-club-b7fdac1ef6cbe21c23c0dac58f9cceaa7ed0189e.zip
TWC327
-rw-r--r--challenge-327/deadmarshal/blog.txt1
-rw-r--r--challenge-327/deadmarshal/erlang/ch1.erl12
-rw-r--r--challenge-327/deadmarshal/erlang/ch2.erl33
-rw-r--r--challenge-327/deadmarshal/perl/ch-1.pl14
-rw-r--r--challenge-327/deadmarshal/perl/ch-2.pl20
5 files changed, 80 insertions, 0 deletions
diff --git a/challenge-327/deadmarshal/blog.txt b/challenge-327/deadmarshal/blog.txt
new file mode 100644
index 0000000000..8fc7ae9917
--- /dev/null
+++ b/challenge-327/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2025/06/twc327.html
diff --git a/challenge-327/deadmarshal/erlang/ch1.erl b/challenge-327/deadmarshal/erlang/ch1.erl
new file mode 100644
index 0000000000..9329e5cec9
--- /dev/null
+++ b/challenge-327/deadmarshal/erlang/ch1.erl
@@ -0,0 +1,12 @@
+-module(ch1).
+-export([missing_integers/1]).
+
+-spec missing_integers(L) -> R when
+ L :: [T],
+ R :: sofs:external_set(),
+ T :: term().
+missing_integers(L) ->
+ S1 = sofs:set(L),
+ S2 = sofs:set(lists:seq(1,length(L))),
+ sofs:to_external(sofs:symdiff(S1,S2)).
+
diff --git a/challenge-327/deadmarshal/erlang/ch2.erl b/challenge-327/deadmarshal/erlang/ch2.erl
new file mode 100644
index 0000000000..4b8c78f64c
--- /dev/null
+++ b/challenge-327/deadmarshal/erlang/ch2.erl
@@ -0,0 +1,33 @@
+-module(ch2).
+-export([mad/1]).
+
+-spec zip(L1,L2) -> R when
+ L1 :: [T],
+ L2 :: [T],
+ R :: [{T,T}],
+ T :: integer().
+zip(L1, L2) -> lists:reverse(zip(L1, L2, [])).
+
+-spec zip(L1,L2,R) -> R when
+ L1 :: [T],
+ L2 :: [T],
+ R :: [{T,T}],
+ T :: integer().
+zip([], _, Acc) -> Acc;
+zip(_, [], Acc) -> Acc;
+zip([X | Xs], [Y | Ys], Acc) ->
+ zip(Xs, Ys, [{X, Y} | Acc]).
+
+-spec mad(L) -> R when
+ L :: [T],
+ R :: [{T,T}],
+ T :: integer().
+mad([]) -> [];
+mad([_]) -> [];
+mad(L) ->
+ Sorted = lists:sort(L),
+ Pairs = zip(Sorted,tl(Sorted)),
+ Diffs = lists:map(fun({A,B}) -> abs(A - B) end,Pairs),
+ Min = lists:min(Diffs),
+ [{A,B} || {A,B} <- Pairs, abs(A - B) =:= Min].
+
diff --git a/challenge-327/deadmarshal/perl/ch-1.pl b/challenge-327/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..569eca5d21
--- /dev/null
+++ b/challenge-327/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Set::Scalar;
+use feature qw(say);
+
+sub missing_integers{
+ Set::Scalar->new(@{$_[0]}) / Set::Scalar->new(1..@{$_[0]})
+}
+
+say missing_integers([1,2,1,3,2,5]);
+say missing_integers([1,1,1]);
+say missing_integers([2,2,1]);
+
diff --git a/challenge-327/deadmarshal/perl/ch-2.pl b/challenge-327/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..dc6aff2a2f
--- /dev/null
+++ b/challenge-327/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Data::Show;
+
+sub mad{
+ my @s = sort{$a <=> $b} @{$_[0]};
+ my @mad = $s[1] - $s[0];
+ foreach my $i(1..$#s){
+ my $diff = abs $s[$i] - $s[$i-1];
+ $mad[0] = $diff if $diff < $mad[0];
+ push @mad,[@s[$i-1,$i]] if $diff == $mad[0]
+ }
+ @mad[1..$#mad]
+}
+
+print show mad([4,1,2,3]);
+print show mad([1,3,7,11,15]);
+print show mad([1,5,3,8]);
+