The New Turtle Solver (cont) 

# Generate all 324 possible card placements
my(@placements, %vec_desc);
foreach my $c (0..$#cards) {
    my @card = @{ $cards[$c] };
    foreach my $rotation (1..4) {
        my $description = join ' ', @card;
        foreach my $p (0..8) {
            my $pos = $positions[$p];
            my $row = '';
            vec($row, 48 + $#cards, 1) = 0;
            vec($row, 48 + $c,      1) = 1;
            foreach my $j (0..3) {
                my $junction = $pos->[$j] or next;
                vec($row, $junction - 1, 4) = $bits_from_name{$card[$j]};
            }
            push @placements, $row;
            $vec_desc{$row} = $description;
        }
        unshift @card, pop @card;
    }
}