Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Hidden Word by viktor.chyrkin
from itertools import zip_longest
def checkio(text, word):
a = text.replace(' ', '').lower().split('\n')
b = map(''.join, zip_longest(*a, fillvalue=' '))
for w, k in enumerate((a, b)):
for i, e in enumerate(k, 1):
r = e.find(word)
if r != -1:
return [r + 1, i, r + len(word), i] if w else [i, r + 1, i, r + len(word)]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print('EX')
print(checkio("""DREAMING of apples on a wall,
And dreaming often, dear,
I dreamed that, if I counted all,
-How many would appear?""", "ten"))
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!")
Sept. 5, 2021
Comments: