Advertisement
iAnonGuy

~ Max Possible Combination(s) Generator ~

Aug 17th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Max Possible Combination(s) Generator</title>
  5.     <style type="text/css">
  6.     body {background-color: black;}
  7.     h1 {font-family: monospace; color: white;}
  8.     </style>
  9. </head>
  10. <body>
  11. <center>
  12. <h1>~ Max Possible Combination(s) Generator ~</h1>
  13. <form method="POST">
  14.     <input type="text" name="comb" />
  15.     <font face="Monospace" color="lime"> ~ </font>
  16.     <input type="submit" value="Generate" />
  17. </form>
  18. <?php
  19. /*
  20. Credits for the function goes to, Joel Hinz.
  21. http://stackoverflow.com/questions/19067556/php-algorithm-to-generate-all-combinations-of-a-specific-size-from-a-single-set
  22.                                                                                                                            */
  23. function combinations($chars, $size, $combinations = array())
  24. {if (empty($combinations)) {$combinations = $chars;}
  25. if ($size == 1) {return $combinations;}
  26. $new_combinations = array();
  27. foreach ($combinations as $combination) {
  28. foreach ($chars as $char) {
  29. $new_combinations[] = $combination . $char;}}
  30. return combinations($chars, $size - 1, $new_combinations);}
  31.  
  32. $chars = $_POST['comb']; # The Post Param
  33. $count = 1; # Duuuh :v
  34. if (isset($chars)){
  35. $strspl = str_split($chars); # To get every 'char' from the param.
  36. $strlen = strlen($chars); # To get the length of the str from the param
  37. $result = combinations($strspl, $strlen); # Runnin the function
  38. echo '<br><font face="Monospace" color="white">Total Possible Combinations<font color="lime"> ~ <font color="red">'.count($result).'<br>'; # Echoing the count of combinations.
  39. foreach ($result as $r) { # Foreach statement to echo the "result"
  40.    echo '<font color="white">'.$count++.' <font color="lime">~<font color="red"> '.$r.'<br>'; # the final result
  41. }}
  42. ?>
  43. </center>
  44. </body>
  45. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement