On the Subject of Passwords

Pyth, 13 bytes

:#%*"[%s]"5Q0c"ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE"5

Test suite.

 #             filter possible words on
:           0  regex match, with pattern
  %        Q   format input as
    "[%s]"     surround each group of letters with brackets (regex char class)
   *      5    repeat format string 5 times for 5 groups of letters

Bash, 22 bytes

grep `printf [%s] $@`< <(echo ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE | sed 's/...../&\n/g')

Run like so:

llama@llama:~$ bash passwords.sh FGARTW LKSIRE UHRKPA TGYSTG LUOTEU
FIRST
      printf [%s] $@    surround all command line args with brackets
grep `              `   output all input lines that match this as a regex
                     <  use the following file as input to grep

Ruby, 48 42 39 bytes

Now that it's done, it's very similar to the Pyth solution, but without %s formatting to the point where it's basically a direct port now.

If you only output the result with puts, you don't need the [0] at the end since puts will deal with that for you.

->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

With test cases:

f=->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

w = %w{about after again below could
every first found great house
large learn never other place
plant point right small sound
spell still study their there
these thing think three water
where which world would write}

puts f.call(w, ["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"]) # first
puts f.call(w, ["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"]) # large
puts f.call(w, ["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"]) # still

Tags:

Code Golf