aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-163/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-163/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-163/paulo-custodio/python/ch-1.py33
-rw-r--r--challenge-163/paulo-custodio/python/ch-2.py51
4 files changed, 86 insertions, 2 deletions
diff --git a/challenge-163/paulo-custodio/perl/ch-1.pl b/challenge-163/paulo-custodio/perl/ch-1.pl
index 4e30d9c4a0..71603848ac 100644
--- a/challenge-163/paulo-custodio/perl/ch-1.pl
+++ b/challenge-163/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 163
#
diff --git a/challenge-163/paulo-custodio/perl/ch-2.pl b/challenge-163/paulo-custodio/perl/ch-2.pl
index abaed6e0f4..918a8874be 100644
--- a/challenge-163/paulo-custodio/perl/ch-2.pl
+++ b/challenge-163/paulo-custodio/perl/ch-2.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 163
#
diff --git a/challenge-163/paulo-custodio/python/ch-1.py b/challenge-163/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..67a949985e
--- /dev/null
+++ b/challenge-163/paulo-custodio/python/ch-1.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Challenge 163
+#
+# Task 1: Sum Bitwise Operator
+# Submitted by: Mohammad S Anwar
+#
+# You are given list positive numbers, @n.
+#
+# Write script to calculate the sum of bitwise & operator for all unique pairs.
+# Example 1
+#
+# Input: @n = (1, 2, 3)
+# Output: 3
+#
+# Since (1 & 2) + (2 & 3) + (1 & 3) => 0 + 2 + 1 => 3.
+#
+# Example 2
+#
+# Input: @n = (2, 3, 4)
+# Output: 2
+#
+# Since (2 & 3) + (2 & 4) + (3 & 4) => 2 + 0 + 0 => 2.
+
+def sum_biwise_and(*n):
+ total_sum = 0
+ for i in range(len(n) - 1):
+ for j in range(i + 1, len(n)):
+ total_sum += n[i] & n[j]
+ return total_sum
+
+import sys
+print(sum_biwise_and(*map(int, sys.argv[1:])))
diff --git a/challenge-163/paulo-custodio/python/ch-2.py b/challenge-163/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..12f03bb6e6
--- /dev/null
+++ b/challenge-163/paulo-custodio/python/ch-2.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+
+# Challenge 163
+#
+# Task 2: Summations
+# Submitted by: Mohammad S Anwar
+#
+# You are given a list of positive numbers, @n.
+#
+# Write a script to find out the summations as described below.
+# Example 1
+#
+# Input: @n = (1, 2, 3, 4, 5)
+# Output: 42
+#
+# 1 2 3 4 5
+# 2 5 9 14
+# 5 14 28
+# 14 42
+# 42
+#
+# The nth Row starts with the second element of the (n-1)th row.
+# The following element is sum of all elements except first element of previous
+# row.
+# You stop once you have just one element in the row.
+#
+# Example 2
+#
+# Input: @n = (1, 3, 5, 7, 9)
+# Output: 70
+#
+# 1 3 5 7 9
+# 3 8 15 24
+# 8 23 47
+# 23 70
+# 70
+
+import sys
+from functools import reduce
+
+def summation(*n):
+ n = list(n)
+ while len(n) > 1:
+ n.pop(0)
+ m = []
+ for i in range(len(n)):
+ m.append(sum(n[:i + 1]))
+ n = m
+ return n[0]
+
+print(summation(*map(int, sys.argv[1:])))