Page 1 of 3 123>
Topic Options
#69123 - 2002-08-17 10:03 PM KiXtart Golf Tournament IV: Anagrams
Sealeopard Offline
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.

Top
#69124 - 2002-08-17 10:30 PM Re: KiXtart Golf Tournament IV: Anagrams
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#69125 - 2002-08-18 12:01 AM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 ]
_________________________
!

download KiXnet

Top
#69126 - 2002-08-18 01:27 AM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
got it pretty much done on paper...

just can't figure the use for sorting.
it should double my code...
_________________________
!

download KiXnet

Top
#69127 - 2002-08-18 02:25 AM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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...
_________________________
!

download KiXnet

Top
#69128 - 2002-08-18 05:28 AM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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...
_________________________
!

download KiXnet

Top
#69129 - 2002-08-18 06:18 AM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, first working code.

score: 548

now I'll start playing with forms2.0 beta.

[ 18. August 2002, 06:33: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#69130 - 2002-08-18 03:19 PM Re: KiXtart Golf Tournament IV: Anagrams
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#69131 - 2002-08-18 04:56 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#69132 - 2002-08-18 05:08 PM Re: KiXtart Golf Tournament IV: Anagrams
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Lonkero, I use KicGolf3.kix like this so that it reports the score after each test execution.
code:
Jens' Kix code...

shell "C:\Data\Kix2001\KiX2001.410\kix32 c:\data\scripts\Kixgolf3.kix $f=@scriptname"
; beginning of the Anagram() UDF and supporting UDFs
;!
Code...
;!
; end of the Anagram() UDF and supporting UDFs

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69133 - 2002-08-18 05:10 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#69134 - 2002-08-18 05:59 PM Re: KiXtart Golf Tournament IV: Anagrams
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well Jooel, I have working code, but nowhere near as tight as yours.

KixGolf score = 1851
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69135 - 2002-08-18 06:03 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, currently at 523 but can't cut it anymore...

head hearts already and we have still something like 80 hours to code.
_________________________
!

download KiXnet

Top
#69136 - 2002-08-18 06:06 PM Re: KiXtart Golf Tournament IV: Anagrams
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
At least I can see some progress being made in my code during the next 80 hours. [Big Grin] Too bad your code is so good. [Eek!]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#69137 - 2002-08-18 06:08 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#69138 - 2002-08-18 06:10 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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
_________________________
!

download KiXnet

Top
#69139 - 2002-08-18 07:16 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hoby, still there?

Golf Score: 484
_________________________
!

download KiXnet

Top
#69140 - 2002-08-18 07:20 PM Re: KiXtart Golf Tournament IV: Anagrams
Anonymous
Unregistered


Well I was hoping to get one over on Lonkero with 527,
but I wasn't fast enough!

Top
#69141 - 2002-08-18 07:35 PM Re: KiXtart Golf Tournament IV: Anagrams
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
good god!

you're getting really close and my code is hard to get even one stroke shorter!
_________________________
!

download KiXnet

Top
#69142 - 2002-08-18 08:25 PM Re: KiXtart Golf Tournament IV: Anagrams
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Okay folks, here's my preliminary score. It's for a working code without variable name reductions:

KiXtart Golf Score=1458
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 3 123>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org