Skip to content

Instantly share code, notes, and snippets.

@masak

masak/points.p6 Secret

Created January 16, 2015 11:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masak/eb8e9a370300c666a0ec to your computer and use it in GitHub Desktop.
Save masak/eb8e9a370300c666a0ec to your computer and use it in GitHub Desktop.
Third time's the charm: a program to generate all the 4x4 mazes
# bitstring; positions 0..11 correspond to vertical walls; 12..23 to horizontal;
# RAKUDO: can't do `0 x 24` here: RT #123602
my @old = "000000000000000000000000";
# 00 01 02
# 12 13 14 15
# 03 04 05
# 16 17 18 19
# 06 07 08
# 20 21 22 23
# 09 10 11
# 0..8 represent the nine internal corner points; 9 represents the outer wall
my @points =
# vertical walls 0..11
[0, 9], [1, 9], [2, 9],
[0, 3], [1, 4], [2, 5],
[3, 6], [4, 7], [5, 8],
[6, 9], [7, 9], [8, 9],
# horizontal walls 12..23
[0, 9], [0, 1], [1, 2], [2, 9],
[3, 9], [3, 4], [4, 5], [5, 9],
[6, 9], [6, 7], [7, 8], [8, 9],
;
my %symmetries =
id => 0..23,
rot1 => +«<15 19 23 14 18 22 13 17 21 12 16 20 2 5 8 11 1 4 7 10 0 3 6 9>,
rot2 => +«<11 10 9 8 7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12>,
rot3 => +«<20 16 12 21 17 13 22 18 14 23 19 15 9 6 3 0 10 7 4 1 11 8 5 2>,
flip => +«<9 10 11 6 7 8 3 4 5 0 1 2 20 21 22 23 16 17 18 19 12 13 14 15>,
frt1 => +«<12 16 20 13 17 21 14 18 22 15 19 23 0 3 6 9 1 4 7 10 2 5 8 11>,
frt2 => +«<2 1 0 5 4 3 8 7 6 11 10 9 15 14 13 12 19 18 17 16 23 22 21 20>,
frt3 => +«<23 19 15 22 18 14 21 17 13 20 16 12 11 8 5 2 10 7 4 1 9 6 3 0>,
;
sub p($s, $n) { $s.substr($n, 1) }
sub ch($s, $n) { $s.substr(0, $n) ~ "1" ~ $s.substr($n + 1) }
for 1..9 {
my %new;
for @old -> $s {
my @active = False xx 9, True;
for ^24 -> $n {
next unless p($s, $n);
@active[@points[$n][0]] = True;
@active[@points[$n][1]] = True;
}
for ^24 -> $n {
next if p($s, $n);
my @p = @points[$n].list;
if @active[@p[0]] != @active[@p[1]] {
my @w = ch($s, $n).comb;
my $min = [min] (@w[%symmetries{$_}.list].join for %symmetries.keys);
%new{$min}++;
}
}
}
@old = %new.keys;
note +@old;
}
.say for @old.sort;
# real 14m39.795s
# user 14m37.898s
# sys 0m2.157s
@eritain
Copy link

eritain commented Jul 25, 2016

This gist has bit-rotted just a skosh. Easy to fix; see my fork.

BTW, unique 3x4 rectangular mazes are in number 629.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment