-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.pl
More file actions
48 lines (38 loc) · 903 Bytes
/
example.pl
File metadata and controls
48 lines (38 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
use lib 'extlib/lib/perl5', 'lib';
use warnings;
use strict;
use v5.14;
use WordTree;
use BoggleGraph;
use Boggle qw(find_all_words);
my $wt = WordTree->init();
say $wt->search('abase');
say $wt->search('ardvark');
say $wt->search('aardvar');
my $board = [
['e', 'e', 'c', 'a'],
['a', 'l', 'e', 'p'],
['h', 'n', 'b', 'o'],
['q', 't', 't', 'a'],
];
my $graph = BoggleGraph->new();
for (my $y = 0; $y < @$board; $y++) {
for (my $x = 0; $x < @{$board->[$y]}; $x++) {
$graph->insert_node(
x => $x,
y => $y,
letter => $board->[$x][$y]
);
}
}
$graph->add_edges;
my %result;
for (my $y = 0; $y < 4; $y++) {
for (my $x = 0; $x < 4; $x++) {
my $start = $graph->board->[$x][$y];
map { $result{$_} = 1 } find_all_words($start, $wt);
}
}
say foreach (sort keys %result);
exit;