wlmb · @wlmb
62 followers · 649 posts · Server mstdn.social

@PerlWChallenge 234 Task 2: Unequal Triplets

```
perl -MAlgorithm::Combinatorics=combinations -MList::Util=sum0,product -E '
++$c{$_} for @ARGV; @n=keys %c; say "@ARGV -> ", @n<3?0:sum0 map {product @c{@$_}} combinations(\@n,3);
' 4 7 1 10 7 4 1 1
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
62 followers · 649 posts · Server mstdn.social

@PerlWChallenge 234 Task 1: Common Characters

```
perl -MList::Util=min -E 'for(@ARGV){my %l; $l{$_}++ for split ""; push @c, \%l;}
say "@ARGV -> ", join " ", map {$l=$_; ($l) x min map {$c[$_]{$l}} 0..@c-1} keys %{$c[0]}
' bella label roller
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
62 followers · 649 posts · Server mstdn.social

@PerlWChallenge 234 Common Characters and Unequal Triplets wlmb.github.io/2023/09/11/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
62 followers · 643 posts · Server mstdn.social

@PerlWChallenge 233 Task 2: Frequency Sort

```
perl -E '
$c{$_}++ for @ARGV; say "@ARGV -> ", join " ", sort {$c{$a} <=> $c{$b} || $b <=> $a} @ARGV;
' 1 1 2 2 2 3
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
62 followers · 642 posts · Server mstdn.social

@PerlWChallenge 233 Task 1: Similar Words

```
perl -MList::Util=uniq,sum0 -E '
$k{join "", sort {$a cmp $b} uniq split "", lc($_)}++ for (@ARGV);
say "@ARGV -> ", sum0 map {$k{$_}*($k{$_}-1)/2} grep {$k{$_}>1} keys %k;
' aba aabb abcd bac aabc
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
62 followers · 642 posts · Server mstdn.social

@PerlWChallenge 231 Task 1: Min Max

```
perl -MList::Util=min,max -E '
@x=@ARGV; ($l,$h)=(min(@x), max(@x)); @Y=grep {$_!=$l && $_!=$h} @x; say "@x -> ", join " ", @Y?@Y:-1
' 3 2 1 4
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 630 posts · Server mstdn.social

@PerlWChallenge 229 Lexicographic Order and Two out of Three wlmb.github.io/2023/08/06/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 629 posts · Server mstdn.social

@PerlWChallenge 229 Task 2: Two out of Three

```
perl -MList::Util=uniq -E '
for(@ARGV){$c{$_}++ for uniq split " ";}@O=grep {$c{$_}>=2} keys %c;say map({"[$_]"} @ARGV), "->[@O]"
' "1 1 2 4" "2 4" "4"
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 628 posts · Server mstdn.social

@PerlWChallenge 229 Task 1: Lexicographic Order

perl -MPDL -MPDL::NiceSlice -E 'for(@ARGV){$z=($y=($x=pdl([map {ord} split "", lc]))->(-1:0))->qsort;
++$c if ($x!=$z)->any&&($y!=$z)->any} say "@ARGV->", $c||0;
' abc bce cae

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 628 posts · Server mstdn.social

@PerlWChallenge 228 Task 2: Empty Array

```
perl -MPDL -E '
$x=pdl(@ARGV); $c=0; while($x->nelem>1){$m=$x->min; $r=which($x==$m)->at(0);
$c+=$r+1; $x=$x->rotate(-$r)->slice([1,-1,1]);} say "@ARGV -> ", $c+1;
' 3 4 2
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 628 posts · Server mstdn.social

@PerlWChallenge 228 Task 1: Unique Sum

```
perl -MList::Util=sum0 -E '++$s{$_} for @ARGV; say "@ARGV -> ", sum0 grep {$s{$_}==1} @ARGV' 2 1 3 2
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
59 followers · 628 posts · Server mstdn.social

@PerlWChallenge 228 Unique Sum and Empty Array wlmb.github.io/2023/07/31/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 613 posts · Server mstdn.social

@Perl @PerlWChallenge 227 Friday 13th and Roman Maths
wlmb.github.io/2023/07/24/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 612 posts · Server mstdn.social

@Perl @PerlWChallenge 227 Task 2: Roman Maths

```
perl -MPOSIX=floor -MText::Roman=:all -E '
%o=map{$_=>eval "sub(\$x,\$y){\$x$_\$y}"} qw(+ - * / ** %); say "$_ ->", r($_) for(@ARGV);
sub r($e){($x,$o,$y)=split " ", $e; $r=$o{$o}->(map {roman2int($_)}($x,$y));
return $r==0?"nulla":($r>3999||$r<0||$r!=floor $r)?"non potest":int2roman($r)}
' "IV + V" "M - I" "X / II" "XI * VI" "VII ** III" "V - V" "V / II" "MMM + M" "V - X" "XXV % IV"
```
wlmb.github.io/2023/07/24/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 611 posts · Server mstdn.social

@Perl @PerlWChallenge 227 Task 1: Friday 13th

```
perl -MPDL -E '
$d=pdl[[0,3,3,6,1,4,6,2,5,0,3,5],[0,3,4,0,2,5,0,3,6,1,4,6]];
for(@ARGV){$y=$_%400; $l=(floor(($y+3)/4)-floor(($y+3)/100));
$s=($y+$l)%7; $t=(!$y||($y%100 &&!!($y%4)))?1:0; $b=($d->slice("",[$t,0,0])+$s)%7;
say "$_->", ($b==1)->sumover}
' 2023 2000 1999
```
wlmb.github.io/2023/07/24/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 607 posts · Server mstdn.social

@PerlWChallenge 226 Shuffle String and Zero Array wlmb.github.io/2023/07/16/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 606 posts · Server mstdn.social

@PerlWChallenge 226 Task 2: Zero Array

```
perl -MPDL -E '
$c=0; print $x=pdl(@ARGV); ++$c, $x=$x->where($x>0), $x-=$x->min while $x->sumover>0; say " -> $c";
' 1 5 0 3 5
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
55 followers · 605 posts · Server mstdn.social

@PerlWChallenge 226 Task 1: Shuffle String

```
perl -E '
print "@ARGV -> "; @L=split "", shift; $o[$_]=shift @L for @ARGV; say join "", @O
' lacelengh 3 2 0 5 4 8 6 7 1
```

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
56 followers · 601 posts · Server mstdn.social

@PerlWChallenge 225 Max Words and Left Right Sum Diff wlmb.github.io/2023/07/09/PWC2

#noxp #perl

Last updated 1 year ago

wlmb · @wlmb
56 followers · 600 posts · Server mstdn.social

@PerlWChallenge 225 Task 2: Left Right Sum Diff

```
perl -MList::Util=reductions -E '
@x=(0, @ARGV, 0); $n=@x-3; ($l,$r)=map {[reductions {$a+$b} @$_]} [@x[0..$n]],
[((reverse @x)[0..$n])]; @O=map {abs($l->[$_]-$r->[-$_-1])} 0..$n; say "@ARGV -> @O";
' 1 2 3 4 5
```

#noxp #perl

Last updated 1 year ago