aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-244/sgreen/README.md4
-rw-r--r--challenge-244/sgreen/blog.txt1
-rwxr-xr-xchallenge-244/sgreen/perl/ch-1.pl18
-rwxr-xr-xchallenge-244/sgreen/perl/ch-2.pl30
-rwxr-xr-xchallenge-244/sgreen/python/ch-1.py14
-rwxr-xr-xchallenge-244/sgreen/python/ch-2.py25
6 files changed, 90 insertions, 2 deletions
diff --git a/challenge-244/sgreen/README.md b/challenge-244/sgreen/README.md
index e2f63d2857..fb592c5c30 100644
--- a/challenge-244/sgreen/README.md
+++ b/challenge-244/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 243
+# The Weekly Challenge 244
-Blog: [Weekly Challenge 243](https://dev.to/simongreennet/weekly-challenge-243-3ld)
+Blog: [Weekly Challenge 244](https://dev.to/simongreennet/weekly-challenge-244-jim)
diff --git a/challenge-244/sgreen/blog.txt b/challenge-244/sgreen/blog.txt
new file mode 100644
index 0000000000..ca15406cb6
--- /dev/null
+++ b/challenge-244/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-244-jim \ No newline at end of file
diff --git a/challenge-244/sgreen/perl/ch-1.pl b/challenge-244/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..6698cd7195
--- /dev/null
+++ b/challenge-244/sgreen/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub less_than ( $i, $ints ) {
+ # Return the number of items in the array less than $i
+ return scalar( grep { $_ < $i } @$ints );
+}
+
+sub main (@ints) {
+ my @solution = map { less_than( $_, \@ints ) } @ints;
+ say join ', ', @solution;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-244/sgreen/perl/ch-2.pl b/challenge-244/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..af44e12ba5
--- /dev/null
+++ b/challenge-244/sgreen/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use Algorithm::Combinatorics 'combinations';
+use List::Util qw(min max);
+
+sub calculate_power($numbers) {
+ # Return the square of the maximum number multiplied by the smallest one
+ my $min_int = min(@$numbers);
+ my $max_int = max(@$numbers);
+ return $max_int ** 2 * $min_int;
+}
+
+sub main (@ints) {
+ my $power = 0;
+ foreach my $len ( 1 .. $#ints + 1 ) {
+ my $iter = combinations( \@ints, $len );
+ while ( my $c = $iter->next ) {
+ $power += calculate_power($c);
+ }
+ }
+
+ say $power;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-244/sgreen/python/ch-1.py b/challenge-244/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..230798c214
--- /dev/null
+++ b/challenge-244/sgreen/python/ch-1.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ solution = [sum(1 for j in ints if j < i) for i in ints]
+ print(*solution, sep=', ')
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)
diff --git a/challenge-244/sgreen/python/ch-2.py b/challenge-244/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..64f54aff7a
--- /dev/null
+++ b/challenge-244/sgreen/python/ch-2.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+import sys
+from itertools import combinations
+
+
+def calculate_power(numbers):
+ '''Return the square of the maximum number multiplied by the smallest one'''
+ min_int = min(numbers)
+ max_int = max(numbers)
+ return max_int ** 2 * min_int
+
+
+def main(ints):
+ power = 0
+ for length in range(1, len(ints)+1):
+ power += sum(calculate_power(c) for c in combinations(ints, length))
+
+ print(power)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)