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 cnkisk
def checkio(text, word):
sol = text.replace(" ","").lower().split("\n")
res = [0,0,0,0]
w = word[0]
for i, s in enumerate(sol):
find_start = 0
if word in s:
return [i+1, s.find(word)+1, i+1, s.find(word)+len(word)]
else:
for _ in range(s.count(w)):
print(i,"count",s.count(w))
col_start = s.find(w,find_start)
if col_start >= 0:
res[0], res[1] = i+1, col_start+1
k = i
for num, j in enumerate(word):
print(j,i+1,col_start+1,sol[k][col_start])
if sol[k][col_start] == j:
if num == len(word)-1:
res[2],res[3] = k+1,col_start+1
return res
k += 1
else:
break
find_start = col_start+1
return False
#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!")
Nov. 29, 2020