aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-195/sgreen/README.md4
-rw-r--r--challenge-195/sgreen/perl/ch-1.pl29
-rw-r--r--challenge-195/sgreen/perl/ch-2.pl31
-rwxr-xr-xchallenge-195/sgreen/python/ch-1.py31
-rwxr-xr-xchallenge-195/sgreen/python/ch-2.py29
-rw-r--r--challenge-196/sgreen/README.md4
-rw-r--r--challenge-196/sgreen/blog.txt1
-rwxr-xr-xchallenge-196/sgreen/perl/ch-1.pl25
-rwxr-xr-xchallenge-196/sgreen/perl/ch-2.pl35
-rwxr-xr-xchallenge-196/sgreen/python/ch-1.py20
-rwxr-xr-xchallenge-196/sgreen/python/ch-2.py31
11 files changed, 236 insertions, 4 deletions
diff --git a/challenge-195/sgreen/README.md b/challenge-195/sgreen/README.md
index f3687cb8b9..a12c4d2028 100644
--- a/challenge-195/sgreen/README.md
+++ b/challenge-195/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 194
+# The Weekly Challenge 195
-Blog [Digital frequency](https://dev.to/simongreennet/digital-frequency-l56)
+Sorry, no blog this week.
diff --git a/challenge-195/sgreen/perl/ch-1.pl b/challenge-195/sgreen/perl/ch-1.pl
new file mode 100644
index 0000000000..8cc80c83e5
--- /dev/null
+++ b/challenge-195/sgreen/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub is_simple_number ($n) {
+ # Determine if the number is simple
+ my %seen = ();
+ foreach my $i ( split //, $n ) {
+ return if $seen{$i}++;
+ }
+ # It is simple
+ return 1;
+}
+
+sub main ($n) {
+ # Iterate through the list counting the number of simple numbers
+ my $simple_count = 0;
+ foreach my $i ( 1 .. $n ) {
+ $simple_count++ if is_simple_number($i);
+ }
+
+ # Print the result
+ say $simple_count;
+}
+
+main( $ARGV[0] ); \ No newline at end of file
diff --git a/challenge-195/sgreen/perl/ch-2.pl b/challenge-195/sgreen/perl/ch-2.pl
new file mode 100644
index 0000000000..d830d8bc24
--- /dev/null
+++ b/challenge-195/sgreen/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+use List::Util qw(max min);
+
+sub main (@list) {
+ # Count the frequency of even numbers
+ my %evens = ();
+ foreach my $i (@list) {
+ $evens{$i}++ if $i % 2 == 0;
+ }
+
+ if ( scalar keys(%evens) == 0 ) {
+ # If no evens, return -1
+ say -1;
+ }
+ else {
+ # Find the evens that occur most often
+ my $m = max( values(%evens) );
+ my @max_evens = grep { $evens{$_} == $m } keys(%evens);
+
+ # The the minimum even that occurs most often
+ my $min_max_evens = min(@max_evens);
+ say $min_max_evens;
+ }
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-195/sgreen/python/ch-1.py b/challenge-195/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..4b3831a16c
--- /dev/null
+++ b/challenge-195/sgreen/python/ch-1.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import sys
+
+
+def is_simple_number(n):
+ # Determine if the number is simple
+ seen = {}
+ for i in str(n):
+ if i in seen:
+ # We've seen the digit before. It's not simple
+ return False
+ seen[i] = 1
+
+ # It is simple
+ return True
+
+
+def main(n):
+ # Iterate through the list counting the number of simple numbers
+ simple_count = 0
+ for i in range(1, n+1):
+ if is_simple_number(i):
+ simple_count += 1
+
+ # Print the result
+ print(simple_count)
+
+
+if __name__ == '__main__':
+ main(int(sys.argv[1]))
diff --git a/challenge-195/sgreen/python/ch-2.py b/challenge-195/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..0ba621b63f
--- /dev/null
+++ b/challenge-195/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(array):
+ # Count the frequency of even numbers
+ evens = {}
+ for i in array:
+ if i % 2 == 0:
+ evens[i] = evens.get(i, 0) + 1
+
+ if not evens:
+ # If no evens, return -1
+ print(-1)
+ else:
+ # Find the evens that occur most often
+ m = max(evens.values())
+ max_evens = [i for i, v in evens.items() if v == m]
+
+ # The the minimum even that occurs most often
+ min_max_evens = min(max_evens)
+ print(min_max_evens)
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-196/sgreen/README.md b/challenge-196/sgreen/README.md
index f3687cb8b9..e446a70844 100644
--- a/challenge-196/sgreen/README.md
+++ b/challenge-196/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 194
+# The Weekly Challenge 196
-Blog [Digital frequency](https://dev.to/simongreennet/digital-frequency-l56)
+Blog [Weekly Challenge 196](https://dev.to/simongreennet/weekly-challenge-196-41j1)
diff --git a/challenge-196/sgreen/blog.txt b/challenge-196/sgreen/blog.txt
new file mode 100644
index 0000000000..8058983946
--- /dev/null
+++ b/challenge-196/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-196-41j1 \ No newline at end of file
diff --git a/challenge-196/sgreen/perl/ch-1.pl b/challenge-196/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..d79ed9232b
--- /dev/null
+++ b/challenge-196/sgreen/perl/ch-1.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use Algorithm::Combinatorics 'combinations';
+
+sub main (@n) {
+ # Work through all combinations of positions
+ my $iter = combinations( [ 0 .. $#n ], 3 );
+ while ( my $x = $iter->next ) {
+ my ( $i, $j, $k ) = sort { $a <=> $b } @$x;
+ if ( $n[$i] < $n[$k] < $n[$j] ) {
+ say "($n[$i], $n[$j], $n[$k])";
+ return;
+ }
+ }
+
+ # No solution is found
+ say '()';
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-196/sgreen/perl/ch-2.pl b/challenge-196/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..1df0c4fc49
--- /dev/null
+++ b/challenge-196/sgreen/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub main (@n) {
+ my @solutions = ();
+
+ # Go through the list until it is exhausted
+ while ( scalar(@n) ) {
+ my $start = my $end = shift @n;
+
+ # See if the next number is one more than the last value
+ while ( scalar(@n) > 0 and $n[0] == $end + 1 ) {
+ $end = shift @n;
+ }
+
+ # We have found a range
+ if ( $start != $end ) {
+ push @solutions, "[$start,$end]";
+ }
+ }
+
+ # Print solution
+ if (@solutions) {
+ say join ', ', @solutions;
+ }
+ else {
+ say 'No solutions found!';
+ }
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-196/sgreen/python/ch-1.py b/challenge-196/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..57b37a70da
--- /dev/null
+++ b/challenge-196/sgreen/python/ch-1.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+
+from itertools import combinations
+import sys
+
+def main(n):
+ # Work through all combinations of positions
+ for x in combinations(range(len(n)), 3):
+ i, j, k = sorted(x)
+ if n[i] < n[k] < n[j]:
+ print(f'({n[i]}, {n[j]}, {n[k]})')
+ return
+
+ # No solution is found
+ print('()')
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-196/sgreen/python/ch-2.py b/challenge-196/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..ce0f95cd62
--- /dev/null
+++ b/challenge-196/sgreen/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ solutions = []
+
+ # Go through the list until it is exhausted
+ while len(n):
+ start = end = n.pop(0)
+
+ # See if the next number is one more than the last value
+ while len(n) > 0 and n[0] == end+1:
+ end = n.pop(0)
+
+ # We have found a range
+ if start != end:
+ solutions.append(f'[{start},{end}]')
+
+ # Print solution
+ if solutions:
+ print(*solutions, sep=', ')
+ else:
+ print('No solutions found!')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)