diff options
| author | Simon Green <mail@simon.green> | 2023-11-19 17:50:52 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2023-11-19 17:50:52 +1100 |
| commit | 8f247dd9b414bfd6f286667e91d13aee8b9575a0 (patch) | |
| tree | c0f70ec061e540d829abeb53f168bde4cc415960 /challenge-243 | |
| parent | dc0651a859d9824512ffbd2c84aba36b7392e84f (diff) | |
| download | perlweeklychallenge-club-8f247dd9b414bfd6f286667e91d13aee8b9575a0.tar.gz perlweeklychallenge-club-8f247dd9b414bfd6f286667e91d13aee8b9575a0.tar.bz2 perlweeklychallenge-club-8f247dd9b414bfd6f286667e91d13aee8b9575a0.zip | |
Simon's solution to challenge 243
Diffstat (limited to 'challenge-243')
| -rw-r--r-- | challenge-243/sgreen/README.md | 4 | ||||
| -rw-r--r-- | challenge-243/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-243/sgreen/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-243/sgreen/perl/ch-2.pl | 20 | ||||
| -rwxr-xr-x | challenge-243/sgreen/python/ch-1.py | 18 | ||||
| -rwxr-xr-x | challenge-243/sgreen/python/ch-2.py | 15 |
6 files changed, 76 insertions, 2 deletions
diff --git a/challenge-243/sgreen/README.md b/challenge-243/sgreen/README.md index fbeb2f577f..e2f63d2857 100644 --- a/challenge-243/sgreen/README.md +++ b/challenge-243/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 241 +# The Weekly Challenge 243 -Blog: [Triplets and Sorting](https://dev.to/simongreennet/similar-frequency-3i6b) +Blog: [Weekly Challenge 243](https://dev.to/simongreennet/weekly-challenge-243-3ld) diff --git a/challenge-243/sgreen/blog.txt b/challenge-243/sgreen/blog.txt new file mode 100644 index 0000000000..3c217e63fe --- /dev/null +++ b/challenge-243/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-243-3ld
\ No newline at end of file diff --git a/challenge-243/sgreen/perl/ch-1.pl b/challenge-243/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..d40db432ac --- /dev/null +++ b/challenge-243/sgreen/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +sub main (@ints) { + my $solutions = 0; + + while ( my ( $i, $value ) = each @ints ) { + # Find future values that are less than half the current value + $solutions += + scalar( grep { $value > $_ * 2 } @ints[ $i + 1 .. $#ints ] ); + } + + say $solutions; +} + +main(@ARGV);
\ No newline at end of file diff --git a/challenge-243/sgreen/perl/ch-2.pl b/challenge-243/sgreen/perl/ch-2.pl new file mode 100755 index 0000000000..778a423841 --- /dev/null +++ b/challenge-243/sgreen/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +use List::Util 'sum'; +use POSIX 'floor'; + +sub main (@ints) { + my $solution = 0; + foreach my $i (@ints) { + $solution += sum( map { floor( $i / $_ ) } @ints ); + } + + say $solution; +} + +main(@ARGV);
\ No newline at end of file diff --git a/challenge-243/sgreen/python/ch-1.py b/challenge-243/sgreen/python/ch-1.py new file mode 100755 index 0000000000..56d72aa4f6 --- /dev/null +++ b/challenge-243/sgreen/python/ch-1.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + solutions = 0 + for i, value in enumerate(ints): + # Find future values that are less than half the current value + solutions += sum(1 for j in ints[i+1:] if value > 2 * j) + + print(solutions) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) diff --git a/challenge-243/sgreen/python/ch-2.py b/challenge-243/sgreen/python/ch-2.py new file mode 100755 index 0000000000..5a3f723c7c --- /dev/null +++ b/challenge-243/sgreen/python/ch-2.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 + +import math +import sys + + +def main(ints): + solution = sum(math.floor(i / j) for i in ints for j in ints) + print(solution) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) |
