Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for The Hidden Word by Kurush
# migrated from python 2.7
def checkio(text, word):
text = text.replace(" ", "").lower()
word = word.lower()
rows = text.split("\n")
rows = [row.ljust(len(max(rows, key = len))) for row in rows]
columns = ["".join(item) for item in zip(*rows)]
for row_number, row in enumerate(rows):
index = row.find(word)
if index != -1: return [row_number + 1, index + 1, row_number + 1, index + len(word)]
for column_number, column in enumerate(columns):
index = column.find(word)
if index != -1: return [index + 1, column_number + 1, index + len(word), column_number + 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]
assert checkio("""xa
xb
x""", "ab") == [1, 2, 2, 2]
June 26, 2014