Railway circuit: Difference between revisions

m
→‎{{header|Perl}}: use False/True instead of 0/1
(Added Perl)
m (→‎{{header|Perl}}: use False/True instead of 0/1)
Line 920:
 
use constant pi => 2 * atan2(1, 0);
use enum qw(False True);
 
my @twelvesteps = map { Point->new( x => sin(pi * $_/6), y => cos(pi * $_/6) ) } 1 .. 12;
Line 942 ⟶ 943:
push @allsym, circularsymmetries(@turns);
push @allsym, circularsymmetries(map { -1 * $_ } @turns);
$$infound{$_} = 1True for @allsym;
(sort @allsym)[-1]
}
Line 948 ⟶ 949:
sub isclosedpath($straight, @turns) {
my $start = Point->new(x=> 0, y =>0);
return 0False unless (if sum(@turns) % ($straight ? 4 : 12) ) == 0;
my ($angl, $point) = (0, $start);
for my $turn (@turns) {
Line 957 ⟶ 958:
}
 
sub allvalidcircuits($N, $doPrint = 0False, $straight = 0False) {
my ( @found, %infound );
say "\nFor N of ". $N . ' and ' . ($straight ? 'straight' : 'curved') . ' track:';
Line 963 ⟶ 964:
my @turns = $straight ?
map { $_ == 0 ? 0 : ($_ == 1 ? -1 : 1) } digits($i,3,$N) :
map { $_ == 0 ? -1 : 1 } digits($i,2,$N);
if (isclosedpath($straight, @turns) && ! exists $infound{join ' ', @turns} ) {
my $canon = addsymmetries(\%infound, @turns);
Line 974 ⟶ 975:
}
 
allvalidcircuits($_, 1True) for 12, 16, 20;
allvalidcircuits($_, 1True, 1True) for 4, 6, 8;</lang>
{{out}}
<pre>For N of 12 and curved track:
2,392

edits