DrillSergeantDrillSergeant
MM club member
Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Here's my 566. I think there's lots of room to improve so let's see if the collective can get it below 500 :-)
Code:
; begin KiXgolfUDF;;!FunctionCIF($a,$l)Dim$b,$c,$d,$f,$i,$j,$k,$n,$t[$a^0],$;$l=split($l,@crlf)for$i=0to79$f=$f+' '$d=$d+'-'nextforeach$iin$l$k=split($i,'&')for$j=1to$a^0$c=len($k[$j-1])if$c>$t[$j]$t[$j]=$cendifnextnextforeach$iin$lfor$j=1to$a^0$k=substr($a,$j,1)$c=instr($i+'&','&')$n=left($i,$c-1)$i=substr($i,$c+1)$c=$t[$j]$=$+'| '+iif($k='<',left($n+$f,$c),iif($k='>',right($f+$n,$c),left(left($f,($c-($n^))/2)+$n+$f,$c)))+' 'next$=$+'|'+@crlfif$b=0$b='@'+left($d,($^)-4)+'@'$=$b+@crlf+$+'|'for$k=1to$a^0$=$+left($d,$t[$k]+2)+'+'next$=left($,($^)-1)+'|'+@crlfendif$cif=$+$bEndFunction;!;!; end KiXgolfUDF
DrillSergeantDrillSergeant
MM club member
Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
Allen's 551
Replaced $c=ubound(split($p[0],"&")) by $c=($a^)-1
Code:
; begin KiXgolfUDF;;!functioncif($a,$p)dim$r,$c,$i,$,$d,$z$z=@crlf$p=split($p,$z)$r=ubound($p)$c=($a^)-1dim$y[$r,$c],$l[$c],$t[$c]for$i=0to$rfor$=0to$c$d=split($p[$i],"&")[$]$y[$i,$]=$dif($d^)>$l[$]$l[$]=0^$dendifnextnextfor$i=0to$rfor$=0to$c$p=substr($a,$+1,1)while($y[$i,$]^)<$l[$]$d=" "+$y[$i,$]+" "$y[$i,$]=iif($p=">",left($d,~),right($d,iif($p="=",$l[$],~)))loopwhile($t[$]^)< $l[$]+2$t[$]=$t[$]+"-"loopnextnext$p="@"+join($t,"-")+"@"$d=$p+$zfor$i=0to$rfor$=0to$c$d=$d+iif($i=1&$=0,"|"+join($t,"+")+"|"+$z,"")+"| "+$y[$i,$]+" "+iif($=$c,"|"+$z,"")$cif=$d+$pendfunction;!;!; end KiXgolfUDF
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Jeez, it's getting so a guy can't take his eye off the ball for a Christmas break without everyone rushing past!
My 586 (game interrupted for Turkey) looks like this:
; begin KiXgolfUDF ; ;! Function CIF($a, $y) Dim $,$s,$l,$e,$h,$q,$z,$c $l=Len($a)-1 Dim $w[$l] $c=@CRLF $y=Split($y,$c)
; ; LOOP 1 - pass through data and record longest entry in each column ; We also construct table top/botton/heading template as we go ; For Each $s in $y $h=@ For $=0 to $l $e=Len(Split($s,"&")[$]) If $w[$]<$e $w[$]=$e EndIf $h=Trim($h+" "+j($w[$],"<",@,"-")) Next Next
; ; LOOP 2 - Pass through data again, constructing table body ; For Each $s in $y $q=@ For $=0 to $l $q=$q+" | "+j($w[$],SubStr($a,$+1,1),Split($s,"&")[$]," ") ; Format data line Next $z=$z+"|"+SubStr($q,3)+" |"+$c +IIf($z=@,"|-"+Join(Split($h),"-+-")+"-|"+$c,@) ; IIf() the table is empty then this is the header line Next ; Add the header line to the top and bottom of the table $h="@-"+Join(Split($h),"---")+"-@" $CIF=$h+$c+$z+$h EndFunction
; Justification UDF ; $w=Width ; $t=Justification type ; $s=String to justify ; $c=Fill character ; Function j($w,$t,$s,$c) Dim $L,$R,$,$x If $t="<" $R=$c EndIf ; Left Justify If $t=">" $L=$c EndIf ; Right Justify If $t="=" $=$c EndIf ; Centre Justify, start on right while Len($s)<$w $s=$L+$j+$s+$R+$ $x=$ $=$j $j=$x ; Toggle centre justify RHS <-> LHS Loop $j=$s EndFunction ;! ;! ; end KiXgolfUDF ; vim:filetype=kix sw=4 ts=4
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ok, down to 560 - it's amazing what shortcuts you forget when you don't play for a while:
; begin KiXgolfUDF ; ;! Function CIF($a, $y) Dim $,$s,$l,$e,$h,$z,$c $l=($a^)-1 Dim $w[$l] $c=@CRLF $y=Split($y,$c)
; ; LOOP 1 - pass through data and record longest entry in each column ; We also construct table top/botton/heading template as we go ; For Each $s in $y $h=@ For $=0 to $l $e=0^Split($s,"&")[$] If $w[$]<$e $w[$]=$e EndIf $h=Trim($h+" "+j($w[$],"<",@,"-")) Next Next
; ; LOOP 2 - Pass through data again, constructing table body ; For Each $s in $y $e=@ For $=0 to $l $e=$e+" | "+j($w[$],SubStr($a,$+1,1),Split($s,"&")[$]," ") ; Format data line Next $z=$z+"|"+SubStr($e,3)+" |"+$c +IIf($z=@,"|-"+Join(Split($h),"-+-")+"-|"+$c,@) ; IIf() the table is empty then this is the header line Next ; Add the header line to the top and bottom of the table $h="@-"+Join(Split($h),"---")+"-@" $CIF=$h+$c+$z+$h EndFunction
; Justification UDF ; $w=Width ; $t=Justification type ; $s=String to justify ; $c=Fill character ; Function j($w,$t,$s,$c) Dim $,$x If $t="=" $=$c EndIf ; Centre Justify, start on right while ($s^)<$w $s=Left($c,$t=">")+$j+$s+Left($c,$t="<")+$ $x=$ $=$j $j=$x ; Toggle centre justify RHS <-> LHS Loop $j=$s EndFunction ;! ;! ; end KiXgolfUDF ; vim:filetype=kix sw=4 ts=4
Hey Rich... just wanted to make sure you saw Drill's 549 of my code... I just posted the 562 because it made me feel better to know he could miss easy ones too.
Interesting... 4 players... mostly different approaches.