Advertisement
wtmhahagd

Untitled

Dec 5th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Word Permutations</title>
  5. </head>
  6. <body>
  7. <h1>Word permutations galore</h1>
  8. <?php
  9. $string = $_GET["string"];
  10. permutation("", $string);
  11. $count = 0;
  12.  
  13. function permutation($pre, $str) {
  14. $n = strlen($str);
  15. if (n == 0) {
  16. print "<p>" . $pre . "</p>";
  17. $count++;
  18. } else {
  19. for ($i = 0; $i < $n; ++$i) {
  20. //permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
  21. permutation($pre . $str[$i], $str.substr(0, $i) . $str.substr($i + 1));
  22. }
  23. }
  24.  
  25. return $p;
  26. }
  27.  
  28. print "<p>All combinations of " . $string . ":";
  29. print "There are " . $count . " permutations of " . $string . ".";
  30. ?>
  31. <script type="text/javascript" src="script.js"></script>
  32. </body>
  33. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement