aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-07-16 16:28:20 +0100
committerGitHub <noreply@github.com>2023-07-16 16:28:20 +0100
commit50cd03bb47d86b2f79d0bb3f0b1214a6349a473a (patch)
tree8592987ed7a513c14963754bd12bcad31c214644
parentdf91349f6fc8018e2f46973fb71deff830d82f05 (diff)
parentf57b4dfe8b950281eda332fabb344b0d42571344 (diff)
downloadperlweeklychallenge-club-50cd03bb47d86b2f79d0bb3f0b1214a6349a473a.tar.gz
perlweeklychallenge-club-50cd03bb47d86b2f79d0bb3f0b1214a6349a473a.tar.bz2
perlweeklychallenge-club-50cd03bb47d86b2f79d0bb3f0b1214a6349a473a.zip
Merge pull request #8385 from simongreen-net/master
Simon's solution to challenge 225
-rw-r--r--challenge-224/sgreen/README.md3
-rw-r--r--challenge-225/sgreen/README.md4
-rw-r--r--challenge-225/sgreen/blog.txt1
-rwxr-xr-xchallenge-225/sgreen/perl/ch-1.pl18
-rwxr-xr-xchallenge-225/sgreen/perl/ch-2.pl21
-rwxr-xr-xchallenge-225/sgreen/python/ch-1.py15
-rwxr-xr-xchallenge-225/sgreen/python/ch-2.py20
7 files changed, 77 insertions, 5 deletions
diff --git a/challenge-224/sgreen/README.md b/challenge-224/sgreen/README.md
deleted file mode 100644
index 1878b0ae58..0000000000
--- a/challenge-224/sgreen/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# The Weekly Challenge 223
-
-Blog: [Counting the coins](https://dev.to/simongreennet/counting-the-coins-3i2f)
diff --git a/challenge-225/sgreen/README.md b/challenge-225/sgreen/README.md
index 1878b0ae58..650646237c 100644
--- a/challenge-225/sgreen/README.md
+++ b/challenge-225/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 223
+# The Weekly Challenge 225
-Blog: [Counting the coins](https://dev.to/simongreennet/counting-the-coins-3i2f)
+Blog: [Weekly Challenge 225](https://dev.to/simongreennet/weekly-challenge-225-2785)
diff --git a/challenge-225/sgreen/blog.txt b/challenge-225/sgreen/blog.txt
new file mode 100644
index 0000000000..33cd79f97d
--- /dev/null
+++ b/challenge-225/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-225-2785 \ No newline at end of file
diff --git a/challenge-225/sgreen/perl/ch-1.pl b/challenge-225/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..eda95b2fcc
--- /dev/null
+++ b/challenge-225/sgreen/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'max';
+
+sub main (@sentences) {
+ # Count the number of spaces + 1
+ my @words = map { tr/ / / + 1 } @sentences;
+
+ # Display the maximum number of words
+ say max(@words);
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-225/sgreen/perl/ch-2.pl b/challenge-225/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..3c2b479dee
--- /dev/null
+++ b/challenge-225/sgreen/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'sum';
+
+sub main (@n) {
+ # Calculate left and right lists
+ my $l = scalar(@n);
+ my @left = ( 0, map { sum( @n[ 0 .. $_ ] ) } ( 0 .. $l - 2 ) );
+ my @right = ( map( { sum( @n[ $_ .. $l - 1 ] ) } ( 1 .. $l - 1 ) ), 0 );
+
+ # Calculate the absolute difference between the list
+ my @solution = map { abs( $left[$_] - $right[$_] ) } ( 0 .. $#n );
+ say join ', ', @solution;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-225/sgreen/python/ch-1.py b/challenge-225/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..0f7f0502ce
--- /dev/null
+++ b/challenge-225/sgreen/python/ch-1.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(sentences):
+ # Count the number of spaces + 1
+ words = [x.count(' ')+1 for x in sentences]
+
+ # Display the maximum number of words
+ print(max(words))
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/challenge-225/sgreen/python/ch-2.py b/challenge-225/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..aee529c28b
--- /dev/null
+++ b/challenge-225/sgreen/python/ch-2.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Calculate left and right lists
+ l = len(n)
+ left = [sum(n[0:i]) for i in range(l)]
+ right = [sum(n[i+1:l]) for i in range(l)]
+
+ # Calculate the absolute difference between the list
+ solution = [abs(left[i] - right[i]) for i in range(l)]
+ print(*solution, sep=', ')
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)