aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-05 12:16:25 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-05 12:16:25 +0000
commit99eada75aaf9004ad00c84c089c4a98d1c72bf14 (patch)
treec6980403440f18d4366bb80c8fdd2f4fb2a8b510
parent1516641772cf7b58d9dc4c172d1a2a23c22ec1a6 (diff)
downloadperlweeklychallenge-club-99eada75aaf9004ad00c84c089c4a98d1c72bf14.tar.gz
perlweeklychallenge-club-99eada75aaf9004ad00c84c089c4a98d1c72bf14.tar.bz2
perlweeklychallenge-club-99eada75aaf9004ad00c84c089c4a98d1c72bf14.zip
Add Python solution to challenge 108
-rw-r--r--challenge-108/paulo-custodio/Makefile2
-rw-r--r--challenge-108/paulo-custodio/python/ch-1.py12
-rw-r--r--challenge-108/paulo-custodio/python/ch-2.py63
-rw-r--r--challenge-108/paulo-custodio/t/test-2.yaml2
-rwxr-xr-xchallenge-108/paulo-custodio/test.pl4
5 files changed, 78 insertions, 5 deletions
diff --git a/challenge-108/paulo-custodio/Makefile b/challenge-108/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-108/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-108/paulo-custodio/python/ch-1.py b/challenge-108/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..132951c182
--- /dev/null
+++ b/challenge-108/paulo-custodio/python/ch-1.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+
+# Challenge 108
+#
+# TASK #1 - Locate Memory
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to declare a variable or constant and print it's location in
+# the memory.
+
+var = "hello world"
+print(hex(id(var)))
diff --git a/challenge-108/paulo-custodio/python/ch-2.py b/challenge-108/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..569e6f47bf
--- /dev/null
+++ b/challenge-108/paulo-custodio/python/ch-2.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+
+# Challenge 108
+#
+# TASK #2 - Bell Numbers
+# Submitted by: Mohammad S Anwar
+#
+# Write a script to display top 10 Bell Numbers. Please refer to wikipedia page
+# for more informations.
+#
+# Example:
+# B0: 1 as you can only have one partition of zero element set
+# B1: 1 as you can only have one partition of one element set {a}.
+# B2: 2
+# {a}{b}
+# {a,b}
+# B3: 5
+# {a}{b}{c}
+# {a,b}{c}
+# {a}{b,c}
+# {a,c}{b}
+# {a,b,c}
+# B4: 15
+# {a}{b}{c}{d}
+# {a,b,c,d}
+# {a,b}{c,d}
+# {a,c}{b,d}
+# {a,d}{b,c}
+# {a,b}{c}{d}
+# {a,c}{b}{d}
+# {a,d}{b}{c}
+# {b,c}{a}{d}
+# {b,d}{a}{c}
+# {c,d}{a}{b}
+# {a}{b,c,d}
+# {b}{a,c,d}
+# {c}{a,b,d}
+# {d}{a,b,c}
+
+import sys
+
+def bell_numbers():
+ n = -1
+ bell = []
+ while True:
+ n += 1
+ if n==0:
+ bell.append([1])
+ yield 1
+ else:
+ bell.append([bell[n-1][n-1]])
+ for i in range(1, n+1):
+ bell[n].append(bell[n-1][i-1] + bell[n][i-1])
+ yield bell[n][0]
+
+count = int(sys.argv[1])
+bell = []
+for n in bell_numbers():
+ if count<=0:
+ break
+ bell.append(n)
+ count -= 1
+print(" ".join([str(x) for x in bell]))
diff --git a/challenge-108/paulo-custodio/t/test-2.yaml b/challenge-108/paulo-custodio/t/test-2.yaml
index db839db250..123634d58d 100644
--- a/challenge-108/paulo-custodio/t/test-2.yaml
+++ b/challenge-108/paulo-custodio/t/test-2.yaml
@@ -1,5 +1,5 @@
- setup:
cleanup:
- args:
+ args: 10
input:
output: 1 1 2 5 15 52 203 877 4140 21147
diff --git a/challenge-108/paulo-custodio/test.pl b/challenge-108/paulo-custodio/test.pl
deleted file mode 100755
index ba6c37260b..0000000000
--- a/challenge-108/paulo-custodio/test.pl
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env perl
-use Modern::Perl;
-use Test::More;
-require '../../challenge-001/paulo-custodio/test.pl';