aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-02 18:35:51 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-02 18:35:51 +0000
commiteb11c182157d8a281f6a4cf62762e7d3135a4e73 (patch)
tree4c55b097a65424753525ffdd9e2a211b116a3938
parentba46d97a0cc88123fceac1767e823591121e35e9 (diff)
downloadperlweeklychallenge-club-eb11c182157d8a281f6a4cf62762e7d3135a4e73.tar.gz
perlweeklychallenge-club-eb11c182157d8a281f6a4cf62762e7d3135a4e73.tar.bz2
perlweeklychallenge-club-eb11c182157d8a281f6a4cf62762e7d3135a4e73.zip
Add Python solution to challenge 117
-rw-r--r--challenge-117/paulo-custodio/Makefile2
-rw-r--r--challenge-117/paulo-custodio/python/ch-1.py33
-rw-r--r--challenge-117/paulo-custodio/python/ch-2.py57
-rwxr-xr-xchallenge-117/paulo-custodio/test.pl4
4 files changed, 92 insertions, 4 deletions
diff --git a/challenge-117/paulo-custodio/Makefile b/challenge-117/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-117/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-117/paulo-custodio/python/ch-1.py b/challenge-117/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..9788415993
--- /dev/null
+++ b/challenge-117/paulo-custodio/python/ch-1.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python3
+
+# Challenge 117
+#
+# TASK #1 - Missing Row
+# Submitted by: Mohammad S Anwar
+# You are given text file with rows numbered 1-15 in random order but there
+# is a catch one row in missing in the file.
+#
+# 11, Line Eleven
+# 1, Line one
+# 9, Line Nine
+# 13, Line Thirteen
+# 2, Line two
+# 6, Line Six
+# 8, Line Eight
+# 10, Line Ten
+# 7, Line Seven
+# 4, Line Four
+# 14, Line Fourteen
+# 3, Line three
+# 15, Line Fifteen
+# 5, Line Five
+# Write a script to find the missing row number.
+
+import sys
+
+rows = set(range(1, 16))
+for line in sys.stdin:
+ row = int(line.split(',')[0])
+ if row in rows:
+ rows.remove(row)
+print(",".join([str(x) for x in list(rows)]))
diff --git a/challenge-117/paulo-custodio/python/ch-2.py b/challenge-117/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..5e979b888d
--- /dev/null
+++ b/challenge-117/paulo-custodio/python/ch-2.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+
+# Challenge 117
+#
+# TASK #2 - Find Possible Paths
+# Submitted by: E. Choroba
+# You are given size of a triangle.
+#
+# Write a script to find all possible paths from top to the bottom right
+# corner.
+#
+# In each step, we can either move horizontally to the right (H), or move
+# downwards to the left (L) or right (R).
+#
+# BONUS: Try if it can handle triangle of size 10 or 20.
+#
+# Example 1:
+# Input: $N = 2
+#
+# S
+# / \
+# / _ \
+# /\ /\
+# /__\ /__\ E
+#
+# Output: RR, LHR, LHLH, LLHH, RLH, LRH
+# Example 2:
+# Input: $N = 1
+#
+# S
+# / \
+# / _ \ E
+#
+# Output: R, LH
+
+import sys
+
+def get_paths(size):
+ paths = []
+
+ def find_paths(path, row, col):
+ nonlocal paths, size
+
+ if row==size and col==size: # reached end
+ paths.append(path)
+ else:
+ if row < size:
+ find_paths(path+'L', row+1, col)
+ find_paths(path+'R', row+1, col+1)
+ if col < row:
+ find_paths(path+'H', row, col+1)
+
+ find_paths('', 0, 0)
+ return paths
+
+paths = get_paths(int(sys.argv[1]))
+print(", ".join(paths))
diff --git a/challenge-117/paulo-custodio/test.pl b/challenge-117/paulo-custodio/test.pl
deleted file mode 100755
index ba6c37260b..0000000000
--- a/challenge-117/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';