aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-02-22 23:41:04 +0000
committerGitHub <noreply@github.com>2023-02-22 23:41:04 +0000
commit78c8cf00255f1c5516b332950be2ea2e97f47ec5 (patch)
tree7d59d847b1e9dd3457ef68c482c6fc3a2c1c93c5
parent6ef0f1642c43ed1f2644789a98c854cfe218257f (diff)
parent1dd34f4c99747713393ea1b20afec29a9955be49 (diff)
downloadperlweeklychallenge-club-78c8cf00255f1c5516b332950be2ea2e97f47ec5.tar.gz
perlweeklychallenge-club-78c8cf00255f1c5516b332950be2ea2e97f47ec5.tar.bz2
perlweeklychallenge-club-78c8cf00255f1c5516b332950be2ea2e97f47ec5.zip
Merge pull request #7603 from simongreen-net/master
Simon's solution to challenge 205
-rw-r--r--challenge-205/sgreen/README.md4
-rw-r--r--challenge-205/sgreen/blog.txt1
-rwxr-xr-xchallenge-205/sgreen/perl/ch-1.pl24
-rwxr-xr-xchallenge-205/sgreen/perl/ch-2.pl30
-rwxr-xr-xchallenge-205/sgreen/python/ch-1.py21
-rwxr-xr-xchallenge-205/sgreen/python/ch-2.py27
6 files changed, 105 insertions, 2 deletions
diff --git a/challenge-205/sgreen/README.md b/challenge-205/sgreen/README.md
index ec08b855cc..b2c76ea65b 100644
--- a/challenge-205/sgreen/README.md
+++ b/challenge-205/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 204
+# The Weekly Challenge 205
-Blog: [Weekly Challenge 204](https://dev.to/simongreennet/weekly-challenge-204-256e)
+Blog: [Weekly Challenge 205](https://dev.to/simongreennet/weekly-challenge-205-3f3)
diff --git a/challenge-205/sgreen/blog.txt b/challenge-205/sgreen/blog.txt
new file mode 100644
index 0000000000..d7e139fcdf
--- /dev/null
+++ b/challenge-205/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/weekly-challenge-205-3f3 \ No newline at end of file
diff --git a/challenge-205/sgreen/perl/ch-1.pl b/challenge-205/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..14acfcee75
--- /dev/null
+++ b/challenge-205/sgreen/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'uniq';
+
+sub main (@n) {
+ # Sort the list numerical, removing duplicates
+ @n = sort {$a <=> $b} ( uniq(@n) );
+
+ if ( $#n >= 2 ) {
+ # There are three or more integers, print the third largest
+ say $n[-3];
+ }
+ else {
+ # There are less than three integers, print the largest
+ say $n[-1];
+ }
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-205/sgreen/perl/ch-2.pl b/challenge-205/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..6ff8d04452
--- /dev/null
+++ b/challenge-205/sgreen/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util 'uniq';
+
+sub main (@n) {
+ # Remove non-unique values
+ @n = map { int($_) } uniq @n;
+ my $max = $n[0] ^ $n[1];
+
+ # Work through each combination of two numbers
+ foreach my $first ( 0 .. $#n - 1 ) {
+ foreach my $second ( $first + 1 .. $#n ) {
+ my $xor_value = $n[$first] ^ $n[$second];
+ if ( $max < $xor_value ) {
+ # We have a new maximum value
+ $max = $xor_value;
+ }
+ }
+ }
+
+ # Print the maximum value found
+ say $max;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-205/sgreen/python/ch-1.py b/challenge-205/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..e9d98479cd
--- /dev/null
+++ b/challenge-205/sgreen/python/ch-1.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Sort the list numerical, removing duplicates
+ n = sorted(set(n))
+
+ if len(n) >= 3:
+ # There are three or more integers, print the third largest
+ print(n[-3])
+ else:
+ # There are less than three integers, print the largest
+ print(n[-1])
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-205/sgreen/python/ch-2.py b/challenge-205/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..d578909fa5
--- /dev/null
+++ b/challenge-205/sgreen/python/ch-2.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Remove non-unique values
+ n = list(set(n))
+ items = len(n)
+ max = n[0] ^ n[1]
+
+ # Work through each combination of two numbers
+ for first in range(items-1):
+ for second in range(first+1, items):
+ xor_value = n[first] ^ n[second]
+ if max < xor_value:
+ # We have a new maximum value
+ max = xor_value
+
+ # Print the maximum value found
+ print(max)
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)