Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $Phrases = array(
- "Your Chinese zodiac tells a lot about your personality.",
- "Embed PHP Scripts within an XHTML document.");
- $SignNames = array(
- "Rat",
- "Ox",
- "Tiger",
- "Rabbit",
- "Dragon",
- "Snake",
- "Horse",
- "Goat",
- "Monkey",
- "Rooster",
- "Dog",
- "Pig");
- function BuildLetterCounts($text){
- $text = strtoupper($text);
- $letter_counts = count_chars($text);
- return $letter_counts;
- }
- function AContainsB($A, $B){
- $retval = TRUE;
- $first_letter_index = ord('A');
- $last_letter_index = ord('Z');
- for ($letter_index = $first_letter_index;
- $letter_index <= $last_letter_index;
- ++$letter_index){
- if ($A[$letter_index] < $B[$letter_index]) {
- $retval = FALSE;
- }
- }
- return $retval;
- }
- foreach ($Phrases as $Phrase) {
- $PhraseArray = BuildLetterCounts($Phrase);
- $GoodWords = array();
- $BadWords = array();
- }
- foreach ($SignNames as $Word) {
- $WordArray = BuildLetterCounts($Word);
- if (AContainsB($PhraseArray, $WordArray))
- $GoodWords[] = $Word;
- else
- $BadWords[] = $Word;
- }
- echo "<p>The following words can be made from the letters in the phrase "$Phrase":";
- foreach ($GoodWords As $Word)
- echo " $Word";
- echo "</p>\n";
- echo "<p>The following words can NOT be made from the letters in the phrase "$Phrase":";
- foreach ($BadWords as $Word)
- echo " $Word";
- echo "</p>\n";
- echo "<hr />\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment