diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-07 14:11:44 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-07 14:11:44 +0000 |
| commit | a6368e3cd07bf057fda6f0d2ccfefcd4e32f8dcf (patch) | |
| tree | adf4b0d46e36320eb441d089ef9bcee7d3509961 | |
| parent | ddc19ed5a251eb1b6123591a8594b4779eff7d38 (diff) | |
| parent | 7b07d041a8c01b78ca1d311502b5e93b5d0a5153 (diff) | |
| download | perlweeklychallenge-club-a6368e3cd07bf057fda6f0d2ccfefcd4e32f8dcf.tar.gz perlweeklychallenge-club-a6368e3cd07bf057fda6f0d2ccfefcd4e32f8dcf.tar.bz2 perlweeklychallenge-club-a6368e3cd07bf057fda6f0d2ccfefcd4e32f8dcf.zip | |
Merge pull request #9355 from simongreen-net/master
Simon's solution to challenge 250
| -rw-r--r-- | challenge-250/sgreen/README.md | 4 | ||||
| -rw-r--r-- | challenge-250/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-250/sgreen/perl/ch-1.pl | 24 | ||||
| -rwxr-xr-x | challenge-250/sgreen/perl/ch-2.pl | 19 | ||||
| -rwxr-xr-x | challenge-250/sgreen/python/ch-1.py | 23 | ||||
| -rwxr-xr-x | challenge-250/sgreen/python/ch-2.py | 17 |
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:]) |
