-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path\
88 lines (63 loc) · 1.2 KB
/
\
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @state;
my $N = 6;
my $moves = [generate(1), generate(0)];
for (my $i = 0; $i < $N; $i++) {
if (($i+1) % 2==0) {
$state[$i]=1;
}
else {
$state[$i]=0;
}
}
print "----\n";
foreach my $i (@$moves) {
move($i);
}
#generate(1);
sub generate
{
my ($odd) = @_;
my @res;
for (my $i = 0; $i < $N; $i++) {
if (($i+1) % 2==$odd) {
$state[$i]=1;
}
else {
$state[$i]=0;
}
}
print " ".join(", ", @state),"\n";
for (my $k = 0; $k < $N; $k++) {
if ($state[$k]!=0) {
print "Touch $k\n";
move($k);
push @res, $k;
}
}
return @res;
}
sub move
{
my ($current) = @_;
$state[$current] = 0;
# print "A: ".join(", ", @state),"\n";
my @todo;
for (my $i = 0; $i < $N; $i++) {
next if $state[$i] == 0;
$state[$i]--;
if ($i > 0) {
push @todo, $i-1;
}
if ($i < $N-1) {
push @todo, $i+1;
}
}
foreach my $j (@todo) {
$state[$j]=1;
}
print "B: ".join(", ", @state),"\n";
}