#191344 - 2008-12-20 02:02 PM
Re: KiXgolf - A Well-Formed Problem - Public Round
[Re: Sealeopard]
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
KiXtart KiXtart Version = 4.53 KiXGolf Script = kixgolf_wfp.kix
Computer OS = Windows XP Professional CPU = Intel Pentium Model 15 Speed = 2131 MHz Memory = 1526 MB
KiXGolf Scoring Engine Scoring Engine = 3.3
KiXtart Golf Score Tournament = A Well-Formed Problem Processing Start = 2008/12/20 15:00:45.171 Processing End = 2008/12/20 15:00:45.390 Duration = 0000/00/00 00:00:00.218 KiXGolf Score = 639
Function WFP($)
dim $e,$p,$s,$k,$i,$_
$k="well-formed"
$s="non "+$k
$wfp=$s
$ = open(1,".\"+$)
do
$=readline(1)
$_=$_+$
until @error
$=split($_,'<?xml version="1.0"?>')
if 1=ubound($)+close(1)
$wfp=$k
for each $ in split($[1],"<")
$_=split(split($,">")[0])
dim $a
for $p=0 to ubound($_)
$k=split($_[$p],'="')[0]
for $i=1 to $k^0
$=asc(ucase(substr($k,$i)))
if 0=(($>64 & $<91) | ($>47 & $<58) | $=45 | 47=asc($k) | $p=0 & $i=($k^) & $=47) | instr($a,\+$k+\) | $p & 0=instr('/"',right($_[$p],1))
$wfp=$s
endif
next
if $p
$a=$a+\+$k+\
else
$=$_[0]
$i=47=asc($)
if $
$=\+substr($,1+$i)+\
if right(join($_),1)<>"/" | $e=$ | $e=""
$e=$e+$
$k=split($e,$)
if $i | $e=$+$
$=$k[0]
$e=$
if 0= ($ | $i) * ($k[1] + ubound($k) = 2)
$wfp=$s
EndFunction
_________________________
!download KiXnet
|
Top
|
|
|
|
#191351 - 2008-12-20 06:31 PM
Re: KiXgolf - A Well-Formed Problem - Public Round
[Re: Lonkero]
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
And here is my code that I did not get finished. I had though about using a COM call, but was unsure where to look and never followed through with the thought.
; begin KiXgolfUDF
;
;!
Function WFP($w)
Dim $L,$I[0],$C,$T,$Y[],$Z,$,$U[]
$wfp = "well-formed"
Open(6,$w)
$L = Readline(6)
While @Error = 0
$I[$C] = $L
$C = $C + 1
Redim Preserve $I[$C]
$L = Readline(6)
Loop
close(6)
If $I[0] <> '<?xml version="1.0"?>'
$T = 1
EndIf
For $C = 1 to Ubound($I)
For $ = 1 to $I[$c] + 1 ^ 0
If SubStr($I[$C],$,1) = "<"
$L = $
While Substr($I[$C],$,1) <> ">"
$ = $ + 1
Loop
Redim Preserve $Y[$Z]
$Y[$Z] = Substr($I[$C],$L,($ +1) - $L)
$Z = $Z + 1
EndIf
Next
Next
For $C = 0 to Ubound($Y)
If left($Y[$C],2) <> "</" AND Left($Y[$C],2) <> 0
$ = Left(Substr($Y[$C],2),-1)
$L = Ascan($Y,"</" + $ + ">",$C)
If Ascan($Y,"<"+$+">",($C + 1)) < $L And Ascan($Y,"<"+$+">",($C + 1)) > -1
$T = $T | 1
EndIf
If Instr($," ")
If Instr($,"=")
$U = Split($,"=")
If left($U[1],1) = CHR(34) AND INSTRREV($U[1],CHR(34)) > 1
$ = Split($U[0])[0]
Else
$T = $T | 1
EndIf
EndIf
EndIf
For $Z = 0 to Len($) -1
Redim Preserve $U[$Z]
$U[$Z] = Substr($,$Z +1,1)
Next
For each $L in $U
$L = ASC($L)
If $L > 44 AND $L < 58 OR $L > 64 AND $L < 91 OR $L > 96 and $L < 123
Else
$T = $T | 1
EndIF
Next
$L = Ascan($Y,"</" + $ + ">",$C)
If $L > -1
$y[$c] = 0
$y[$L] = 0
Else
$L = Ascan($Y,"<" + Left($,-1) + "/>")
If $L > -1
$y[$L] = 0
Else
$T = $T | 1
EndIf
EndIf
EndIf
Next
If Instr(Join($y),"<")
$T = $T | 1
EndIf
If $T <> 0
$wFP = "non " + $wFP
EndFunction
;!
;!
; end KiXgolfUDF
Edited by Gargoyle (2008-12-20 06:34 PM) Edit Reason: didn't like the html post
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
#191360 - 2008-12-21 05:27 PM
Re: KiXgolf - A Well-Formed Problem - Public Round
[Re: Lonkero]
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Here is my fully bloated code. This has my thought process in it and the debugging that I was doing. For those that want to tell me how I could have approached different challenges I am welcome to comments.
; begin KiXgolfUDF
;
;!
Function WFP($)
Dim $LineIn,$InitialArray[0],$Counter,$TestResult,$TempArray[0],$Counter2,$Temp,$Temp2,$Tag,$Temp3[],$Start,$Letter,$Match
$Counter = 0
$Counter2 = 0
;Start by Breaking up the Initial File into an array to manage the contents
Open(1,$)
;;======Debug Here=========
Open (2,"ArrayOutput.txt",5)
WriteLine(2,"File Name = " + $ + @CRLF)
;;
$LineIn = Readline(1)
While @Error = 0
$InitialArray[$Counter] = Trim($LineIn)
$Counter = $Counter + 1
Redim Preserve $InitialArray[$counter]
$LineIn = Readline(1)
Loop
Close(1)
;;;===========Debug Here ===============
;For $counter = 0 to Ubound($InitialArray)
;
; Writeline(2, "Element " + $counter + " = " + $InitialArray[$Counter] + @CRLF)
;
;Next
;;;
;Look to see if the version tag is there
If $InitialArray[0] = '<?xml version="1.0"?>'
$TestResult = 0
Else
$TestResult = 1
EndIf
$InitialArray[0] = "" ;Clear the data so we can safely ignore it later
;;==============Debug Here ===============
Writeline(2, "Version tag test = " + $Testresult + @CRLF)
;;
;Parse out the Open and Close Tags
;Look at the Input string from the initial array and find the first <
For $Counter = 1 to Ubound($InitialArray)
;break out the string to look for multiple tags on a single line
For $Temp = 1 to Len($InitialArray[$Counter])
If SubStr($InitialArray[$counter],$Temp,1) = "<"
$Start = $Temp
While Substr($InitialArray[$Counter],$Temp,1) <> ">"
$Temp = $Temp + 1
Loop
Redim Preserve $TempArray[$Counter2]
$TempArray[$Counter2] = Substr($InitialArray[$Counter],$Start,($Temp +1) - $Start)
$Counter2 = $Counter2 + 1
EndIf
Next
Next
;;Debug Code
For $counter = 0 to Ubound($TempArray)
Writeline(2, "Element " + $counter + " = " + $TempArray[$Counter] + @CRLF)
Next
;Are there matching open and close tags
For $Counter = 0 to Ubound($TempArray)
;Find an Open Tag
If left($TempArray[$Counter],2) <> "</" AND left($TempArray[$Counter],2) <> 0
;Now we validate all the different conditions
;To Get it working in the most basic form
$Temp = Left(Substr($TempArray[$Counter],2),-1) ;This will give us the non tag characters to use for comparison
WriteLine(2,"Line that we are checking = " + $Temp +@CRLF) ;Debugging
;Check for same name tags within each other
$Temp2 = Ascan($Temparray,"</" + $Temp + ">",$Counter)
WriteLine(2,"value of tag in a tag = " +$Temp2+@crlf) ; debuggin
If Ascan($Temparray,"<"+$Temp+">",($counter + 1)) < $Temp2 And Ascan($Temparray,"<"+$Temp+">",($counter + 1)) > -1
$Tag = Ascan($Temparray,"<"+$Temp+">",($counter + 1))
WriteLine(2,"We found a value of "+$Tag+" less than the next close"+@crlf) ;debuggin
$TestResult = $TestResult | 1
EndIf
;Now we have to test to see if this is an attibute
If Instr($Temp," ")
If Instr($Temp,"=")
$Temp3 = Split($Temp,"=")
Writeline(2,"This is an Attribute, The Value after the = is " +$Temp3[1] +@CRLF) ;Debuggin
;Writeline(2,"This is the first value we are checking " + left($Temp3[1],1) + "and this is the second value " + Right($Temp3[1],1) + @CRLF) ; Debuggin
Writeline(2,"This is the first value we are checking " + left($Temp3[1],1) + "and this is the second value " + InstrRev($Temp3[1],CHR(34)) + @CRLF)
;If left($Temp3[1],1) = CHR(34) and Right($Temp3[1],1) = CHR(34)
;;;This is the new LINE to be PUT into the stipped code
If Left($Temp3[1],1) = CHR(34) and InstrRev($Temp3[1],CHR(34)) > 1
WriteLine(2,"The attribute test Passed" + @CRLF) ;Debuggin
;Have to rewrite the value of $Temp to remove attibute fields
$Temp = Split($Temp3[0])[0]
Writeline(2,"New value of $Temp = " + $Temp + @CRLF)
$TestResult = $TestResult | 0
Else
$TestResult = $TestResult | 1
EndIf
EndIf
EndIf
;Check for invalid characters in the string
For $Counter2 = 0 to Len($Temp) -1
Redim Preserve $Temp3[$Counter2]
$Temp3[$Counter2] = Substr($Temp,$Counter2 +1,1)
Next
For each $Letter in $Temp3
Select
Case asc($Letter) = 45
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($Letter) > 46 AND asc($letter) < 58
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) > 64 AND asc($letter) < 91
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) > 96 and asc($letter) < 123
Writeline(2,"Valid Character of " +$Letter+@CRLF); debuggin
Case asc($letter) = 32
Case 1
Writeline(2,"inValid Character of " +$Letter+@CRLF); debuggin
$TestResult = $TestResult | 1
EndSelect
Next
;Finally is there corresponding open and close tags
$Temp2 = Ascan($TempArray,"</"+ $Temp + ">",$Counter)
If $Temp2 > -1
$TempArray[$Counter] = 0
WriteLine(2,"Found a proper Close tag. Clearing the element: "+$counter+@CRLF)
$TempArray[$Temp2] = 0
WriteLine(2,"And The closing tag is element: "+$Temp2+@CRLF)
Else
$Temp2 = Ascan($TempArray,"<" + Left($Temp,-1) + "/>")
If $Temp2 > -1
$TempArray[$Temp2] = 0
Writeline(2,"Found the 'orders/' tag. Clearing element: "+$Temp2+@CRLF)
Else
$TestResult = $TestResult | 1
Writeline(2,"Failue on open and close tags"+@CRLF)
EndIf
EndIf
; If Ascan($TempArray,"</" + $Temp + ">",$Counter) > -1 OR Ascan($TempArray,"<" + Left($Temp,-1) + "/>") > -1
;
; $TestResult = $TestResult | 0
; Else
; $TestResult = $Testresult | 1
; EndIf
EndIf
Next
If Instr(Join($TempArray),"<")
$TestResult = $TestResult | 1
EndIf
Writeline(2,Join($TempArray)+@CRLF)
If $TestResult = 0
$WFP = "well-formed"
Else
$WFP = "non well-formed"
EndIf
;;================= Debug Here ==============
Close(2)
;;
EndFunction
;!
;!
; end KiXgolfUDF
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
#191379 - 2008-12-22 03:34 PM
Re: KiXgolf - A Well-Formed Problem - Public Round
[Re: Lonkero]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
230
Your solution passed all tests
KiXtart
KiXtart Version = 4.60
KiXGolf Script = kixgolf_wfp.kix
Computer
OS = Windows Vista Business Edition
CPU = Intel(R) Pentium(R) D CPU 3.20GHz
Speed = 3200 MHz
Memory = 2046 MB
KiXGolf Scoring Engine
Scoring Engine = 3.3
KiXtart Golf Score
Tournament = A Well-Formed Problem
Processing Start = 2008/12/22 08:33:06.788
Processing End = 2008/12/22 08:33:06.929
Duration = 0000/00/00 00:00:00.140
KiXGolf Score = 230
Thank you for participating in KiXtart Golf!
Press any key to continue...
Function WFP($c)
Dim $
$ = CreateObject(Microsoft.XMLDOM)
$wfp = IIf($.load($c) + Val($.firstChild.nodetype), w, 'non w') + 'ell-formed'
For Each $ in $.getElementsByTagName('*')
For Each $c in $.childnodes
If $ .tagname = $c.tagname
$wfp = 'non ' + $wfp
EndFunction
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 366 anonymous users online.
|
|
|