Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>Word Permutations</title>
- </head>
- <body>
- <h1>Word permutations galore</h1>
- <?php
- $string = $_GET["string"];
- permutation("", $string);
- $count = 0;
- function permutation($pre, $str) {
- $n = strlen($str);
- if (n == 0) {
- print "<p>" . $pre . "</p>";
- $count++;
- } else {
- for ($i = 0; $i < $n; ++$i) {
- //permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
- permutation($pre . $str[$i], $str.substr(0, $i) . $str.substr($i + 1));
- }
- }
- return $p;
- }
- print "<p>All combinations of " . $string . ":";
- print "There are " . $count . " permutations of " . $string . ".";
- ?>
- <script type="text/javascript" src="script.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement