aboutsummaryrefslogtreecommitdiff
path: root/challenge-173/mohammad-anwar/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-16 13:55:23 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-07-16 13:55:23 +0100
commitedf94eeec3c29a9cfdf35792f43096a5cebae6bf (patch)
tree26210c58ff21fbfb83a93f8a1d934ed7d2c7e8e7 /challenge-173/mohammad-anwar/python/ch-2.py
parent51b2e3d945bde176baf659ca6f7f5ef2626232ce (diff)
downloadperlweeklychallenge-club-edf94eeec3c29a9cfdf35792f43096a5cebae6bf.tar.gz
perlweeklychallenge-club-edf94eeec3c29a9cfdf35792f43096a5cebae6bf.tar.bz2
perlweeklychallenge-club-edf94eeec3c29a9cfdf35792f43096a5cebae6bf.zip
- Added solutions to the task "Sylvester Sequence" of week 173.
Diffstat (limited to 'challenge-173/mohammad-anwar/python/ch-2.py')
-rw-r--r--challenge-173/mohammad-anwar/python/ch-2.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-173/mohammad-anwar/python/ch-2.py b/challenge-173/mohammad-anwar/python/ch-2.py
new file mode 100644
index 0000000000..0bedda5388
--- /dev/null
+++ b/challenge-173/mohammad-anwar/python/ch-2.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python3
+
+'''
+
+Week 173:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-173
+
+Task #2: Sylvester’s sequence
+
+ Write a script to generate first 10 members of Sylvester's sequence.
+
+'''
+
+import unittest
+
+def SylvesterSequence(n):
+ ss = [2]
+ for i in range (1, --n):
+ ss.append(1 + ss[-1] * (ss[-1] - 1))
+ return ss
+
+#
+#
+# Unit test class
+
+class TestSylvesterSequence(unittest.TestCase):
+
+ def test_example(self):
+ self.assertEqual(SylvesterSequence(10),
+ [
+ 2
+ ,3
+ ,7
+ ,43
+ ,1807
+ ,3263443
+ ,10650056950807
+ ,113423713055421844361000443
+ ,12864938683278671740537145998360961546653259485195807
+ ,165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
+ ])
+
+unittest.main()