Skip to content

Instantly share code, notes, and snippets.

@jeek
Created April 27, 2012 06:53
Show Gist options
  • Save jeek/2506718 to your computer and use it in GitHub Desktop.
Save jeek/2506718 to your computer and use it in GitHub Desktop.
Anus evaluation
$| = 1;
use Memoize;
memoize(pullcard);
# Dredger + Faithless Looting + LED + Dredger
# AABC
# Dredger + LED/Putrid Imp + Faithless Looting/Careful Study/Breakthrough/Cephalid Coliseum + Rainbow land
# ABCH
# ACEH
# ACFH
# ACGH - REMOVED
# ABDH
# ADEH
# ADFH
# ADGH
# Dredger + Faithless Looting + Rainbow land + Faithless Looting/Careful Study/Breakthrough/Cephalid Coliseum
# ABBH
# ABEH
# ABFH
# ABGH
# Dredger + Careful Study + Rainbow land + Faithless Looting/Careful Study/Breakthrough/Cephalid Coliseum
# ABEH
# AEEH
# AEFH
# AEGH
# Dredger + Careful Study + Cephalid Coliseum + Cephalid Coliseum/Careful Study/Breakthrough
# AEGG
# AEEG
# AEFG
@needed = ("AABC", "ABCH", "ACEH", "ACFH", "ABDH", "ADEH", "ADFH", "ADGH", "ABBH", "ABEH", "ABFH", "ABGH", "ABEH", "AEEH", "AEFH", "AEGH", "AEGG", "AEEG", "AEFG");
# A: Dredger (5-12)
# B: Faithless Looting (0-4)
# C: LED (0-4)
# D: Putrip Imp / Tireless Tribe / Cabal Therapy (0-12)
# E: Careful Study (0-4)
# F: Breakthrough (0-4)
# G: Cephalid Coliseum (0-4)
# H: Rainbow Land (0-16)
for ($a = 12 ; $a >= 5 ; $a--) {
for ($b = 4 ; $b >= 0 ; $b--) {
for ($c = 4 ; $c >= 0 ; $c--) {
for ($d = 12 ; $d >= 0 ; $d--) {
for ($e = 4 ; $e >= 0 ; $e--) {
for ($f = 4 ; $f >= 0 ; $f--) {
for ($g = 4 ; $g >= 0 ; $g--) {
for ($h = 16 ; $h >= 0 ; $h--) {
if ($a + $b + $c + $d + $e + $f + $g + $h == 48) {
@deck = ();
for ($i = 0 ; $i < $a ; $i++) {
push @deck, "A";
}
for ($i = 0 ; $i < $b ; $i++) {
push @deck, "B";
}
for ($i = 0 ; $i < $c ; $i++) {
push @deck, "C";
}
for ($i = 0 ; $i < $d ; $i++) {
push @deck, "D";
}
for ($i = 0 ; $i < $e ; $i++) {
push @deck, "E";
}
for ($i = 0 ; $i < $f ; $i++) {
push @deck, "F";
}
for ($i = 0 ; $i < $g ; $i++) {
push @deck, "G";
}
for ($i = 0 ; $i < $h ; $i++) {
push @deck, "H";
}
while ((scalar @deck) < 60) {
push @deck, "I";
}
$deck = join ("",@deck);
print "" . (++$count) . " " . $deck . " ";
print deckeval($deck);
if (deckeval($deck) > $best) {
$best = deckeval($deck);
$bestdeck = $deck;
}
print " | $best $bestdeck\n";
}
}
}
}
}
}
}
}
}
print "$count\n";
sub deckeval {
my $deck = shift;
my $d7 = pullcard($deck,7,"");
my $d6 = pullcard($deck,6,"");
my $d5 = pullcard($deck,5,"");
my $d4 = pullcard($deck,4,"");
my $oddsofgood7 = ($d7 * 1.0 / (60 * 59 * 58 * 57 * 56 * 55 * 54));
my $oddsofgood6 = ($d6 * 1.0 / (60 * 59 * 58 * 57 * 56 * 55));
my $oddsofgood5 = ($d5 * 1.0 / (60 * 59 * 58 * 57 * 56));
my $oddsofgood4 = ($d4 * 1.0 / (60 * 59 * 58 * 57));
return ($oddsofgood7 + (1-$oddsofgood7)*$oddsofgood6 + (1-((1-$oddsofgood7)*$oddsofgood6))*$oddsofgood5 + (1-((1-((1-$oddsofgood7)*$oddsofgood6))*$oddsofgood5))*$oddsofgood4);
}
sub pullcard {
my $deck = shift;
my $handsize = shift;
my $pulledsofar = shift;
if ($handsize == length($pulledsofar)) {
my %counthash = ();
my $i;
foreach $i (split //,$pulledsofar) {
$counthash{$i}++;
}
foreach $i (@needed) {
my %hashcount = ();
my $j;
foreach $j (split (//,$i)) {
$hashcount{$j}++;
}
my $good = 1;
foreach $j (keys %hashcount) {
if ($counthash{$j} < $hashcount{$j}) {
$good = 0;
}
}
if ($good == 1) {
return 1;
}
}
return 0;
}
my $i; my $total = 0;
for ($i = 0 ; $i < length($deck) ; $i++) {
my $deckcopy = "";
my $pulledsofarcopy = $pulledsofar;
my $card = substr($deck,$i,1);
if ($i == 0) {
$deckcopy = substr($deck,1,length($deck)-1);
} else {
if ($i == (length($deck) - 1)) {
$deckcopy = substr($deck,0,length($deck)-1);
} else {
$deckcopy = substr($deck,0,$i) . substr($deck,$i+1,length($deck)-($i+1));
}
}
$pulledsofarcopy .= $card;
$pulledsofarcopy = join("",sort {$a cmp $b} split(//,$pulledsofarcopy));
$total += pullcard($deckcopy,$handsize,$pulledsofarcopy);
}
return $total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment