diff options
| -rw-r--r-- | challenge-228/sgreen/README.md | 4 | ||||
| -rw-r--r-- | challenge-228/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-228/sgreen/perl/ch-1.pl | 22 | ||||
| -rwxr-xr-x | challenge-228/sgreen/perl/ch-2.pl | 34 | ||||
| -rwxr-xr-x | challenge-228/sgreen/python/ch-1.py | 20 | ||||
| -rwxr-xr-x | challenge-228/sgreen/python/ch-2.py | 29 |
6 files changed, 108 insertions, 2 deletions
diff --git a/challenge-228/sgreen/README.md b/challenge-228/sgreen/README.md index f9524c44af..97f37e7c0a 100644 --- a/challenge-228/sgreen/README.md +++ b/challenge-228/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 227 +# The Weekly Challenge 228 -Blog: [Weekly Challenge 227](https://dev.to/simongreennet/weekly-challenge-227-3loi) +Blog: [Weekly Challenge 228](https://dev.to/simongreennet/weekly-challenge-228-1j9) diff --git a/challenge-228/sgreen/blog.txt b/challenge-228/sgreen/blog.txt new file mode 100644 index 0000000000..ca1ae2e25f --- /dev/null +++ b/challenge-228/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-228-1j9
\ No newline at end of file diff --git a/challenge-228/sgreen/perl/ch-1.pl b/challenge-228/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..39041a47e0 --- /dev/null +++ b/challenge-228/sgreen/perl/ch-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +use List::Util 'sum0'; + +sub main (@ints) { + # Get the frequency of all numbers + my %freq = (); + foreach my $i (@ints) { + ++$freq{$i}; + } + + # Get the sum of all unique values + my $solution = sum0( grep { $freq{$_} == 1 } keys %freq ); + say $solution; +} + +main(@ARGV);
\ No newline at end of file diff --git a/challenge-228/sgreen/perl/ch-2.pl b/challenge-228/sgreen/perl/ch-2.pl new file mode 100755 index 0000000000..010852b9c8 --- /dev/null +++ b/challenge-228/sgreen/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +use List::Util 'min'; + +sub main (@ints) { + # Get the minimum value + my $moves = 0; + my $min_int = min(@ints); + + while ( scalar @ints ) { + ++$moves; + my $value = shift @ints; + + # If this is the minimum value, calculate the new minimum value + if ( $value == $min_int ) { + if ( scalar(@ints) ) { + $min_int = min(@ints); + } + } + else { + # Move it to the end + push @ints, $value; + } + } + + say $moves; +} + +main(@ARGV);
\ No newline at end of file diff --git a/challenge-228/sgreen/python/ch-1.py b/challenge-228/sgreen/python/ch-1.py new file mode 100755 index 0000000000..039b606169 --- /dev/null +++ b/challenge-228/sgreen/python/ch-1.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + # Get the frequency of all numbers + freq = {} + for i in ints: + freq[i] = 1 + freq.get(i, 0) + + # Get the sum of all unique values + solution = sum(i for i in freq if freq[i] == 1) + print(solution) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) diff --git a/challenge-228/sgreen/python/ch-2.py b/challenge-228/sgreen/python/ch-2.py new file mode 100755 index 0000000000..5422a435d1 --- /dev/null +++ b/challenge-228/sgreen/python/ch-2.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + # Get the minimum value + moves = 0 + min_int = min(ints) + + while len(ints): + moves += 1 + value = ints.pop(0) + + # If this is the minimum value, calculate the new minimum value + if value == min_int: + if len(ints): + min_int = min(ints) + else: + # Move it to the end + ints.append(value) + + print(moves) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) |
