use File::stat;
use List::Util qw(min max);
+use POSIX qw(floor);
my %options = (debug => 0,
help => 0,
# for now, concentrate on finding single word solutions
if ($options{acrostic}) {
+}
+elsif ($options{acrostic}) {
foreach my $word (@words) {
my $length = length($word);
my @let = split //, $word;
return grep {$words{$_} >= $must_match} keys %words;
}
+sub solve_acrostic {
+ my ($acrostic) = @_;
+ # need to find unsolved words
+
+ # if there are multiple intersecting unsolved locations, try to
+ # solve the hard ones first, then the easy ones.
+
+ # given the current state of the board, find all possible words
+ # that fit the fixed positions
+
+ # find unsolved words
+
+ # find positions with _ or ?, * or | are unsolved bits
+
+ # scan the puzzle from left to right, top to bottom (across
+ # answers), then top to bottom, left to right (down answers)
+ my $in_word=0;
+ my $current_answer=0;
+
+ sub __add_to_answers {
+ my ($acrostic,$current_answer,$in_word,$pos) = @_;
+ if ($acrostic->{grid}[$pos] !~ /^\*\|$/) {
+ if (not $$in_word) {
+ $$current_answer++;
+ }
+ $$in_word = 1;
+ $acrostic->{answers}[$$current_answer]{letters} .= $acrostic->{grid}[$pos];
+ $acrostic->{answers}[$$current_answer]{length}++;
+ $acrostic->{answers}[$$current_answer]{unsolved} = 0;
+ push @{$acrostic->{answers}[$current_answer]{positions}}, $pos;
+ push @{$acrostic->{answer_grid}[$pos]}, $current_answer;
+ if ($acrostic->{grid}[$pos] =~ /^\_\?$/) {
+ $acrostic->{answers}[$$current_answer]{unsolved} = 1;
+ }
+ }
+ else {
+ $$in_word = 0;
+ }
+ }
+
+ for my $width (0..($acrostic->{width}-1)) {
+ $in_word = 0;
+ for my $height (0..($acrostic->{height}-1)) {
+ my $pos = $height*$acrostic->{height} + $width;
+ __add_to_answers($acrostic,\$current_answer,\$in_word,$pos);
+ }
+ }
+ for my $height (0..($acrostic->{height}-1)) {
+ $in_word = 0;
+ for my $width (0..($acrostic->{width}-1)) {
+ my $pos = $height*$acrostic->{height} + $width;
+ __add_to_answers($acrostic,\$current_answer,\$in_word,$pos);
+ }
+ }
+
+ # for all possible answers which are unsolved, find allowable words
+ for my $answer (0..$#{$acrostic->{answers}}) {
+ }
+
+ # for all crossing positions, find allowed letters and eliminate
+ # words which do not share a letter in common with a word in the
+ # opposite direction
+
+ # for all crossing positions, eliminate words which do not share a
+ # letter in common with a word in the opposite direction
+}
+
sub update_and_load_database {
my ($dir,$wordlist) = @_;