Skip to content

Instantly share code, notes, and snippets.

@onishi
Created August 19, 2021 00:45
Show Gist options
  • Save onishi/31209e8c5733dd8c3a22a950f8bd55fc to your computer and use it in GitHub Desktop.
Save onishi/31209e8c5733dd8c3a22a950f8bd55fc to your computer and use it in GitHub Desktop.
ルービックキューブをシャッフルしたい
#!/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