|
|
|||||||
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:Example$outputarray=Anagram($inputarray) 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 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 a score of 45.for $b=0 to ubound($a) 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 ] |
||||||||
|
|
|||||||
AJ: This will NOT require a dictionary since you are only comparing the provided words. So, if I have the words ELVIS, LIVES, SILVER then the algorithm should be able to figure out that ELVIS is an anagram of LIVES and that SILVER is not an anagram of either ELVIS or LIVES. The algorithm is not supposed to find that SLIVER is an anagram of SILVER since SLIVER wasn't provided in the list of words. |
||||||||
|
|
|||||||
again (I think I said this last time too), isn't the actual number V not IV... [ 18. August 2002, 00:06: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
got it pretty much done on paper... just can't figure the use for sorting. it should double my code... |
||||||||
|
|
|||||||
I think there is something wrong with the validation code... I don't have the sort yet in my code but wanted to check how it comes out with current state. there was no output at all but it just said that my udf passed the validation... |
||||||||
|
|
|||||||
huh. currently the sorting has got my code tribled and it's not even working properly yet. guys, are you all sleeping or what? I miss brian as he was a competition even at night time... just wonder what hoby might be doing... |
||||||||
|
|
|||||||
ok, first working code. score: 548 now I'll start playing with forms2.0 beta. [ 18. August 2002, 06:33: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
Lonkero: If $outputarray is empty, then yes, it'll tell you that your UDF passed. I will update the code to reflect the case of $outputarray being empty. |
||||||||
|
|
|||||||
mmm... also, if the array is less than 4 elements, it gets passed. hoby, your version 3 of the golfcounter is lot harder to use as you can't use it directly on commandline without adding the line: kixgolf($F) into the start. neither putting it to the udf-file did not work as then it errored out. Golf Score: 531 |
||||||||
|
|
|||||||
Lonkero, I use KicGolf3.kix like this so that it reports the score after each test execution. code:Jens' Kix code... |
||||||||
|
|
|||||||
yeah, that's what I mean... there is need to play with shell. well, as long as it counts faster than me, it will do. |
||||||||
|
|
|||||||
Well Jooel, I have working code, but nowhere near as tight as yours. KixGolf score = 1851 |
||||||||
|
|
|||||||
well, currently at 523 but can't cut it anymore... head hearts already and we have still something like 80 hours to code. |
||||||||
|
|
|||||||
At least I can see some progress being made in my code during the next 80 hours. Too bad your code is so good. |
||||||||
|
|
|||||||
well, I'm waiting... and I'm afraid that brian is going to show up suddenly tomorrow and beat me. and still, even though it seems to work correctly, there can be a bug... Golf Score: 515 |
||||||||
|
|
|||||||
btw, I was going over 1000 when tried to get that sorting working. then found some nice tricks and here is the result. as the actual anagram finding code is only 180-200 scores |
||||||||
|
|
|||||||
hoby, still there? Golf Score: 484 |
||||||||
|
|
|||||||
Well I was hoping to get one over on Lonkero with 527, but I wasn't fast enough! |
||||||||
|
|
|||||||
good god! you're getting really close and my code is hard to get even one stroke shorter! |
||||||||
|
|
|||||||
Okay folks, here's my preliminary score. It's for a working code without variable name reductions: KiXtart Golf Score=1458 |
||||||||
|
|
|||||||
Golf Score: 483 {edit 21:23} Golf Score: 482 [ 18. August 2002, 21:23: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
Jens, what if the number of words in a set exceeds 15? discard the rest or make a set of 15 and a set of the rest? How must this be printed? |
||||||||
|
|
|||||||
well, I understood that it will not exceed. means no checking for that is needed. also, it may and may not work for with longer ones too. I tested my shortest code with: $inputarray='hack,snooped,tables,salt,spiff,tnipr,feeling,spooned,last,print,intpr,grep,bleats,gas,ablest,fleeing,stable,slat,drive,rpitn' and output was: feeling fleeing snooped spooned last salt slat ablest bleats stable tables intpr print rpitn tnipr [ 18. August 2002, 21:57: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
Golf Score 507 Can't seem to break the magic 500 barrier |
||||||||
|
|
|||||||
I have some difficulties here too. I tried changing and compining and mixing. got it to work but scores went to 490... can't seem to cut this anymore. |
||||||||
|
|
|||||||
now it's done. after three hours of playing with simple if statement saves one stroke getting me to Golf Score: 481 {edit [02:20 finnish time]} duh. numbers are lovely strings... Golf Score: 479 {edit 02:45} I quess it's time for me to go to bed... Golf Score: 473 [ 19. August 2002, 01:43: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
Golf score = 483 only 10 behind! Jens - Technical question. If the input array is empty or there are no matches, what do you want returned ? a) An unassigned variable (VarType = Empty) b) An empty string (VarType = String) c) An array containing only (a) above* d) An array containing only (b) above* (* array consists of one dimension ie UBOUND($OutputArray) = 0) [ 19. August 2002, 21:14: Message edited by: AJH ] |
||||||||
|
|
|||||||
I think then the output should be empty... or 0 lenght string or something like that... |
||||||||
|
|
|||||||
If the input string is empty, then the output string is empty. If the input array is empty, then the output string is empty. |
||||||||
|
|
|||||||
ajh, I leave you in peace. I left my laptop at work and at home have only linux-server. this means, you can freely try to beat my score. I have to sleep. as you got so close I can assume only that your code is same as mine before... or it uses really fully different syntax. if latter, you might even get ahead of me. |
||||||||
|
|
|||||||
If I read Jens correctly then no anagrams should produce a variable as the result (vartype 'Empty' Ubound = -1), and I have a score of 477 (so near and yet so far ). If on the other hand no anagrams can produce an empty array (vartype = Variant[] with Ubound = 0, Result[0] = Empty) then I can get 468. So Lonkero still rules! |
||||||||
|
|
|||||||
AJH: I don't think you read it correctly, I specified that the OUTPUT STRING is empty, thus VARTYPE=8. Anyway, below is a more extensive validation script. It checks four different conditions 1) Anagrams (as provided in the firts post) 2) Empty input string 3) Empty input array 4) Input string with words but not containing any anagrams My score is now 742 passing all four conditions and I have absolutely no clue how to cut out about 1/3rd of my code to come close to you guys code:BREAK ON |
||||||||
|
|
|||||||
AJH, How can I still rule if you are almost 10 ahead of me? I also have code shrunk some much, I can't do anything to it anymore. and I think my code size propably rises on the explicit string on output. uttleast 4 chars. |
||||||||
|
|
|||||||
Still trying... feeling fleeing snooped spooned last salt slat ablest bleats stable tables The Anagram() UDF passed validation KixGolf score = 470 {edit} KixGolf score = 467 {edit} KixGolf score = 464 {edit} KixGolf score = 462 {edit} KixGolf score = 458 [ 20. August 2002, 09:34: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
hoby, you seem to be rocking today. I can't get any of the strokes out and you just cut them like they were just air. I think I must start reorganizing my udf... |
||||||||
|
|
|||||||
I soooo tired, but I can't stop. |
||||||||
|
|
|||||||
Got it working without sorting; Score = 267 Be back later with sorting (if I get it working!) |
||||||||
|
|
|||||||
heh... pat, it just is that the sorting makes it big. my script would be just 100 chars without it. |
||||||||
|
|
|||||||
just 100?? Well I won't give up... |
||||||||
|
|
|||||||
Jens 4 tests put me back up to 487 |
||||||||
|
|
|||||||
Everybody: Please test your Anagram scripts with KiXtart 4.11 RC-1. My script bombs with a line like this: code:It seems we lost the ability to directly reference an array element after a split operation. KiXtart 4.10a and KiXtart 4.11 beta 2 seem to work fine, though.$a=split($b,' ')[0] Anyway, now that your heart is racing, you are free to use any Kixtart version of your choosing. |
||||||||
|
|
|||||||
What 4 tests? Jens only supplied one. Still at: KixGolf score = 458 |
||||||||
|
|
|||||||
Jens, Sad but true It seems that you are right, you can't directly reference a member from the split() function when using v. 4.11 rc1 -Erik |
||||||||
|
|
|||||||
Yeah, I'll report is as a bug Also, I ahve expanded my test suite again, this time with more anagrams. The latest version of th test suite is posted below and (because of the extremely long lines) can also be downloaded at http://people.bu.edu/jenmeyer/kixtart/anagram_test.zip You will also need the KiXGolf3.kix file and KiXtart in the same directory as the test script. then just paste your Anagram UDF into it, and it'll validate your UDF and spit out the KiXtart golf score. I'm done with my script, passing all five validation test and achieving a test score of 742 and no way of shortening it. code:BREAK ON |
||||||||
|
|
|||||||
after changing my udf to return empty strings instead of empty arrays the score raised: Golf Score: 495 I'll give this up as my script has had so many structures all the loops one can think of and so much weirdness... can't compete anymore. |
||||||||
|
|
|||||||
My score will probably being going up as well. I just ran Jens new validation code and only passed the first test. [ 20. August 2002, 20:49: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
Now that is strange, you should have passed the first and second test since they are just two different sets of anagrams. |
||||||||
|
|
|||||||
I cheated on the half of the sorting since I was coding to the inital test only. My sorting algorithm succeeded in one step with the first array but could and did fail on a different mix of words. [ 20. August 2002, 19:47: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
does that mean that I still have hope? would like to hear AJH's current score too... |
||||||||
|
|
|||||||
Started from scratch again. C:\Data\Scripts\Golf>C:\Data\Kix2001\KiX2001.411b2\kix32 golf4.kix feeling fleeing snooped spooned last salt slat ablest bleats stable tables UDF passed regular input array test admirer married aphrodite atrophied perseus peruses filets itself stifle hoes hose shoe ladder larded raddle filters lifters stifler trifles parental parlante paternal prenatal portes poster presto repost UDF passed another regular input array test UDF passed empty input array test UDF passed empty input string test UDF passed no anagram input array test The Anagram() UDF passed validation KixGolf score = 672 time to start tweaking {edit} KixGolf score = 658 {edit} KixGolf score = 653 {edit} KixGolf score = 645 [ 21. August 2002, 18:00: Message edited by: Howard Bullock ] |
||||||||
|
|
|||||||
now, if ajh would just inform us where he is at. otherwise I'll assume, I'm in lead again and rest this day. anyway, if you get pass me, it's not that I didn't try, but I did best I could already at the weekend. now, it's not compressable. |
||||||||
|
|
|||||||
KixGolf score = 625 |
||||||||
|
|
|||||||
you are running out of time sadly, didn't take my laptop home so can't post the to be winning code until tomorrow. means 10 hours from now. [ 21. August 2002, 20:27: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
As stated previously Current golf score = 487 Passes Jens 5 tests |
||||||||
|
|
|||||||
oh, man I like to see your script. can't think of what method you used on it... |