aboutsummaryrefslogtreecommitdiff
path: root/challenge-173/mohammad-anwar/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-13 23:55:31 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-13 23:55:31 +0100
commit47b189c896e6478d5e74dc74d6e91fa6cbaffab9 (patch)
tree48320154bc4b9cda0fcd4e5177c817620fe18c89 /challenge-173/mohammad-anwar/python/ch-1.py
parentfbf64879852eec49f370950872ce34903e357dfe (diff)
downloadperlweeklychallenge-club-47b189c896e6478d5e74dc74d6e91fa6cbaffab9.tar.gz
perlweeklychallenge-club-47b189c896e6478d5e74dc74d6e91fa6cbaffab9.tar.bz2
perlweeklychallenge-club-47b189c896e6478d5e74dc74d6e91fa6cbaffab9.zip
- Added solutions to the task "Esthetic Number" of week 173.
Diffstat (limited to 'challenge-173/mohammad-anwar/python/ch-1.py')
-rw-r--r--challenge-173/mohammad-anwar/python/ch-1.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/challenge-173/mohammad-anwar/python/ch-1.py b/challenge-173/mohammad-anwar/python/ch-1.py
new file mode 100644
index 0000000000..5d9e80c567
--- /dev/null
+++ b/challenge-173/mohammad-anwar/python/ch-1.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+'''
+
+Week 173:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-173
+
+Task #1: Esthetic Number
+
+ You are given a positive integer, $n.
+
+ Write a script to find out if the given number is Esthetic Number.
+
+'''
+
+import unittest
+
+def is_esthetic_number(n):
+ s = str(n)
+ for i in range(1, len(s)):
+ if abs(int(s[i-1]) - int(s[i])) != 1:
+ return False
+ return True
+
+#
+#
+# Unit test class
+
+class TestPrimePartition(unittest.TestCase):
+
+ def test_example_1(self):
+ self.assertTrue(is_esthetic_number(5456))
+
+ def test_example_2(self):
+ self.assertFalse(is_esthetic_number(120))
+
+unittest.main()