Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use List::Util qw(minstr sum);
  6. # bitstring; positions 0..11 correspond to vertical walls; 12..23 to horizontal;
  7. my @old = "000000000000000000000000";
  8.  
  9. # 00 01 02
  10. # 12 13 14 15
  11. # 03 04 05
  12. # 16 17 18 19
  13. # 06 07 08
  14. # 20 21 22 23
  15. # 09 10 11
  16.  
  17. # 0..8 represent the nine internal corner points; 9 represents the outer wall
  18. my @points = (
  19. # vertical walls 0..11
  20. [0, 9], [1, 9], [2, 9],
  21. [0, 3], [1, 4], [2, 5],
  22. [3, 6], [4, 7], [5, 8],
  23. [6, 9], [7, 9], [8, 9],
  24. # horizontal walls 12..23
  25. [0, 9], [0, 1], [1, 2], [2, 9],
  26. [3, 9], [3, 4], [4, 5], [5, 9],
  27. [6, 9], [6, 7], [7, 8], [8, 9]
  28. );
  29.  
  30. my %symmetries = (
  31. id => [0..23],
  32. 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)],
  33. 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)],
  34. 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)],
  35. 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)],
  36. 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)],
  37. 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)],
  38. 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)],
  39. )
  40. ;
  41.  
  42. sub p { my ($s, $n) = @_; return substr($s, $n, 1) }
  43. sub ch { my ($s, $n) = @_; return substr($s, 0, $n) . "1" . substr($s, $n + 1) }
  44.  
  45. for (1..9) {
  46. my %new;
  47. for my $s (@old) {
  48. my @active = (0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
  49. for my $n (0..23) {
  50. next unless p($s, $n);
  51. $active[$points [$n][0]] = 1;
  52. $active[$points [$n][1]] = 1;
  53. }
  54. for my $n (0..23) {
  55. next if p($s, $n);
  56. my @x = @{$points[$n]};
  57. if ($active[$x[0]] != $active[$x[1]]) {
  58. my @w = split //, ch($s, $n);
  59. my $min = minstr map { join '', @w[@{$symmetries{$_}}] } keys %symmetries;
  60. $new{$min}++;
  61. }
  62. }
  63. }
  64.  
  65. @old = keys %new;
  66. warn scalar @old;
  67. }
  68.  
  69. for (sort @old) {
  70. print substr($_, 0, 24), "\n";
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement