#66592 - 2002-06-11 12:43 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Sealeopard
KiX Master
Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
|
Lonkero:
The code works for me. I tested the following script under Kixtart 4.10 RC2 and it correctly spits out KIXTART:
code:
? BaseConverter("44680832201","10","36")
exit 0
FUNCTION BaseConverter($v,$f,$t) $y = CDBL(1) $c = "" $n = 0 FOR $i = LEN($V) TO 1 STEP -1 $x = SUBSTR(UCASE($V),$i,1) IF ASC($x) > 57 $x = ASC($x) - 55 ENDIF $n = $y * $x + $n $y = $y * $f NEXT WHILE $N $a = INT($n - (INT($n/$t) * $t)) $n = ($n-$a)/$t IF $a > 9 $a = CHR($a + 55) ENDIF $c = "$a$c" LOOP $BaseConverter = $c ENDFUNCTION
[ 11 June 2002, 00:43: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
|
Top
|
|
|
|
#66594 - 2002-06-11 01:30 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
kholm
Korg Regular
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Nice Scripts everyone
I believe the trick in this KixGolf game is to force KiXtart to use 'big' numbers by forcing the var to be double instead of integer!
$number = $Number * CDbl(1)
Or Shawn's approach:
$number = 0. + $Number
Should we start a new Tricks-forum ? This one could also be in the FAQ section under typecasting.
The KixGolf games is a great idea, but could we have a summary of the new tricks by the submitter or the winner of the game ?
Shouldn't this lead up to a deeper understanding of the syntax in KiXtart (and hard testing of same) ?
Just a thougt about the scoring system: Shouldn't all variables be considered as one char, then $, $a and $array would all count as one char in the script, and the the scripts would be a lot more readable (and easyer to submit to the forum).
-Erik
|
Top
|
|
|
|
#66595 - 2002-06-11 01:34 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I've gotten it down to 252... .. still working on it.. going to play volleyball, though.
|
Top
|
|
|
|
#66596 - 2002-06-11 02:02 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
I promised to make one. here it is. haven't checked the kixgolf score, cause here is time 03AM and my laptops battery is dead.
anyways, proudly can say, that your scripts were too complex for me to understand, and as such, I could not adapt any of your code. neither can I yet try to improve yours because of that.
the udf: code:
function baseconverter($x,$f,$t)
if val($f)<>10 $y=1 $x=ucase($x) for $c=0 to len($x)-1 $d=0.+asc(substr($x,len($x)-$c,1)) if $d>64 $d=$d-55 else $d=$d-48 endif $d=$d*$y $e=$e+$d $y=0.+$y*$f next if val($t)=10 $x=$e goto "t" endif endif $z="" do $d="" $y=0 $e="" for $c=1 to len($x) $d=""+$d $d=val($d+substr($x,$c,1)) $y=$d/$t if $y $d=$d-$y*$t endif $e=$e+$y next if $d>9 $d=chr($d+55) endif $z=""+$d+$z $x=$e $e=val($e) until val($e)<$t and 5>len($e) if $e>9 $e=chr($e+55) endif $x="$e$z" :t $baseconverter=$x endfunction
one thing I wonder. when converting from 10base, the ticks return 10 and from kixtart(base36) to ten result is 0! is there a bug or is my script truly so fast?!?!? using kix4.10 rc2 with: code:
"starting the function..." $time=@ticks baseconverter("kixtart","36","10") $time=@ticks-$time ? $time get $ exit 0
cheers mates and good/night/day...
_________________________
!download KiXnet
|
Top
|
|
|
|
#66597 - 2002-06-11 03:27 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Brian, I also got your script down to 252.
|
Top
|
|
|
|
#66599 - 2002-06-11 03:59 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
code:
FUNCTION BaseConverter($v,$f,$t) $y = 1. $c = "" $n = 0
$i = LEN($V) Do $x = SUBSTR(UCASE($V),$i,1) IF $x > 9 $x = ASC($x) - 55 ENDIF $n = $y * $x + $n $y = $y * $f $i = $i -1 Until $i=0
WHILE $N $a = INT($n - (INT($n/$t) * $t)) $n = ($n-$a)/$t IF $a > 9 $a = CHR($a + 55) ENDIF $c = "$a$c" LOOP $BaseConverter = $c ENDFUNCTION ;! BaseConverter('Kixtart',36,10) ? BaseConverter('52',10,2) ? BaseConverter('Kixtart',36,10) ?
|
Top
|
|
|
|
#66601 - 2002-06-11 04:57 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Howard.. that looks like what I did.. I did something else, too, and got the same result. I couldn't simplify it any further, though, so I'm working on something else.. One thought I had was that the number could be converted to base 2 instead of base 10. I'm not sure it would save any effort, though. Also, I was seeing if there was a way I could shorten the conversion from ascii to a number... haven't found one, yet. (I came close.. still playing with it.)
Brian
|
Top
|
|
|
|
#66602 - 2002-06-11 04:57 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
My 1st program is wrong. It drops Zeroes.
|
Top
|
|
|
|
#66603 - 2002-06-11 05:28 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
KixGolf score = 243
code:
Function BaseConverter($v,$f,$t) $i = len($v) $b=1. $n=0 Do $ = substr($v,$i,1) if $ > 9 $ = ASC(ucase($)) - 55 endif $n=$b*$+$n $b=$b*$f $i=$i-1 Until $i=0
$c="" While $n $ = INT($n - (INT($n/$t) * $t)) $n = ($n-$)/$t IF $ > 9 $ = CHR($ + 55) ENDIF $c = "" + $ + $c Loop $BaseConverter = $c Endfunction
[ 11 June 2002, 05:57: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#66604 - 2002-06-11 05:33 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Oops! Drops zeros? hmm. so I guess that method doesn't work, eh? I'm still playing with it.. going to bed now, though.
Brian
|
Top
|
|
|
|
#66605 - 2002-06-11 05:35 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The string of characters does not include a zero so you can't do a substr to find a zero.
|
Top
|
|
|
|
#66606 - 2002-06-11 05:45 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I thought we weren't allowed to use $ as a variable? is that changed now?
Brian [ 11 June 2002, 05:53: Message edited by: BrianTX ]
|
Top
|
|
|
|
#66607 - 2002-06-11 05:48 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I was always under the impression we could. Jens, Help! Please clarify. Thanks.
|
Top
|
|
|
|
#66608 - 2002-06-11 05:52 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
$C is initialized to "" in the middle. I moved it closer to where it was being used. This code can be executed multiple times in a script returning the proper values each time. [ 11 June 2002, 05:54: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#66609 - 2002-06-11 05:54 AM
Re: Round 2: KiXtart Golf Tournament Part III
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Where is $n initialized? suppose you had a value $n already existing in a script?
Brian
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 239 anonymous users online.
|
|
|