10 my ($p1, $sign, $score, $p2) = /(\w+) would (\w+) (\d+) happiness units? by sitting next to (\w+)\./;
11 $sign = ($sign eq 'gain') ? 1 : -1;
12 $rules{$p1}{$p2} = $sign * $score;
18 for my $p (keys %persons) {
19 $rules{myself}{$p} = 0;
20 $rules{$p}{myself} = 0;
25 my ($done, $rest) = @_;
28 for my $i (0 .. $#$rest) {
31 push @nd, splice @nr, $i, 1;
36 for my $i (0 .. $#$done) {
37 my $self = $done->[$i];
38 my @neigh = ($done->[$i-1], $done->[$i == $#$done ? 0 : $i+1]);
40 $score += $rules{$self}{$n};
43 $max = $score if !defined $max || $max < $score;
47 perm([], [ keys %persons ]);