Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Created Jan 30, 2022
Embed
What would you like to do?
<?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

lukebouch commented Apr 25, 2022

Hey @JacobBennett, if you are ok with it, I will rewrite this in JavaScript/AlpineJS and throw it up on GitHub Pages or Netlify.

@JacobBennett
Copy link
Author

JacobBennett commented Apr 26, 2022

do it!

@lukebouch
Copy link

lukebouch commented May 2, 2022

@JacobBennett ok I will

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