aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyoungjin JEON <jeongoon@gmail.com>2020-10-20 23:24:11 +1100
committerMyoungjin JEON <jeongoon@gmail.com>2020-10-20 23:24:11 +1100
commit3739e2e9688cd223dae50692e46254adc19de9a0 (patch)
treef05040214a822431131c6a2a6f5ab3271cda8cbf
parentf243dd3d3349bfdc6292faca8b2e08899552c6b1 (diff)
parentd244e1d3a5e39ce0fad850b17c0b406ff462ebc1 (diff)
downloadperlweeklychallenge-club-3739e2e9688cd223dae50692e46254adc19de9a0.tar.gz
perlweeklychallenge-club-3739e2e9688cd223dae50692e46254adc19de9a0.tar.bz2
perlweeklychallenge-club-3739e2e9688cd223dae50692e46254adc19de9a0.zip
Merge remote-tracking branch 'upstream/master'
-rwxr-xr-xchallenge-081/alexander-karelas/perl/ch-1.pl21
-rwxr-xr-xchallenge-081/alexander-karelas/perl/ch-2.pl25
-rw-r--r--challenge-081/alexander-karelas/perl/input (renamed from challenge-083/simon-proctor/raku/input)2
-rw-r--r--challenge-083/ash/raku/ch-1.raku13
-rw-r--r--challenge-083/ash/raku/ch-2.raku34
-rw-r--r--challenge-083/dave-cross/perl/ch-1.pl17
-rw-r--r--challenge-083/dave-cross/perl/ch-2.pl37
-rw-r--r--challenge-083/frankivo/WordsLength.scala20
-rwxr-xr-xchallenge-083/james-smith/perl/ch-1.pl26
-rwxr-xr-xchallenge-083/james-smith/perl/ch-2.pl39
-rw-r--r--challenge-083/mark-anderson/raku/ch-1.p615
-rw-r--r--challenge-083/mark-anderson/raku/ch-2.p615
-rw-r--r--challenge-083/markus-holzer/raku/ch-1.raku2
-rw-r--r--challenge-083/markus-holzer/raku/ch-2.raku12
-rwxr-xr-xchallenge-083/roger-bell-west/perl/ch-1.pl16
-rwxr-xr-xchallenge-083/roger-bell-west/perl/ch-2.pl38
-rwxr-xr-xchallenge-083/roger-bell-west/python/ch-1.py17
-rwxr-xr-xchallenge-083/roger-bell-west/python/ch-2.py30
-rwxr-xr-xchallenge-083/roger-bell-west/raku/ch-1.p615
-rwxr-xr-xchallenge-083/roger-bell-west/raku/ch-2.p624
-rwxr-xr-xchallenge-083/roger-bell-west/ruby/ch-1.rb20
-rwxr-xr-xchallenge-083/roger-bell-west/ruby/ch-2.rb37
-rw-r--r--challenge-083/sgreen/README.md4
-rw-r--r--challenge-083/sgreen/blog.txt1
-rwxr-xr-xchallenge-083/sgreen/perl/ch-1.pl19
-rwxr-xr-xchallenge-083/sgreen/perl/ch-2.pl51
-rw-r--r--challenge-083/simon-proctor/raku/ch-1.raku13
-rw-r--r--challenge-083/simon-proctor/raku/ch-2.raku30
-rw-r--r--stats/pwc-challenge-081.json315
-rw-r--r--stats/pwc-challenge-082.json766
-rw-r--r--stats/pwc-current.json686
-rw-r--r--stats/pwc-language-breakdown-summary.json58
-rw-r--r--stats/pwc-language-breakdown.json565
-rw-r--r--stats/pwc-leaders.json464
-rw-r--r--stats/pwc-summary-1-30.json42
-rw-r--r--stats/pwc-summary-121-150.json46
-rw-r--r--stats/pwc-summary-151-180.json114
-rw-r--r--stats/pwc-summary-181-210.json42
-rw-r--r--stats/pwc-summary-31-60.json102
-rw-r--r--stats/pwc-summary-61-90.json118
-rw-r--r--stats/pwc-summary-91-120.json32
-rw-r--r--stats/pwc-summary.json66
42 files changed, 2405 insertions, 1604 deletions
diff --git a/challenge-081/alexander-karelas/perl/ch-1.pl b/challenge-081/alexander-karelas/perl/ch-1.pl
new file mode 100755
index 0000000000..f484f0ae77
--- /dev/null
+++ b/challenge-081/alexander-karelas/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use v5.30;
+use warnings;
+
+my ($A, $B) = @ARGV[0, 1];
+
+my $shorter = length $A;
+$shorter = length $B if length $B < length $A;
+
+my @solutions;
+
+for (my $len = 1; $len <= $shorter; $len++) {
+ next if length($A) % $len != 0 or length($B) % $len != 0;
+ my $candidate = substr $A, 0, $len;
+ if ($A eq $candidate x (length($A) / $len) and $B eq $candidate x (length($B) / $len)) {
+ push @solutions, $candidate;
+ }
+}
+
+print "(", join(", ", map qq{"$_"}, @solutions), ")\n";
diff --git a/challenge-081/alexander-karelas/perl/ch-2.pl b/challenge-081/alexander-karelas/perl/ch-2.pl
new file mode 100755
index 0000000000..d7ba46423d
--- /dev/null
+++ b/challenge-081/alexander-karelas/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use v5.30;
+use warnings;
+
+# read file into string var
+open my $fh, "input";
+my $text = do {local $/; <$fh>};
+close $fh;
+
+# get frequency of each word
+my %frequencies;
+my @words = split /(?:[\.\"\(\)\,]|\'s|\-\-|\s)+/, $text;
+$frequencies{$_}++ foreach @words;
+
+# generate %reverse_frequencies, a map from frequencies to words
+my %reverse_frequencies;
+while (my ($word, $freq) = each %frequencies) {
+ push @{ $reverse_frequencies{$freq} }, $word;
+}
+
+# display sorted
+foreach my $freq (sort {$a <=> $b} keys %reverse_frequencies) {
+ print $freq, (map " $_", sort @{ $reverse_frequencies{$freq} }), "\n\n";
+}
diff --git a/challenge-083/simon-proctor/raku/input b/challenge-081/alexander-karelas/perl/input
index 37001629ad..d2bb45d308 100644
--- a/challenge-083/simon-proctor/raku/input
+++ b/challenge-081/alexander-karelas/perl/input
@@ -1,3 +1,3 @@
West Side Story
-The award-winning adaptation of the classic romantic tragedy "Romeo and Juliet". The feuding families become two warring New York City gangs, the white Jets led by Riff and the Latino Sharks, led by Bernardo. Their hatred escalates to a point where neither can coexist with any form of understanding. But when Riff's best friend (and former Jet) Tony and Bernardo's younger sister Maria meet at a dance, no one can do anything to stop their love. Maria and Tony begin meeting in secret, planning to run away. Then the Sharks and Jets plan a rumble under the highway--whoever wins gains control of the streets. Maria sends Tony to stop it, hoping it can end the violence. It goes terribly wrong, and before the lovers know what's happened, tragedy strikes and doesn't stop until the climactic and heartbreaking ending.
+The award-winning adaptation of the classic romantic tragedy "Romeo and Juliet". The feuding families become two warring New York City gangs, the white Jets led by Riff and the Latino Sharks, led by Bernardo. Their hatred escalates to a point where neither can coexist with any form of understanding. But when Riff's best friend (and former Jet) Tony and Bernardo's younger sister Maria meet at a dance, no one can do anything to stop their love. Maria and Tony begin meeting in secret, planning to run away. Then the Sharks and Jets plan a rumble under the highway--whoever wins gains control of the streets. Maria sends Tony to stop it, hoping it can end the violence. It goes terribly wrong, and before the lovers know what's happened, tragedy strikes and doesn't stop until the climactic and heartbreaking ending. \ No newline at end of file
diff --git a/challenge-083/ash/raku/ch-1.raku b/challenge-083/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..46ec086f54
--- /dev/null
+++ b/challenge-083/ash/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+#
+# Task 1 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-083/
+
+# Output:
+# $ raku ch-1.raku
+# 23
+
+my $s = 'The purpose of our lives is to be happy';
+# my $s = 'The Weekly Challenge';
+
+$s.words[1 .. *-2]>>.chars.sum.say;
diff --git a/challenge-083/ash/raku/ch-2.raku b/challenge-083/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..0b38dd9979
--- /dev/null
+++ b/challenge-083/ash/raku/ch-2.raku
@@ -0,0 +1,34 @@
+#!/usr/bin/env raku
+#
+# Task 2 from
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-083/
+
+my @a = 12, 2, 100;
+# Number of sign flips: 2; min sum: 86
+
+# my @a = 12, 2, 10;
+# Number of sign flips: 1; min sum: 0
+
+# my @a = 3, 10, 8;
+# Number of sign flips: 1; min sum: 1
+
+my $min_sum = Inf;
+my $min_flips = Inf;
+my $min_comb = '';
+
+my $fmt = '%0' ~ @a.elems ~ 'b';
+
+for ^ 2**@a -> $n {
+ my @bits = $n.fmt($fmt).comb;
+
+ my $sum = [+] @bits>>.subst(0, -1) Z* @a;
+ next if $sum < 0;
+
+ if $sum < $min_sum {
+ $min_sum = $sum;
+ my $flips = @bits.grep(0).elems;
+ $min_flips = $flips if $flips < $min_flips;
+ }
+}
+
+say "Number of sign flips: $min_flips; min sum: $min_sum";
diff --git a/challenge-083/dave-cross/perl/ch-1.pl b/challenge-083/dave-cross/perl/ch-1.pl
new file mode 100644
index 0000000000..70cc450472
--- /dev/null
+++ b/challenge-083/dave-cross/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+$_ = join ' ', @ARGV;
+
+unless (defined and /\S+\s+\S+\s+\S+/) {
+ die "Your string must include three words\n";
+}
+
+s/^\s*\S+\s+//;
+s/\s+\S+\s*$//;
+s/\s+//g;
+
+say length;
diff --git a/challenge-083/dave-cross/perl/ch-2.pl b/challenge-083/dave-cross/perl/ch-2.pl
new file mode 100644
index 0000000000..e5b0f15ad4
--- /dev/null
+++ b/challenge-083/dave-cross/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+
+use List::Util qw[sum];
+
+my @ints = grep { !/\D/ and $_ } @ARGV;
+
+die "Please give me some positive integers\n" unless @ints;
+
+my $options = 2 ** @ints - 1;
+
+my $lowest_sum = sum @ints;
+my $fewest_flips = @ints;
+my $number_of_flags = @ints;
+
+for (0 .. $options) {
+ my $binary = sprintf "%0${number_of_flags}b", $_;
+ my @flags = split //, $binary;
+ my $number_of_on_flags = grep { $_ } @flags;
+
+ my $total = sum map {
+ $flags[$_] ? -$ints[$_] : $ints[$_];
+ } 0 .. $#flags;
+
+ next if $total < 0;
+
+ if ($total < $lowest_sum or
+ $total == $lowest_sum and $number_of_on_flags < $fewest_flips) {
+ $lowest_sum = $total;
+ $fewest_flips = $number_of_on_flags;
+ }
+}
+
+say $fewest_flips;
diff --git a/challenge-083/frankivo/WordsLength.scala b/challenge-083/frankivo/WordsLength.scala
new file mode 100644
index 0000000000..4888ca1439
--- /dev/null
+++ b/challenge-083/frankivo/WordsLength.scala
@@ -0,0 +1,20 @@
+object WordsLength {
+ val examples: Seq[String] = Seq(
+ "The Weekly Challenge",
+ "The purpose of our lives is to be happy"
+ )
+
+ def main(args: Array[String]): Unit = {
+ examples
+ .map(e => (e, count(e)))
+ .foreach(println)
+ }
+
+ def count(line: String) : Int = {
+ line.split(" ")
+ .drop(1)
+ .dropRight(1)
+ .mkString
+ .length
+ }
+} \ No newline at end of file
diff --git a/challenge-083/james-smith/perl/ch-1.pl b/challenge-083/james-smith/perl/ch-1.pl
new file mode 100755
index 0000000000..dce37e780d
--- /dev/null
+++ b/challenge-083/james-smith/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+is( other_chars( 'The Weekly Challenge' ), 6 );
+is( other_chars( 'The purpose of our lives is to be happy' ), 23 );
+is( other_chars( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas fringilla tincidunt velit, euismod vulputate arcu tristique a. Cras malesuada bibendum erat, sed ullamcorper diam egestas at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus venenatis dolor dolor, quis dictum mauris mattis finibus. Praesent feugiat neque vulputate erat consequat, quis dignissim risus vestibulum. Phasellus feugiat tellus vestibulum tellus eleifend sodales. Aenean non feugiat mauris. Praesent eu nisl a nunc rhoncus pharetra id non mi. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Duis tincidunt scelerisque erat, sagittis sagittis quam laoreet non. Cras convallis lacinia nisl, eget vehicula ante consequat eu. Etiam justo tellus, scelerisque vel consectetur id, feugiat sed tellus.
+
+Cras et turpis augue. Nulla nec dolor odio. Fusce placerat nisi sit amet magna accumsan, sit amet facilisis turpis tincidunt. Integer velit erat, suscipit eu pretium nec, pretium eget tellus. Aliquam eleifend laoreet velit id feugiat. Donec sit amet ultrices turpis, nec mollis ante. Praesent et odio eu ligula luctus aliquam. Donec semper ligula sit amet ante auctor, non consequat est vulputate. Sed gravida, ipsum in condimentum maximus, sapien eros lacinia dolor, quis molestie neque magna nec dolor. Aliquam diam magna, euismod vitae justo in, sagittis mollis ipsum. Suspendisse a erat turpis. Vestibulum blandit orci ut imperdiet egestas.
+
+Quisque lacinia euismod orci, ac vulputate dui pellentesque et. Suspendisse vitae diam odio. Curabitur lacinia pellentesque mi non ultricies. Nulla suscipit vitae ipsum nec hendrerit. Cras in commodo lorem, sit amet iaculis tellus. Integer maximus tellus varius, facilisis orci placerat, volutpat est. Donec non neque sodales, ullamcorper massa at, feugiat massa. Cras interdum est ac porta malesuada. Nunc sed mi ante. Nulla vitae pellentesque erat.
+
+Nulla vitae leo accumsan, tincidunt ex nec, malesuada mi. Praesent sed finibus dui. Suspendisse aliquam mauris sed consectetur interdum. Proin bibendum tellus orci, a interdum ligula tincidunt rhoncus. Pellentesque lorem neque, venenatis et aliquet vel, lacinia et libero. Suspendisse nec urna ut dolor volutpat aliquet. Aenean faucibus porttitor risus vel ultricies.
+
+Aliquam id blandit nulla. Phasellus pharetra diam sed malesuada congue. Ut sit amet congue eros. Suspendisse potenti. Sed aliquet erat massa, non tincidunt ligula mollis et. Sed ac elementum libero, id viverra justo. Nullam non ante posuere ligula porta congue sollicitudin a nisi. Donec fringilla nibh a bibendum ullamcorper. Sed sed bibendum diam. Vestibulum nec urna sem. Donec enim quam, viverra sit amet porttitor ac, tempus sed diam. Vivamus lacinia leo sit amet aliquet porttitor. Donec accumsan consequat scelerisque. Integer ultrices mi ut pretium interdum' ), 2508 );
+
+done_testing;
+
+sub other_chars {
+ my @A = split m{\s+}, shift; ## split into words...
+ pop @A; ## remove first
+ shift @A; ## and last
+ return length join q(), @A; ## compute length of words - simpler to join...
+}
diff --git a/challenge-083/james-smith/perl/ch-2.pl b/challenge-083/james-smith/perl/ch-2.pl
new file mode 100755
index 0000000000..2018366e3b
--- /dev/null
+++ b/challenge-083/james-smith/perl/ch-2.pl
@@ -0,0 +1,39 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+is( flip_array( 3,10,8 ), 1 );
+is( flip_array( 12, 2, 10 ), 1 );
+is( flip_array( 1..20 ), 6 );
+
+done_testing;
+
+## Let's avoid recursion as this is inefficient...
+## We will try and do this with a minimum of variables
+## We effectively do binary increment on the elements of the array
+## Flipping from +ve -> -ve is like flipping from 0 -> 1
+## So if we flip from -ve -> +ve we need to flip the next bit or number
+
+sub flip_array {
+ my @array = @_;
+ my $sum = 0;
+ $sum+=$_ foreach @array; ## Initial "unflipped" sum...
+ my( $flipped, $smallest, $best, $na ) = ( 0, $sum, 0, scalar @array ); ## Initialise counts/running sums...
+
+ while(1) {
+ ($best,$smallest)=($flipped,$sum) if $sum>=0 && $sum < $smallest || $sum == $smallest && $flipped < $best;
+ foreach(0..$na) {
+ return $best if $_ == $na; ## Now reached the end as we have flipped the last element back...
+ $sum += 2*($array[$_]=-$array[$_]); ## Flip bit and update sum...
+ if( $array[$_]> 0 ) { ## We carry over to the next bit (if the element has been flipped back)
+ $flipped --;
+ } else { ## No need to carry so finish loop...
+ $flipped ++;
+ last;
+ }
+ }
+ }
+}
diff --git a/challenge-083/mark-anderson/raku/ch-1.p6 b/challenge-083/mark-anderson/raku/ch-1.p6
new file mode 100644
index 0000000000..c001e08bc8
--- /dev/null
+++ b/challenge-083/mark-anderson/raku/ch-1.p6
@@ -0,0 +1,15 @@
+use Test;
+
+plan 2;
+
+my $S = "The Weekly Challenge";
+
+ok words-length($S) == 6, "$S = 6";
+
+$S = "The purpose of our lives is to be happy";
+
+ok words-length($S) == 23, "$S = 23";
+
+sub words-length($S) {
+ $S.words[1..*-2].join.chars;
+}
diff --git a/challenge-083/mark-anderson/raku/ch-2.p6 b/challenge-083/mark-anderson/raku/ch-2.p6
new file mode 100644
index 0000000000..73732ade9d
--- /dev/null
+++ b/challenge-083/mark-anderson/raku/ch-2.p6
@@ -0,0 +1,15 @@
+unit sub MAIN(*@A where (.elems > 1 and .all ~~ UInt and .all > 0));
+
+my $A = gather {
+ for @A.keys.combinations.skip -> @C {
+ my @N = @A;
+ @N[@C].map(* *= -1);
+ take [@N.sum, @C.elems, @N] if @N.sum >= 0;
+ }
+}
+
+my ($Sum, $A2) = (min classify { .[0] }, $A).kv;
+my ($Flips, $A3) = (min classify { .[1] }, |$A2).kv;
+
+say "Sum = $Sum\nFlips = $Flips\n";
+say .[2].fmt("(%d)", " + ") for |$A3;
diff --git a/challenge-083/markus-holzer/raku/ch-1.raku b/challenge-083/markus-holzer/raku/ch-1.raku
new file mode 100644
index 0000000000..6785656edb
--- /dev/null
+++ b/challenge-083/markus-holzer/raku/ch-1.raku
@@ -0,0 +1,2 @@
+unit sub MAIN( Str $S );
+$S.words[ 1 .. *-2 ].join.chars.say \ No newline at end of file
diff --git a/challenge-083/markus-holzer/raku/ch-2.raku b/challenge-083/markus-holzer/raku/ch-2.raku
new file mode 100644
index 0000000000..9bc6e3ee33
--- /dev/null
+++ b/challenge-083/markus-holzer/raku/ch-2.raku
@@ -0,0 +1,12 @@
+unit sub MAIN( *@A );
+
+my &neg = *.grep: * < 0;
+
+say + neg # find and count all negative numbers of
+ ( [X] map { +$_, -$_ }, @A ) # all possible candidates
+ .classify( *.sum ) # grouped by sum
+ .grep( *.key > -1 ) # filtered where sum is positive
+ .sort( *.key ) # sorted by sum
+ .head.value # closest to zero
+ .min( &neg ) # the one with the least flips
+
diff --git a/challenge-083/roger-bell-west/perl/ch-1.pl b/challenge-083/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..5f6d34ec61
--- /dev/null
+++ b/challenge-083/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+is (wl('The Weekly Challenge'),6,'example 1');
+is (wl('The purpose of our lives is to be happy'),23,'example 2');
+
+sub wl {
+ my $s=shift;
+ $s =~ s/^\S+\s+(.*?)\s+\S+$/$1/;
+ $s =~ s/\s+//g;
+ return length($s);
+}
diff --git a/challenge-083/roger-bell-west/perl/ch-2.pl b/challenge-083/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..1ef34b5478
--- /dev/null
+++ b/challenge-083/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use integer;
+
+use List::Util qw(sum);
+
+use Test::More tests => 3;
+
+is (fa(3,10,8),1,'example 1');
+is (fa(12,2,10),1,'example 2');
+is (fa(2,2,10),2,'example 3');
+
+sub fa {
+ my @a=@_;
+ my $n = (1 << scalar @a);
+ my $ss=sum(@a);
+ my $ls;
+ my $li;
+ foreach my $mask (1..$n-1) {
+ my $s=$ss;
+ my $m=1;
+ my $inv=0;
+ foreach my $i (0..$#a) {
+ if ($m & $mask) {
+ $inv++;
+ $s -= 2*$a[$i];
+ }
+ $m <<= 1;
+ }
+ if ($s>=0 && (!defined $ls || $s < $ls || ($ls == $s && $inv < $li))) {
+ $ls=$s;
+ $li=$inv;
+ }
+ }
+ return $li;
+}
diff --git a/challenge-083/roger-bell-west/python/ch-1.py b/challenge-083/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..05553d994f
--- /dev/null
+++ b/challenge-083/roger-bell-west/python/ch-1.py
@@ -0,0 +1,17 @@
+#! /usr/bin/python3
+
+import unittest
+
+def wl(s):
+ a=s.split()
+ return len(''.join(a[1:len(a)-1]))
+
+class TestWl(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(wl('The Weekly Challenge'),6,'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(wl('The purpose of our lives is to be happy'),23,'example 2')
+
+unittest.main()
diff --git a/challenge-083/roger-bell-west/python/ch-2.py b/challenge-083/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..c518da107a
--- /dev/null
+++ b/challenge-083/roger-bell-west/python/ch-2.py
@@ -0,0 +1,30 @@
+#! /usr/bin/python3
+
+from itertools import combinations
+import unittest
+
+def fa(*a):
+ ss=sum(a)
+ ls=ss
+ li=0
+ for inv in range(1,len(a)):
+ for l in combinations(a,inv):
+ s=ss-2*sum(l)
+ if (s >= 0):
+ if (ls == ss or s < ls or (s == ls and inv < li)):
+ ls=s
+ li=inv
+ return li
+
+class TestFa(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(fa(3,10,8),1,'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(fa(12,2,10),1,'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(fa(2,2,10),2,'example 3')
+
+unittest.main()
diff --git a/challenge-083/roger-bell-west/raku/ch-1.p6 b/challenge-083/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..02f8f79c7a
--- /dev/null
+++ b/challenge-083/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,15 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 2;
+
+is(wl('The Weekly Challenge'),6,'example 1');
+is(wl('The purpose of our lives is to be happy'),23,'example 2');
+
+sub wl($so) {
+ my $s=$so;
+ $s ~~ s/^\S+\s+(.*?)\s+\S+$/$0/;
+ $s ~~ s:g/\s+//;
+ return $s.chars;
+}
diff --git a/challenge-083/roger-bell-west/raku/ch-2.p6 b/challenge-083/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..37e6b3432c
--- /dev/null
+++ b/challenge-083/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,24 @@
+#! /usr/bin/perl6
+
+use Test;
+plan 3;
+
+is(fa(3,10,8),1,'example 1');
+is(fa(12,2,10),1,'example 2');
+is(fa(2,2,10),2,'example 3');
+
+sub fa(**@a) {
+ my $ss=sum(@a);
+ my $ls;
+ my $li;
+ for @a.combinations(1..@a.elems) -> $l {
+ my $s=$ss-2*sum($l);
+ if ($s >= 0) {
+ if ((!defined $ls) || $s < $ls || ($ls == $s && $l.elems < $li)) {
+ $ls=$s;
+ $li=$l.elems;
+ }
+ }
+ }
+ return $li;
+}
diff --git a/challenge-083/roger-bell-west/ruby/ch-1.rb b/challenge-083/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..51dc6d4500
--- /dev/null
+++ b/challenge-083/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,20 @@
+#! /usr/bin/ruby
+
+def wl(s)
+ a=s.split(' ')
+ return a[1...-1].join('').length
+end
+
+require 'test/unit'
+
+class TestWl < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(6,wl('The Weekly Challenge'))
+ end
+
+ def test_ex2
+ assert_equal(23,wl('The purpose of our lives is to be happy'))
+ end
+
+end
diff --git a/challenge-083/roger-bell-west/ruby/ch-2.rb b/challenge-083/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..dd26fc9944
--- /dev/null
+++ b/challenge-083/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/ruby
+
+def fa(*a)
+ ss=a.sum
+ ls=ss
+ li=0
+ 1.upto(a.length) do |inv|
+ a.combination(inv) do |l|
+ s=ss-2*l.sum
+ if s >= 0
+ if (ls == ss or s < ls or (s == ls and inv < li))
+ ls=s
+ li=inv
+ end
+ end
+ end
+ end
+ return li
+end
+
+require 'test/unit'
+
+class TestFa < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(1,fa(3,10,8))
+ end
+
+ def test_ex2
+ assert_equal(1,fa(12,2,10))
+ end
+
+ def test_ex3
+ assert_equal(2,fa(2,2,10))
+ end
+
+end
diff --git a/challenge-083/sgreen/README.md b/challenge-083/sgreen/README.md
index 669247f1fc..4337d62b73 100644
--- a/challenge-083/sgreen/README.md
+++ b/challenge-083/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 082
+# The Weekly Challenge 083
-Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-082-3a9d)
+Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-083-4ga6)
diff --git a/challenge-083/sgreen/blog.txt b/challenge-083/sgreen/blog.txt
new file mode 100644
index 0000000000..337dd4ea24
--- /dev/null
+++ b/challenge-083/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-083-4ga6
diff --git a/challenge-083/sgreen/perl/ch-1.pl b/challenge-083/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..11b736a9a5
--- /dev/null
+++ b/challenge-083/sgreen/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+sub main {
+ my $string = shift;
+
+ my ($middle_words) = ( $string =~ /^\s*\S+?\s+(.*)\s+\S+\s*$/ );
+ die "You must enter a string with at least three words\n"
+ unless $middle_words;
+
+ # Remove ant whitespace
+ $middle_words =~ s/\s//g;
+ say length $middle_words;
+}
+
+main(@ARGV);
diff --git a/challenge-083/sgreen/perl/ch-2.pl b/challenge-083/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..e2454ff9c1
--- /dev/null
+++ b/challenge-083/sgreen/perl/ch-2.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+use List::Util qw(sum uniq);
+
+sub main {
+ my @numbers = @_;
+ my $items = scalar(@numbers);
+
+ # Sanity check
+ die "You must specify at least one value" unless scalar(@numbers);
+ foreach my $n (@numbers) {
+ die "The value '$n' is not a positive number\n"
+ unless $n =~ /^[1-9][0-9]*$/;
+ }
+
+ # Set up some variables. We start with the minimum sum being one
+ # more than the sum of the numbers.
+ my $minimum_sum = sum(@numbers) + 1;
+ my $minimum_flips = 0;
+ my @results = ();