aboutsummaryrefslogtreecommitdiff
path: root/challenge-166/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-30 21:59:28 +0100
committerGitHub <noreply@github.com>2024-09-30 21:59:28 +0100
commite4cdda8a1053c2bcd7d33bbad494158355fd0b3c (patch)
treecc3c55c356d6a6c0a3ddf40e5e1853b341787b94 /challenge-166/paulo-custodio/python/ch-1.py
parentfb4ae25cbf52df4ae59b5b7dfbd32004b67be604 (diff)
parent13ac4b279c2937fc35bb2094095fa9203a7f5e30 (diff)
downloadperlweeklychallenge-club-e4cdda8a1053c2bcd7d33bbad494158355fd0b3c.tar.gz
perlweeklychallenge-club-e4cdda8a1053c2bcd7d33bbad494158355fd0b3c.tar.bz2
perlweeklychallenge-club-e4cdda8a1053c2bcd7d33bbad494158355fd0b3c.zip
Merge pull request #10934 from pauloscustodio/master
Add Python solutions
Diffstat (limited to 'challenge-166/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-166/paulo-custodio/python/ch-1.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-166/paulo-custodio/python/ch-1.py b/challenge-166/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..b64b0f1337
--- /dev/null
+++ b/challenge-166/paulo-custodio/python/ch-1.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+
+# Challenge 166
+#
+# Task 1: Hexadecimal Words
+# Submitted by: Ryan J Thompson
+#
+# As an old systems programmer, whenever I needed to come up with a 32-bit
+# number, I would reach for the tired old examples like 0xDeadBeef and
+# 0xC0dedBad. I want more!
+#
+# Write a program that will read from a dictionary and find 2- to 8-letter
+# words that can be "spelled" in hexadecimal, with the addition of the following
+# letter substitutions:
+#
+# o -> 0 (e.g., 0xf00d = "food")
+# l -> 1
+# i -> 1
+# s -> 5
+# t -> 7
+#
+# You can use your own dictionary or you can simply open
+# ../../../data/dictionary.txt (relative to your script's location in our GitHub
+# repository) to access the dictionary of common words from Week #161.
+#
+# Optional Extras (for an 0xAddedFee, of course!)
+#
+# Limit the number of "special" letter substitutions in any one result to
+# keep that result at least somewhat comprehensible. (0x51105010 is an
+# actual example from my sample solution you may wish to avoid!)
+#
+# Find phrases of words that total 8 characters in length
+# (e.g., 0xFee1Face), rather than just individual words.
+
+import sys
+
+if len(sys.argv) != 2:
+ sys.exit("usage: ch-1.py words.txt")
+
+f = open(sys.argv[1], "r")
+for line in f.readlines():
+ word = line.strip()
+ if len(word) >= 2 and len(word) <= 8 and all(c in 'abcdef0list' for c in word.lower()):
+ word = word.translate(str.maketrans('olist', '01157'))
+ print("0x" + word.upper())