Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $length = $_GET['length'];
- $proto = $_GET['proto'];
- $dead = $_GET['dead'];
- $dict = file("wordlist/" . $length . "_letters.txt", FILE_IGNORE_NEW_LINES);
- $exp = '/^' . str_replace('*', '\w{1}', $proto) . '$/u';
- $words = array_filter($dict, function($v) use ($exp, $dead) {
- $dw = true;
- foreach (array_diff(preg_split('//u', $dead), ['']) as $d) {
- if (preg_match('/' . $d . '/u', $v)) {
- $dw = false;
- break;
- };
- }
- return (preg_match($exp, $v) && $dw);
- });
- $letters = [];
- foreach ($words as $v) {
- $imp = implode('|', preg_split('//u', str_replace('*', '', $proto)));
- foreach (array_diff(preg_split('//u', preg_replace('/(' . $imp . ')/u', '', $v)), ['']) as $w) {
- $letters[] = $w;
- }
- }
- $percentageLetters = [];
- $count = count($letters);
- foreach (array_count_values($letters) as $k => $v) {
- $percentageLetters[] = ['letter' => $k, 'percent' => round(($v / $count * 100), 0) . '%'];
- }
- $ret = ['words' => $words, 'letters' => $percentageLetters];
- print_r($ret);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement