From 82bb0ee8a7a5211443dda553bcbd7afff6794a14 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 24 Oct 2022 23:14:22 -0500 Subject: Solve PWC 188 --- challenge-188/wlmb/blog.txt | 1 + challenge-188/wlmb/perl/ch-1.pl | 21 +++++++++++++++++++++ challenge-188/wlmb/perl/ch-2.pl | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 challenge-188/wlmb/blog.txt create mode 100755 challenge-188/wlmb/perl/ch-1.pl create mode 100755 challenge-188/wlmb/perl/ch-2.pl diff --git a/challenge-188/wlmb/blog.txt b/challenge-188/wlmb/blog.txt new file mode 100644 index 0000000000..9458cb0342 --- /dev/null +++ b/challenge-188/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io//2022/10/25/PWC188.org diff --git a/challenge-188/wlmb/perl/ch-1.pl b/challenge-188/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..469f5b67b1 --- /dev/null +++ b/challenge-188/wlmb/perl/ch-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +# Perl weekly challenge 188 +# Task 1: Divisible Pairs +# +# See https://wlmb.github.io/2022/10/25/PWC188/#task-1-divisible-pairs +use v5.36; +use Algorithm::Combinatorics qw(combinations); +die <=3; +Usage: $0 D N1 N2 [N3...]\nto count distinct ordered pairs of integers Ni +that add to a multiple of D +EOF +my $divisor=shift; +my @list=sort @ARGV; +my $iter=combinations(\@list, 2); +my $count=0; +while(my $z=$iter->next){ + my ($x, $y)=@$z; + ++$count if ($x+$y)%$divisor==0; +} +say "The number of pairs from the list ", + join(", ", @ARGV), " divisible by $divisor is $count"; diff --git a/challenge-188/wlmb/perl/ch-2.pl b/challenge-188/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..eb4d38e452 --- /dev/null +++ b/challenge-188/wlmb/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# Perl weekly challenge 188 +# Task 2: Total Zero +# +# See https://wlmb.github.io/2022/10/25/PWC188/#task-2-total-zero +use v5.36; +use POSIX qw(floor); +die <0 and $y>0 and $x==floor $x and $y==floor $y; +use integer; +while($y>0){ + my ($d, $r)=($x/$y, $x%$y); + $counter += $d; + ++$actual; + ($x, $y)=($y, $r); +} +say "The number of operations required to bring $x0 $y0 to zero is $counter (divisions: $actual)"; -- cgit From 50b08241503a29dfc16335429344cce741bd6642 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Tue, 25 Oct 2022 07:35:25 -0500 Subject: Fix message --- challenge-188/wlmb/perl/ch-1.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-188/wlmb/perl/ch-1.pl b/challenge-188/wlmb/perl/ch-1.pl index 469f5b67b1..2ec087eec5 100755 --- a/challenge-188/wlmb/perl/ch-1.pl +++ b/challenge-188/wlmb/perl/ch-1.pl @@ -18,4 +18,4 @@ while(my $z=$iter->next){ ++$count if ($x+$y)%$divisor==0; } say "The number of pairs from the list ", - join(", ", @ARGV), " divisible by $divisor is $count"; + join(", ", @ARGV), " with sum divisible by $divisor is $count"; -- cgit