Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
KiXtart Golf IV: Anagrams
The general KiXtart Golf rules are at the end of the post. Following are the goal and rules for the current KiXtart Golf challange.
Goal Find all the anagrams in a given input array and display them in the specified format.
An anagram is a word (or phrase, but we'll stick with words for this contest) formed by rearranging the letters of another word (or phrase). For example, elvis and lives.
Rules The input file is an array of words, one word per array element. Each word consists of [a-z] only.
Each input array element consists of the word only, with no leading or trailing whitespace, and no empty lines (unless the array or array element is empty).
Please note that the input array can be empty.
You may not assume that the input array will be sorted.
You are to return the anagrams found, one space-delimited array element for each set.
You are to print the anagrams and only the anagrams: you are to discard standalone words with no anagrams.
A array element of the output array consists of all the words that anagrams the others: each word is separated by one space (no leading/trailing space allowed).
Each set of anagrams will not exceed 15 words per anagram.
The words on each output array element will be sorted alphabetically.
The output array elements are first sorted by number of words (the fewer first), then alphabetically using the first word of the line (after the line itself is sorted alphabetically).
The program may use any version of KiXtart up to and including the latest beta versions (currently KiXtart 4.11 beta 2)
The prototye for the function is as follows:
code:
$outputarray=Anagram($inputarray)
Example Given the input:
hack snooped tables salt spiff feeling spooned last grep bleats gas ablest fleeing stable slat drive
You are to output the following:
feeling fleeing snooped spooned last salt slat ablest bleats stable tables
Test Code
code:
BREAK ON
DIM $rc, $inputarray, $correctoutput, $outputarray, $line, $error
$rc=SETOPTION('Explicit','ON') $rc=SETOPTION('NoVarsInString','ON')
$inputarray='hack,snooped,tables,salt,spiff,feeling,spooned,last,grep,bleats,gas,ablest,fleeing,stable,slat,drive' $correctoutput='feeling fleeing,snooped spooned,last salt slat,ablest bleats stable tables'
$inputarray=SPLIT($inputarray,',') $correctoutput=SPLIT($correctoutput,',')
$outputarray=Anagram($inputarray)
IF UBOUND($outputarray)=UBOUND($correctoutput) FOR $line=0 TO UBOUND($outputarray) ? $outputarray[$line] IF $outputarray[$line]<>$correctoutput[$line] $error=1 ENDIF NEXT ELSE $errror=1 ENDIF
IF $error ? 'The output array is not correct' ELSE ? 'The Anagram() UDF passed validation' ENDIF
; beginning of the Anagram() UDF and supporting UDFs ; end of the Anagram() UDF and supporting UDFs
================================================================ KiXtart GOLF - How To Play ================================================================
Most importantly, anybody can play, no age restrictions, no penalties, no handicap!
The object in "real" golf is to hit the ball in the hole in the fewest strokes. The object in KiXtart Golf is to get from input (tee) to target (hole) in the fewest keystrokes.
Example: How many positive elements are in array $a?
Array $a could be of structure $a=[1, 2 ,-3, 4, -5, -7, 8, 9]
One approach:
code:
for $b=0 to ubound($a) if $a[$b]>0 $c=$c+1 endif next
for a score of 45.
Another solution is: code]DO $b=$b+1 if $a[$b]>0 $c=$c+1 endif UNTIL $b>(UBOUND($a)+1)[/code]
for a score of 53.
Better approach: Code sample 1
================================================================ KiXtart GOLF - The Rules ================================================================
1) The goal of KiXtart Golf is to score the lowest strokes.
2) Strokes are all characters in a piece of code except whitespace characters, unless the whitespace character is necessary for the line of code to work. Therefore, carriage returns and line feeds do not count or spaces in between the '=' sign when assigning variables, e.g. '$a = $b' scores 5.
3) Code can be constructed any way you like, as long as it is syntactically correct with KiXtart.
4) The final solution MUST pass all test scripts that accompagny the KiXtart golf challenge.
5) The use of '$' as a variable is allowed.
6) In case of questions about a particular way to count the KiXtart Golf Challenge organizer has the last call.
7) During the private coding phase, no code is allowed to be posted. Violations result in disqualification of said player.
8) During the public coding phase, code should be posted, reused, and borrowed from other players.
9) The following script can be used to count the KiXtart Golf score: http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=2;t=003608
================================================================ KiXtart GOLF - The Duration of the Competition ================================================================
1) Private coding phase: From date/time of posting the tournament challenge to the following Wednesday, 3pm EST (BBS+6 time)
2) Public coding phase: From Wednesday 3pm EST (BBS+6 time) to the following Sunday, 7pm EST (BBS+6 time)
3) Final results: The following Monday, 11am EST (BBS+6 time) [ 18. August 2002, 15:21: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|