All pastes #277266 Raw Edit

Something

public text v1 · immutable
·published 2006-12-13 01:37 UTC
rendered paste body
sub megaminx {
  if (time()-$time >= 20 && $parse[2] =~ /#testing123/i) {
    my $chars = "AaBbCcDdEeFf2'";
    my @check = (1,0,3,2,5,4,7,6,9,8,11,10);
    my ($result, $a, $b, $c, $rand);
    for (my $i; $i < 60; $i++) {
      $rand = int(rand(12));
      while ($rand == $a || !is_legal_pair($rand,$a,$b) || !is_legal_triple($rand,$a,$b,$c)) { 
        $rand = int(rand(12));
      }
      $c = $b;
      $b = $a;
      $a = $rand;
      $result .= substr($chars,$rand,1);
      $rand = int(rand(4));
      if ($rand) {
        if ($rand == 2) {
          $result .= "2'";
        } else {
          $result .= substr($chars,$rand+11,1);
        }
      }
      $result .= " ";
    }
    $totalm++;
    #print "megaminx scramble #: $result\n";
    print $sock "privmsg #testing123 :megaminx scramble #$totalm: $result\n";
    print "<micro5002> megaminx scramble #$totalm: $result\n";
    $time = time();
    save_counts();
  }
}

sub is_legal_pair { 
  if ($_[0] != $_[2]) { return 1; }
  if (is_adjacent($_[0],$_[1])) { return 1; }
  return 0;
}
sub is_adjacent {
  if (index($edges{$_[0]},$_[1]) != -1) { return 1; }
  return 0;
}
sub is_legal_triple {
  if ($_[0] != $_[3]) { return 1; }
  if (is_adjacent($_[0],$_[1]) || is_adjacent($_[0],$_[2])) { return 1; }
  return 0;
}