Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Created January 30, 2022 04:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JacobBennett/2f3893c6d48f69700600c00c44281458 to your computer and use it in GitHub Desktop.
Save JacobBennett/2f3893c6d48f69700600c00c44281458 to your computer and use it in GitHub Desktop.
<?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;
@lukebouch
Copy link

@JacobBennett ok I will

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment