Created
August 19, 2021 00:45
-
-
Save onishi/31209e8c5733dd8c3a22a950f8bd55fc to your computer and use it in GitHub Desktop.
ルービックキューブをシャッフルしたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $count = shift || 20; | |
my @random = qw/R R F F U U L D M/; | |
my $rate_2 = 0.3; | |
my $rate_prime = 0.3; | |
my @result; | |
for my $i (1..$count) { | |
my $type; | |
while (1) { | |
$type = $random[int(rand(scalar @random))]; | |
$result[-1] or last; | |
$result[-1] =~ /$type/ or last; | |
} | |
if (rand() < $rate_2) { | |
$type .= '2'; | |
} | |
if ($type =~ /M/) { | |
$type .= q{'}; | |
} elsif (rand() < $rate_prime) { | |
$type .= q{'}; | |
} | |
push @result, $type; | |
} | |
print join(' ', @result) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment