diff options
| -rw-r--r-- | challenge-173/paulo-custodio/perl/ch-1.pl | 2 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/perl/ch-2.pl | 4 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/python/ch-1.py | 33 | ||||
| -rw-r--r-- | challenge-173/paulo-custodio/python/ch-2.py | 37 |
4 files changed, 73 insertions, 3 deletions
diff --git a/challenge-173/paulo-custodio/perl/ch-1.pl b/challenge-173/paulo-custodio/perl/ch-1.pl index caba1bf96d..859df10ea8 100644 --- a/challenge-173/paulo-custodio/perl/ch-1.pl +++ b/challenge-173/paulo-custodio/perl/ch-1.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 173 # diff --git a/challenge-173/paulo-custodio/perl/ch-2.pl b/challenge-173/paulo-custodio/perl/ch-2.pl index 34eb742026..765fc70299 100644 --- a/challenge-173/paulo-custodio/perl/ch-2.pl +++ b/challenge-173/paulo-custodio/perl/ch-2.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Challenge 173 # -# Task 2: Sylvester’s sequence +# Task 2: Sylvester's sequence # Submitted by: Mohammad S Anwar # # Write a script to generate first 10 members of Sylvester's sequence. For more diff --git a/challenge-173/paulo-custodio/python/ch-1.py b/challenge-173/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..47d713f903 --- /dev/null +++ b/challenge-173/paulo-custodio/python/ch-1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +# Challenge 173 +# +# Task 1: Esthetic Number +# Submitted by: Mohammad S Anwar +# +# You are given a positive integer, $n. +# +# Write a script to find out if the given number is Esthetic Number. +# +# An esthetic number is a positive integer where every adjacent digit differs +# from its neighbour by 1. +# +# +# For example, +# +# 5456 is an esthetic number as |5 - 4| = |4 - 5| = |5 - 6| = 1 +# 120 is not an esthetic numner as |1 - 2| != |2 - 0| != 1 + +def is_esthetic(n): + n = list(map(int, str(n))) + while len(n) > 1: + if abs(n[0] - n[1]) != 1: + return 0 + n.pop(0) + return 1 + +import sys + +if len(sys.argv) != 2: + raise ValueError("usage: ch-1.py n") +print(1 if is_esthetic(sys.argv[1]) else 0) diff --git a/challenge-173/paulo-custodio/python/ch-2.py b/challenge-173/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..0ccf9d64d7 --- /dev/null +++ b/challenge-173/paulo-custodio/python/ch-2.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +# Challenge 173 +# +# Task 2: Sylvester's sequence +# Submitted by: Mohammad S Anwar +# +# Write a script to generate first 10 members of Sylvester's sequence. For more +# informations, please refer to the wikipedia page. +# +# Output +# +# 2 +# 3 +# 7 +# 43 +# 1807 +# 3263443 +# 10650056950807 +# 113423713055421844361000443 +# 12864938683278671740537145998360961546653259485195807 +# 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 + +import sys + +def sylvester_seq(N): + n = [2] + prod = 2 + while len(n) < N: + term = prod + 1 + n.append(term) + prod *= term + return n + +if len(sys.argv) != 2: + raise ValueError("usage: ch-2.py n") +print(", ".join(map(str, sylvester_seq(int(sys.argv[1]))))) |
