17
2
Given a list of words and a grid of letters, find all the words in the grid and remove any letters which are not part of any of the words. The words could be forwards, backwards, up, down or diagonal. You may assume that no word in the list will occur in more than one place in the grid.
Input will always be: a list of words, 1 per line, followed by a blank line, followed by the grid of letters.
Examples
Input
ADA
ALGOL
ASSEMBLY
BASIC
COBOL
DELPHI
FORTRAN
JAVA
LABVIEW
LOGO
PASCAL
PERL
PHP
PYTHON
SMALLTALK
VISUALC
LLJKCABLFCI
OROLOBOCOIM
GELACSAPRSX
LPSTAHWVTAV
ANRLXLXQRBI
IHPLEDOXAHS
KJYAPHPYNOU
FABMADANZJA
EVISNOHTYPL
AAYLBMESSAC
WEIVBALOGOM
Output
LL K FC
OR LOBOCOI
GELACSAPRS
LP T TAV
A L RBI
IHPLED A S
J APHP N U
A MADA A
V SNOHTYPL
AYLBMESSAC
WEIVBALOGO
Input
BACKSPACE
BOLD
CLOSE
COMPACTDISC
COPY
CPU
CURSOR
DELETE
DESKTOP
DVD
EDIT
ENTER
EXIT
FLOPPY
FONT
HARDWARE
INTERNET
KEYBOARD
MONITOR
MOUSE
PASSWORD
PASTE
RETURN
SAVE
SOFTWARE
START
TEXT
TOWER
WORDPROCESSING
IAUERAWTFOSICPN
DGZPFLOPPYARFLU
RSNOCURSORVZDBM
AMNIUOMRNHEGUIN
OTBNSRMONITORNT
BEYTTSGPJBOLDRT
YRQEAHEHARDWARE
EOGRRNECECLOSEP
KIONTYKTODTOWER
ELCENSUPERPDKNN
ATRTPRYKELPVIEJ
GIEANPOTKSEDUSL
NXCMPASSWORDRUC
TEDITAGVSWJCTOV
CWOYPGYQKNLVXMW
Output
UERAWTFOS
DG PFLOPPYA
R NOCURSORV
A NI O E
OT NS MONITOR
B TTS P BOLD
Y EA EHARDWARE
E RRNECECLOSE
K NT KTO TOWER
E SUPER D
TRTPRY ELPVIE
IEANPOTKSED S
XC PASSWORDRUC
TEDITA O
P MW
This is code-golf - shortest solution wins.
Can we assume the grid is always square? – Scott Logan – 2011-08-09T16:38:19.463
@Bunnit No, I don't think so. Both the given examples are, but I think a solver should be able to handle other rectangular grids. – Gareth – 2011-08-09T16:41:32.500
Can we assume all letters are uppercase and A-Z? – Howard – 2011-08-09T18:09:57.917
@Howard Yes you can. – Gareth – 2011-08-09T18:10:33.493
@Gareth: In your first example, the bottom row has "LABVIEW" in it, but it is not displayed on the output. – Briguy37 – 2011-08-09T18:17:58.320
@Briguy37 Thanks. I did those things by hand and it took ages. I knew I'd mess it up. :-S – Gareth – 2011-08-09T18:19:46.367
@Gareth: No worries, I didn't see it either till I was testing my program :) – Briguy37 – 2011-08-09T18:32:01.360
I want to see a Befunge answer. – Thomas Eding – 2011-08-10T18:22:37.757
What if one word is inside of another word? E.g.
PASTE
andAST
? Does that count as a word being in "more than one place in the grid" ? – Joey Adams – 2011-08-11T03:43:07.097Also, can we assume that the word list will be sorted? – Joey Adams – 2011-08-11T03:50:11.563
@Joey Adams You can assume there will never be two words where one is a substring of another, but not that the list will be sorted. – Gareth – 2011-08-11T08:05:48.150