diff options
| author | Lakpa Tashi Bhutia <lakpatashi@users.noreply.github.com> | 2023-11-25 21:02:55 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-25 21:02:55 +0530 |
| commit | 6db863c3ee8cb8a3315eeae5fde99af83385aefc (patch) | |
| tree | 761f0c9b8aef13375cca819d8deed4a70fff8c7e /challenge-243/sgreen | |
| parent | 9c96baeeda85997b321a4d4fbebd5fd51bffb729 (diff) | |
| parent | 9a1dd9390973363a40ccda4a6d03f9f61a0ae386 (diff) | |
| download | perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.tar.gz perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.tar.bz2 perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-243/sgreen')
| -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) |
