Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Concise algorithm solution in Speedy category for The Hidden Word by Igor_Sekretarev
from itertools import zip_longest
from typing import List
def checkio(text: str, word: str) -> List[int]:
text = text.replace(' ', '').lower().splitlines()
for i, row in enumerate(text):
pos = row.find(word)
if pos >= 0:
return [i+1, pos+1, i+1, pos+len(word)]
for i, column in enumerate(map(''.join, zip_longest(*text, fillvalue=''))):
pos = column.find(word)
if pos >= 0:
return [pos+1, i+1, pos+len(word), i+1]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("""DREAMING of apples on a wall,
And dreaming often, dear,
I dreamed that, if I counted all,
-How many would appear?""", "ten") == [2, 14, 2, 16]
assert checkio("""He took his vorpal sword in hand:
Long time the manxome foe he sought--
So rested he by the Tumtum tree,
And stood awhile in thought.
And as in uffish thought he stood,
The Jabberwock, with eyes of flame,
Came whiffling through the tulgey wood,
And burbled as it came!""", "noir") == [4, 16, 7, 16]
print("Coding complete? Click 'Check' to earn cool rewards!")
April 26, 2021
Comments: