#164782 - 2006-07-22 02:11 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
This is the submission from Richard Mallesch (it_took_my_meds), which I am posting on his behalf: Code:
Function m($a) $l=0,5,2,1,0 $v="|",":",".","-" $n = 1 If AScan($v,Left($a,1))=-1 Do $ = $a Mod ($n*20) $a = $a - $ $ = $ / $n $n = $n * 20 If $ For $q = 1 to 3 While $ / $l[$q] $m=$v[$q-1]+$m $=$-$l[$q] Loop Next Else $m="-"+$m EndIf $m=" "+$m Until $a=0 $m=Trim($m) Else $a = " "+$a While $a $c=Right($a,1) $=IIf($c=" ",-$,$+$l[AScan($v,$c)+1]) $a=Left($a,~) If $<0 Or $c="-" $m = $m - $n * $ $n = $n * 20 $=0 ;EndIf ;Next ;EndIf EndFunction
Note: The code does not pass the validation as the variables inside the UDF are not declared despite "$iRC=SETOPTION('Explicit','on')" defined in kixgolf_mnc.kix
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#164783 - 2006-07-22 02:12 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
krabourn
Hey THIS is FUN
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Only fitting that the highest scrore be posted first. HAHAHA!!!
Code:
FUNCTION m($) DIM $a[6], $b, $i, $j, $t, $s, $u IF InStr(".:|-", SubStr($, 1, 1)) $a = Split($) $u = UBound($a) FOR $i = 0 TO $u $t = 0 FOR $j = 1 TO Len($a[$i]) $b = SubStr($a[$i], $j, 1) $t = $t + IIf($b = ".", 1, IIf($b = ":", 2, IIf($b = "|", 5, 0))) NEXT $s = 1 IF $u - $i $s = 20 FOR $j = 1 TO $u - $i - 1 $s = $s * 20 NEXT ENDIF $m = $m + $s * $t NEXT ELSE DO IF $ > 19 $s = 1 FOR $i = 1 TO 6 $s = $s * 20 IF $s < $ $j = $i $t = $s ENDIF NEXT IF $ > 19 FOR $i = 1 TO 20 $s = $t $s = $s * $i IF $s <= $ $a[$j] = $i ENDIF NEXT ELSE $t = $ ENDIF $ = $ - ($t * $a[$j]) ELSE $a[0] = $ $ = $ - $ ENDIF UNTIL $ < 1 FOR $i = 6 TO 0 STEP -1 IF $a[$i] = "" AND $i REDIM PRESERVE $a[$i - 1] ELSE $i = -1 ENDIF NEXT FOR EACH $ IN $a DO $m = IIf($ > 4, "|", IIf($ > 1, ":", IIf($, ".", "-"))) + $m $ = $ - IIf($ > 4, 5, IIf($ > 1, 2, IIf($, 1, 0))) UNTIL $ < 1 $m = " " + $m NEXT $m = Trim($m) ENDIF ENDFUNCTION
Oop! Guess I was not fast enough.
Edited by krabourn (2006-07-22 02:16 PM)
|
Top
|
|
|
|
#164784 - 2006-07-22 02:19 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
Right,
here's my 352 still with vartype()
Code:
function m($) dim $a, $b, $c, $p $a = split('- . : .: :: | .| :| .:| ::| || .|| :|| .:|| ::|| ||| .||| :||| .:||| ::|||') $p = 64000000, 3200000, 160000, 8000, 400, 20, 1 if vartype($) = 3 for $b = 0 to 6 $c = $p[$b] $m = iif($ >= $c, trim($m + ' ' + $a[$/$c]), iif($m, $m + " -", $m)) $ = $ - $/$c * $c next $m = iif($m, $m, '-') else $c = split($) $ = ubound($c) for $b = 0 to $ $m = $p[6-$+$b] * ascan($a,$c[$b]) + $m ;next ;endif endfunction
[edit] in the make I had a helper udf for power of 20, as well as a programmatic building of the mayan string; Something like this: $m = $m + left('.',( $} - $}/5) mod 2 ) + left('::',( $}-5*($}/5))/2) + left('|||',$}/5) + ' ' (where $} = $/${ , and ${ = p(6-$e) in a for 0 to 6) which was of course too long. That said, have a very nice weekend gentlemen, see you on monday [/edit]
Edited by Jochen (2006-07-22 02:27 PM)
_________________________
|
Top
|
|
|
|
#164787 - 2006-07-22 02:38 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Here is my 448, the additional UDF 'x($)'is the power calculator and both UDF's were placed between ;!,... ;! so that it was included in the count calc:
Code:
Function m($i) Dim $a,$b,$c,$,$p If VarType($i)=8 $i=Split($i) For $c = UBound($i) to 0 Step-1 $=0 For $b = 1 to Len($i[$c]) $a=SubStr($i[$c],$b,1) $=$+($a=".") $=$+($a=":")*2 $=$+($a="|")*5 Next $m=$m+$*x($p) $p=$p+1 Next Else $p=1 Do $b=$i-$i/x($p)*x($p) $=$b/x($p-1) If $=0 $m="-"+$m Else For $c=1 to $/5 $m="|"+$m $=$-5 Next For $c=1 to $/2 $m=":"+$m $=$-2 Next If $=1 $m="."+$m $=$-1 EndIf EndIf $i=$i-$b $p=$p+1 If $i>0 $m=" "+$m EndIf Until $i=0 EndFunction
Function x($) Dim $y $x=1 For $y = 1 to $ $x=$x*20 EndFunction
|
Top
|
|
|
|
#164788 - 2006-07-22 03:16 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Here's my code for a score of 225
Code:
Function m($) dim $c,$d,$f $f = '- . : .: :: | ' $f = split($f+$f+$f) for $c=6 to 19 $f[$c]=$f[$c-5]+'|' next if $+-$=0 do $m = trim($f[$ mod 20] + ' ' + $m) $ = $/20 until $=0 else $ = split($) for $d = -ubound($) to 0 $m = $m + $c/20 * ascan($f,$[-$d]) $c=$c*20 ;next ;endif EndFunction
|
Top
|
|
|
|
#164789 - 2006-07-22 03:45 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
My god Eric - our code is almost identical:
My 213 is:
Code:
Function m($)
dim $a,$b,$c
for $b = 1 to 15 $c = split("- . : .: :: | " + $a) $a = $a + $c[$b] + "| " next
if $+0=$ $m = $c[$ mod 20] if $/20 $m = m($/20) + " " + $m endif else $ = split($) $b = 1 for $a = -ubound($) to 0 $m = $m + $b * ascan($c,$[-$a]) $b = $b * 20 ;next ;endif
EndFunction
This is my new public coding submission for a score of 185
Code:
Function m($)
dim $a,$b,$c
for $b = 1 to 15 $c = split("- . : .: :: | " + $a) $a = $a + $c[$b] + "| " next
if $+0=$ $m = $c[$ mod 20] if $/20 $m = m($/20) + " " + $m endif else for each $ in split($) $m = $m * 20 + ascan($c,$) ;next ;endif
EndFunction
By the way - I am officially protesting Jooels submission of 182. Jens - your going to have to verify it - none of us have time to do it - and if he does win - I figure the public golfing of it would take - like - 100 years !
|
Top
|
|
|
|
#164790 - 2006-07-22 03:59 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
285... Code:
; begin Mayan Number Converter ; ;! Function m($) dim $a,$b,$c,$p if $=$+0 do $b = $ mod 20 $=($-$b)/20
if $b $a=5,2,1 for each $p in $a while $b/$p>0 $m=substr(".:zz|",$p,1)+$m $b=$b-$p loop next else $m="-"+$m endif $m=" "+$m until $=0 $m=ltrim($m) else $c=1 for $a=len($) to 1 step -1 $b=substr($,$a,1)
if $b=" " $c=$c*20 endif $m=$c*instr(".:zz|",$b)+$m
EndFunction ;! ;! ; end Mayan Number Converter
|
Top
|
|
|
|
#164791 - 2006-07-22 04:23 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
Top
|
|
|
|
#164792 - 2006-07-22 04:24 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This latest challenge was probably more interesting and fun that most of those we've had recently as it lends itself to many different paths to the solution.
I've discovered a few new techniques and tricks that surprised me, world weary old cynic that I am.
Anyhoo, here it is. Not the shortest, but a thing of chiaroscuric beauty none-the-less (in the authors humble opinion )
Code:
; begin Mayan Number Converter ; ;! Function m($n) Dim $,$c If $n=Val($n) Do $=$n mod 20 $n=$n/20 Do $c=($>4)*3+IIf($>1,2,$) $=$-$c $m=SubStr("-.:xx|",$c+1,1)+$m Until $=0 $m=" "+$m Until $n=0 Else For Each $ in Split($n) $m=$m*20 While $ $m=$m+InStr(".:xx|",Left($,1)) $=SubStr($,2) Loop Next EndIf $m=Trim($m) EndFunction ;! ;! ; end Mayan Number Converter ; vim600:filetype=kix ai sw=4 ts=4
|
Top
|
|
|
|
#164793 - 2006-07-22 04:35 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Richard, I see we think alike.
|
Top
|
|
|
|
#164794 - 2006-07-22 04:38 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
256
Code:
Function m($) dim $y,$r,$c $y=split("- . : .: :: | .| :| .:| ::| || .|| :|| .:|| ::|| ||| .||| :||| .:||| ::|||") if $+0=$ do $r=$ mod 20 $m=" "+$y[$r]+$m $=$/20 until $=0 $m=trim($m) else $c=split($) $=ubound($c) $r=1 while $>=0 $m=$m+ascan($y,$c[$])*$r $=$-1 $r=$r*20 ; loop ; endif EndFunction
|
Top
|
|
|
|
#164795 - 2006-07-22 04:42 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Code:
for $b = 1 to 15 $c = split("- . : .: :: | " + $a) $a = $a + $c[$b] + "| " next
Shawn... so simple...yet... I spent hours and never thought of that...
|
Top
|
|
|
|
#164797 - 2006-07-22 04:47 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
Here's some golf tips for the public round - assuming your going to maybe start with the 185 code:
1) The best opportunity for removing strokes (imho) is here:
Code:
for $b = 1 to 15 $c = split("- . : .: :: | " + $a) $a = $a + $c[$b] + "| " next
If anyone can find a shorter way to build a mayan character table - it will be gold.
The other place is here:
Code:
if $+0=$
If anyone can find a shorter numeric check or b) find a similar or shorter way to test for STRING instead. If you can find a string check - then one should be able to flip the code blocks around - probably saving a single stroke on the commented-out nexts and endif's
One word of caution - this here:
Code:
$m = m($/20) + " " + $m
is a recursive call - so things like IIF() will not work. IIF expressions always get evalulated so using them can cause an endless recurse. Of course - thats just been my experience ;o)
-Shawn
|
Top
|
|
|
|
#164798 - 2006-07-22 04:55 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
More about that table ...
Code:
for $b = 1 to 15 $c = split("- . : .: :: | " + $a) $a = $a + $c[$b] + "| " next
If one is able to bring the number of $vars down from 3 to 2 - and still keep the same number of strokes - then one should be able to remove the DIM of the $var - and save like three strokes !
I've been staring at this table for days - with zero luck.
For reference - here is the absolute max way of defining the table:
$c = split("- . : .: :: | .| :| .:| ::| || .|| :|| .:|| ::|| ||| .||| :||| .:||| ::|||")
|
Top
|
|
|
|
#164799 - 2006-07-22 04:56 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
Richard, I see we think alike.
You're not fooling me, I know that you are just another voice in my head and I am the real Howie
Shhhhh! Hush my brother, they are ever listening...
|
Top
|
|
|
|
#164800 - 2006-07-22 05:02 PM
Re: KiXgolf: Mayan Number Converter - Public Phase
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Why does the following work? Maybe I stayed up too late night and just can't think straight, but why isn't "$" redefined and fail on the next iteration.
Code:
for each $ in split($)
Code:
$="1 2 3 4 5" ? Vartypename($) ? $ for each $ in split($) ? $ ? Vartypename($) next ? Vartypename($) ? "$$="+$ The original value of "$" is set to Empty after the loop.
Edited by Howard Bullock (2006-07-22 05:16 PM)
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(mole)
and 405 anonymous users online.
|
|
|