Created
October 10, 2018 14:37
-
-
Save asdkant/9019014f26899b23ff2658082516da5d to your computer and use it in GitHub Desktop.
Solution to the "what is the longest word you can write with 7 segments displays" problem from Tom Scott's video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, re | |
# first argument: the words file | |
# second argument: the banned characters | |
wordsfile = sys.argv[1] | |
banned = sys.argv[2] | |
# print("words file: " + wordsfile) | |
# print("banned: " + banned) | |
# print("") | |
with open(wordsfile) as f: | |
lines = [line.rstrip('\n') for line in f.readlines()] | |
p = re.compile('[^'+banned+']*',re.IGNORECASE) | |
not_banned = list(filter(lambda x: p.fullmatch(x), lines)) | |
mlen = max(map(len,not_banned)) | |
result = [w for w in not_banned if len(w) == mlen] | |
for w in result: | |
print(w) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment