aboutsummaryrefslogtreecommitdiff
path: root/challenge-046/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
committerLubos Kolouch <lubos@kolouch.net>2024-09-16 09:41:35 +0200
commit65b9d6b25e0a823ca7ab6d15744ff98eb3697471 (patch)
treefcbcdebd50e3e146dfecf519701ec04b191053eb /challenge-046/paulo-custodio/python/ch-1.py
parentbd1fe7ae50ca42bda58c134b9edfdc287fb3f386 (diff)
parent68e321dd32a834f54b55d5e8924f04358e41cf1f (diff)
downloadperlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.gz
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.tar.bz2
perlweeklychallenge-club-65b9d6b25e0a823ca7ab6d15744ff98eb3697471.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-046/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-046/paulo-custodio/python/ch-1.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/challenge-046/paulo-custodio/python/ch-1.py b/challenge-046/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..bf49bd63c2
--- /dev/null
+++ b/challenge-046/paulo-custodio/python/ch-1.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+# Challenge 046
+#
+# TASK #1
+# Cryptic Message
+# The communication system of an office is broken and message received are not
+# completely reliable. To send message Hello, it ended up sending these following:
+#
+# H x l 4 !
+# c e - l o
+# z e 6 l g
+# H W l v R
+# q 9 m # o
+# Similary another day we received a message repeatedly like below:
+#
+# P + 2 l ! a t o
+# 1 e 8 0 R $ 4 u
+# 5 - r ] + a > /
+# P x w l b 3 k \
+# 2 e 3 5 R 8 y u
+# < ! r ^ ( ) k 0
+# Write a script to decrypt the above repeated message (one message repeated 6
+# times).
+#
+# HINT: Look for characters repeated in a particular position in all six messages
+# received.
+
+import sys
+
+def read_input():
+ input = []
+ for line in sys.stdin:
+ input.append(line.rstrip())
+ return input
+
+def decode(input):
+ decoded = ""
+ for col in range(len(input[0])):
+ hist = {}
+ max_letter, max_count = '', 0
+ for row in range(len(input)):
+ letter = input[row][col]
+ if letter not in hist:
+ hist[letter] = 1
+ else:
+ hist[letter] += 1
+ if hist[letter] > max_count:
+ max_letter, max_count = letter, hist[letter]
+ decoded += max_letter
+ return decoded
+
+
+input = read_input()
+decoded = decode(input)
+print(decoded)