aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-174/sgreen/README.md4
-rw-r--r--challenge-174/sgreen/blog.txt1
-rwxr-xr-xchallenge-174/sgreen/perl/ch-1.pl32
-rwxr-xr-xchallenge-174/sgreen/python/ch-1.py25
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()