Can you find the word 'needle' in the haystack below?
n e d e d
d e d e d l e l l
e e e e n n e e l e e
n n d e d l e d e e d n l
e l e e e e d e n n l d e
e e l n l e e e e n e d e d n
l l n n e e e e n d n e e e e
e e d e e l d e l e d d n d l
e e d e e l e d l n l l e e e
e n l e e e e e e d e d n l l
n n e e n n e n e e e e e e d
e e l d e e d d n n l e e l e
e d d l n l e l e e l n n e e
(In reply to
Another one... by Timothy Bard)
It appears 3 times.
start start
row col delta row delta col
5 10 1 -1
11 6 -1 -1
13 13 -1 -1
When delta row is 1 and delta col is -1, that's down and to the left. The other two are up and to the left, from the starting rows/col. Even rows/col positions that are blank are counted.
DIM ltr$(13, 15)
OPEN "needle.txt" FOR INPUT AS #1
DO
i = i + 1
LINE INPUT #1, l$
l$ = LEFT$(l$ + SPACE$(30), 30)
FOR j = 1 TO 15
ltr$(i, j) = MID$(l$, j * 2 - 1, 1)
NEXT j
LOOP UNTIL EOF(1)
FOR row = 1 TO 13
FOR col = 1 TO 15
IF ltr$(row, col) = "n" THEN
FOR dr = -1 TO 1
FOR dc = -1 TO 1
IF dr <> 0 OR dc <> 0 THEN
lr = row + dr * 5: lc = col + dc * 5
IF lr > 0 AND lr < 14 AND lc > 0 AND lc < 16 THEN
c = col: ptr = 1: good = 1
FOR r = row TO lr STEP dr
IF MID$("needle", ptr, 1) <> ltr$(r, c) THEN good = 0: EXIT FOR
c = c + dc
ptr = ptr + 1
NEXT r
IF good THEN
PRINT row, col, dr, dc
END IF
END IF
END IF
NEXT
NEXT
END IF
NEXT
NEXT
|
Posted by Charlie
on 2005-08-17 15:33:32 |