Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. $length = $_GET['length'];
  2. $proto = $_GET['proto'];
  3. $dead = $_GET['dead'];
  4.  
  5. $dict = file("wordlist/" . $length . "_letters.txt", FILE_IGNORE_NEW_LINES);
  6.  
  7. $exp = '/^' . str_replace('*', '\w{1}', $proto) . '$/u';
  8. $words = array_filter($dict, function ($v) use ($exp, $dead) {
  9. $dw = true;
  10. foreach (array_diff(preg_split('//u', $dead), ['']) as $d) {
  11. if (preg_match('/' . $d . '/u', $v)) {
  12. $dw = false;
  13. break;
  14. };
  15. }
  16. return (preg_match($exp, $v) && $dw);
  17. });
  18.  
  19. $letters = [];
  20. foreach ($words as $v) {
  21. $imp = implode('|', preg_split('//u', str_replace('*', '', $proto)));
  22. foreach (array_diff(preg_split('//u', preg_replace('/(' . $imp . ')/u', '', $v)), ['']) as $w) {
  23. $letters[] = $w;
  24. }
  25. }
  26.  
  27. $percentageLetters = [];
  28. $count = count($words);
  29. foreach (array_unique($letters) as $v) {
  30. $c = 0;
  31. foreach ($words as $w) {
  32. if (preg_match('/' . $v . '/u', $w)) $c++;
  33. }
  34. $percentageLetters[] = ['letter' => $v, 'percent' => round(($c / $count * 100), 1) . '%'];
  35. }
  36. uasort($percentageLetters, function ($a, $b) {
  37. return ((float)$a['percent'] > (float)$b['percent']) ? -1 : 1;
  38. });
  39.  
  40. $ret = ['words' => $words, 'letters' => $percentageLetters];
  41. print_r($ret);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement