Skip to content

Instantly share code, notes, and snippets.

@sudarshang
Last active February 10, 2022 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudarshang/28cb53a44d879354a8101575cc011bbb to your computer and use it in GitHub Desktop.
Save sudarshang/28cb53a44d879354a8101575cc011bbb to your computer and use it in GitHub Desktop.
Word challenge
import sys
from itertools import chain
telepad = [
["1"],
["2", "a", "b", "c"],
["3", "d", "e", "f"],
["4", "g", "h", "i" ],
["5", "j", "k", "l"],
["6", "m", "n", "o"],
["7", "p", "q", "r", "s"],
["8", "t", "u", "v"],
["9", "w", "x", "y", "z"],
]
contigous_sets = [set(chain(*telepad[i:i+3])) for i in range(len(telepad) - 3 + 1)]
for line in sys.stdin:
word = line.strip()
for set in contigous_sets:
if all(l in set for l in word.lower()):
print word
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment