-
-
Save JacobBennett/2f3893c6d48f69700600c00c44281458 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
$lookup = [ | |
1 => "\u{2B1C}", // white | |
2 => "\u{1F7E8}", // yellow | |
3 => "\u{1F7E9}", // green | |
]; | |
function getNumber($weight, $max) { | |
// probability that you will get a green | |
if ($max == 1) { | |
return 1; | |
} | |
if ($max == 3 && mt_rand(1, 100) <= $weight) { | |
return 3; | |
} else { | |
return mt_rand(1,2); | |
} | |
} | |
$numberOfMoves = rand(1,6); | |
$string = ''; | |
if ($numberOfMoves == 1) { | |
// just make it a win already | |
$string = '33333'; | |
} else { | |
$results = collect(range(1,$numberOfMoves - 1))->reduce(function($carry, $item) use ($numberOfMoves) { | |
$last = end($carry); | |
$new = collect($last)->map(function ($number) use ($numberOfMoves, $item) { | |
// create some weight for how probable it is to get a green | |
$weight = (($numberOfMoves - ($item+1)) / $numberOfMoves) * 100; | |
return getNumber($weight, $number); | |
})->toArray(); | |
array_push($carry, $new); | |
return $carry; | |
}, [[3,3,3,3,3]]); | |
$string = collect($results)->reverse()->map(function ($items) { | |
return implode('', $items); | |
})->join("\n"); | |
} | |
$newThing = str_replace(array_keys($lookup), array_values($lookup), $string); | |
return "Wordle 222 {$numberOfMoves}/6\n\n".$newThing; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@JacobBennett ok I will