aboutsummaryrefslogtreecommitdiff
path: root/challenge-250
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-250')
-rw-r--r--challenge-250/sgreen/README.md4
-rw-r--r--challenge-250/sgreen/blog.txt1
-rwxr-xr-xchallenge-250/sgreen/perl/ch-1.pl24
-rwxr-xr-xchallenge-250/sgreen/perl/ch-2.pl19
-rwxr-xr-xchallenge-250/sgreen/python/ch-1.py23
-rwxr-xr-xchallenge-250/sgreen/python/ch-2.py17
6 files changed, 87 insertions, 1 deletions
diff --git a/challenge-250/sgreen/README.md b/challenge-250/sgreen/README.md
index d2fd2ac699..98fb8281b8 100644
--- a/challenge-250/sgreen/README.md
+++ b/challenge-250/sgreen/README.md
@@ -1 +1,3 @@
-# The Weekly Challenge 249
+# The Weekly Challenge 250
+
+Blog: [Small and large](https://dev.to/simongreennet/small-and-large-2ap)
diff --git a/challenge-250/sgreen/blog.txt b/challenge-250/sgreen/blog.txt
new file mode 100644
index 0000000000..1ad1762407
--- /dev/null
+++ b/challenge-250/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/small-and-large-2ap \ No newline at end of file
diff --git a/challenge-250/sgreen/perl/ch-1.pl b/challenge-250/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..79872fc28e
--- /dev/null
+++ b/challenge-250/sgreen/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub main (@ints) {
+ my $solution = -1;
+
+ # Loop through each position
+ foreach my $idx ( 0 .. $#ints ) {
+ # The index mod 10 is the value at this position
+ if ( $idx % 10 == $ints[$idx] ) {
+ # We have the best solution, so no need to continue looping
+ $solution = $idx;
+ last;
+ }
+ }
+
+ say $solution;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-250/sgreen/perl/ch-2.pl b/challenge-250/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..61746c4d46
--- /dev/null
+++ b/challenge-250/sgreen/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'max';
+
+sub calculate_value ($s) {
+ #Return the number if it looks like an integer else the length of string
+ return $s =~ /^[0-9]+$/ ? int($s) : length($s);
+}
+
+sub main (@values) {
+ say max( map { calculate_value($_) } @values );
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-250/sgreen/python/ch-1.py b/challenge-250/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..d907d03257
--- /dev/null
+++ b/challenge-250/sgreen/python/ch-1.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ solution = -1
+
+ # Loop through each position
+ for idx in range(len(ints)):
+ # The index mod 10 is the value at this position
+ if idx % 10 == ints[idx]:
+ # We have the best solution, so no need to continue looping
+ solution = idx
+ break
+
+ print(solution)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)
diff --git a/challenge-250/sgreen/python/ch-2.py b/challenge-250/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..9ee64eea3f
--- /dev/null
+++ b/challenge-250/sgreen/python/ch-2.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def calculate_value(s):
+ '''Return the number if it looks like an integer else the length of string'''
+ return int(s) if re.search(r'^\d+$', s) else len(s)
+
+
+def main(values):
+ print(max(map(calculate_value, values)))
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])