Skip to content

Instantly share code, notes, and snippets.

@tgt
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgt/e07a3ba2a82ab4bc9348 to your computer and use it in GitHub Desktop.
Save tgt/e07a3ba2a82ab4bc9348 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use List::Util qw(minstr sum);
# bitstring; positions 0..11 correspond to vertical walls; 12..23 to horizontal;
# 24 to the outer wall
# RAKUDO: can't do `0 x 24 ~ 1` here: RT #123602
my @old = "0000000000000000000000001";
# 00 01 02
# 12 13 14 15
# 03 04 05
# 16 17 18 19
# 06 07 08
# 20 21 22 23
# 09 10 11
# neighboring relation; for example, wall 0 neighbors 3, 12, 13, and
# the outer wall
my @n = (
[3, 12, 13, 24], [4, 13, 14, 24], [5, 14, 15, 24],
[0, 6, 12, 13, 16, 17], [1, 7, 13, 14, 17, 18], [2, 8, 14, 15, 18, 19],
[3, 9, 16, 17, 20, 21], [4, 10, 17, 18, 21, 22], [5, 11, 18, 19, 22, 23],
[6, 20, 21, 24], [7, 21, 22, 24], [8, 22, 23, 24],
[0, 3, 13, 24], [0, 1, 3, 4, 12, 14], [1, 2, 4, 5, 13, 15], [2, 5, 14, 24],
[3, 6, 17, 24], [3, 4, 6, 7, 16, 18], [4, 5, 7, 8, 17, 19], [5, 8, 18, 24],
[6, 9, 21, 24], [6, 7, 9, 10, 20, 22], [7, 8, 10, 11, 21, 23], [8, 11, 22, 24]
);
sub p { my ($s, $n) = @_; return substr($s, $n, 1) }
sub n { my ($s, $n) = @_; return sum map { p($s, $_) } @{$n[$n]} }
sub ch { my ($s, $n) = @_; return substr($s, 0, $n) . "1" . substr($s, $n + 1) }
my %symmetries = (
id => [0..24],
rot1 => [qw(15 19 23 14 18 22 13 17 21 12 16 20 2 5 8 11 1 4 7 10 0 3 6 9 24)],
rot2 => [qw(11 10 9 8 7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12 24)],
rot3 => [qw(20 16 12 21 17 13 22 18 14 23 19 15 9 6 3 0 10 7 4 1 11 8 5 2 24)],
flip => [qw(9 10 11 6 7 8 3 4 5 0 1 2 20 21 22 23 16 17 18 19 12 13 14 15 24)],
frt1 => [qw(12 16 20 13 17 21 14 18 22 15 19 23 0 3 6 9 1 4 7 10 2 5 8 11 24)],
frt2 => [qw(2 1 0 5 4 3 8 7 6 11 10 9 15 14 13 12 19 18 17 16 23 22 21 20 24)],
frt3 => [qw(23 19 15 22 18 14 21 17 13 20 16 12 11 8 5 2 10 7 4 1 9 6 3 0 24)],
)
;
for (1..9) {
my %new;
for my $s (@old) {
for my $n (0..23) { # this doesn't include the outer wall
next if p($s, $n);
if (n($s, $n) == 1) {
my @w = split //, ch($s, $n);
my $min = minstr map { join '', @w[@{$symmetries{$_}}] } keys %symmetries;
$new{$min}++;
}
}
}
@old = keys %new;
warn scalar @old;
}
for (sort @old) {
print substr($_, 0, 24), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment