diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-07-24 10:06:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-24 10:06:19 +0100 |
| commit | dccad79fb3738429d8cb704663cbbc012a6a4e6d (patch) | |
| tree | 200cc0746ee3445d0d4a76b990ba44762abc31c0 | |
| parent | 35c6f5200e28d661dc3142cfca919ebd93f5e073 (diff) | |
| parent | aa833882a1c8cc63273b16e326718460e200fa21 (diff) | |
| download | perlweeklychallenge-club-dccad79fb3738429d8cb704663cbbc012a6a4e6d.tar.gz perlweeklychallenge-club-dccad79fb3738429d8cb704663cbbc012a6a4e6d.tar.bz2 perlweeklychallenge-club-dccad79fb3738429d8cb704663cbbc012a6a4e6d.zip | |
Merge pull request #6487 from simongreen-net/master
sgreen solutions to challenge 174
| -rw-r--r-- | challenge-174/sgreen/README.md | 4 | ||||
| -rw-r--r-- | challenge-174/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-174/sgreen/perl/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-174/sgreen/python/ch-1.py | 25 |
4 files changed, 60 insertions, 2 deletions
diff --git a/challenge-174/sgreen/README.md b/challenge-174/sgreen/README.md index c4ff584191..e236fffec0 100644 --- a/challenge-174/sgreen/README.md +++ b/challenge-174/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 173 +# The Weekly Challenge 174 -[Blog](https://dev.to/simongreennet/weekly-challenge-173-1kli) +[Blog](https://dev.to/simongreennet/weekly-challenge-174-5ga6) diff --git a/challenge-174/sgreen/blog.txt b/challenge-174/sgreen/blog.txt new file mode 100644 index 0000000000..4ed97d8715 --- /dev/null +++ b/challenge-174/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-174-5ga6
\ No newline at end of file diff --git a/challenge-174/sgreen/perl/ch-1.pl b/challenge-174/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..1d5ea07511 --- /dev/null +++ b/challenge-174/sgreen/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use experimental 'signatures'; + +sub is_disarium ($n) { + my $sum = 0; + + foreach my $count ( 1 .. length($n) ) { + $sum += substr( $n, $count - 1, 1 )**$count; + } + + return $sum == $n; +} + +sub main { + my @solutions = (); + my $number = 0; + + while ( scalar(@solutions) < 19 ) { + if ( is_disarium($number) ) { + push @solutions, $number; + } + $number++; + } + + say join ', ', @solutions; +} + +main(); diff --git a/challenge-174/sgreen/python/ch-1.py b/challenge-174/sgreen/python/ch-1.py new file mode 100755 index 0000000000..cf3ae3c075 --- /dev/null +++ b/challenge-174/sgreen/python/ch-1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +def is_disarium(n): + sum = 0 + + for count, value in enumerate(str(n)): + sum += int(value) ** (count+1) + + return sum == n + + +def main(): + solutions = [] + number = 0 + + while len(solutions) < 19: + if is_disarium(number): + solutions.append(number) + number += 1 + + print(*solutions, sep=', ') + + +if __name__ == '__main__': + main() |
