Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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;
- 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 => [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)],
- 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)],
- 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)],
- 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)],
- 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)],
- 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)],
- 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)],
- )
- ;
- sub p { my ($s, $n) = @_; return substr($s, $n, 1) }
- sub ch { my ($s, $n) = @_; return substr($s, 0, $n) . "1" . substr($s, $n + 1) }
- for (1..9) {
- my %new;
- for my $s (@old) {
- my @active = (0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
- for my $n (0..23) {
- next unless p($s, $n);
- $active[$points [$n][0]] = 1;
- $active[$points [$n][1]] = 1;
- }
- for my $n (0..23) {
- next if p($s, $n);
- my @x = @{$points[$n]};
- if ($active[$x[0]] != $active[$x[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";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement