in reply to Improving this word search solver

I ultimately want to duplicate the results from this online tool, which produces perfect results ... The hidden message is supposed to be LYNNBUETTNERART, but my version produces LYNNBUETTNRART... (note the missing second E), whereas the the online tool gets this right.

Have you solved the puzzle by hand; are you sure the online tool is getting it "right"? One of your words is "EEL", which happens to appear on the second line, 12th character, down. That's where that "E" between "TN" and "RART" on the third line is probably going. Perhaps your ruleset is different from what the online tool is using. I'm guessing the online tool only matches each word once, and if that's the case, how does it determine which match has priority? Anyway, my suggestion:

  1. Decide on the set of rules used for solving. (Without these specs, it's difficult to give advice on a solution anyway!)
  2. Write many test cases, solving them by hand.
  3. Work on your algorithm until all tests pass.

Step 2 can get a little annoying, but Step 3 usually makes up for that, that feeling when all your tests pass is great :-)

Here's a template:

#!/usr/bin/env perl use warnings; use strict; use Test::More; is solve("FOO\nBAR\nOOF\n", ['FOO']), 'BAR'; my $INPUT1 = <<'_X_'; BFOO AQUZ ROOF _X_ my @WORDS1 = qw/ FOO BAR /; is solve($INPUT1, \@WORDS1), 'QUZ'; # more test cases here! done_testing; sub solve { my ($grid, $words) = @_; my $solution = "..."; # your algorithm here! return $solution; }

Replies are listed 'Best First'.
Re^2: Improving this word search solver
by phizel (Acolyte) on Jan 21, 2015 at 01:41 UTC
    The online tool is correct, especially since it outputs the right hidden message and mine is only close. I have no idea of their algorithm because it's closed source and the only other place I could find a similar algorithm was that codegolf stackexchange link.

      I don't see a description of their solver on their website at the moment, and my French is no good... If you really want your solving rules to match the "dCode" version exactly, you'll have to figure them out somehow - ask the people who wrote them, figure them out experimentally, ... in that respect my crystal ball is not any clearer than yours ;-)

      Remember, the "rules" for solving the puzzle are not necessarily the same as an algorithm. The rules will, in English (or French?), say things like "longer words match first", "the search proceeds from left to right, top to bottom", "each word matches only once", "matches across have higher priority than diagonal", etc. Maybe if you ask the people who implemented the solver, they can give you these rules, without revealing their code.

        I have implemented some rules, and you can see I look for longer words first. I have been tinkering with the code, but I can't replicate the results yet. I've also tried allowing only one match per word, but that didn't help this test case.
        I don't see a description of their solver on their website at the moment, and my French is no good...

        I looked at the French version, I haven't found any further detail on the detailed rules.

        Je suis Charlie.