Page 1 of 2 12>
Topic Options
#134353 - 2005-02-23 12:15 AM KiXgolf: Balanced Ternary Addition - Public Coding
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Private coding is now closed.

The winner of the private coding session is Finnish maven Jooel with 209 strokes closely followed by our Candian friend Shawn with 220 strokes.

Please post your codes here and hack away at the other's codes.
_________________________
There are two types of vessels, submarines and targets.

Top
#134354 - 2005-02-23 12:17 AM Re: KiXgolf: Balanced Ternary Addition - Public Coding
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Saving best for last...

Score = 279
Code:

Function BTA($a,$b)
dim $x,$,$s,$y
$b = $a,$b,0
while $b[0] + $b[1]
$s=3
for $a=0 to 2
$y = $b[$a]
$x= right($y,2)
$b[$a]=left($y,len($y)-1-($x<0))
$s = $s + $x mod 2
next
$a=0,1,-1,0,1,-1,0,-1,-1,0,0,0,1,1
$ = "" + $a[$s] + $
$b[2] = $a[$s+7]
loop

$ = "0" + $b[2] + $
do
$ = substr($,2)
until left($,1)<>0 or len($)<2
$BTA=$
EndFunction

_________________________
Eric

Top
#134355 - 2005-02-23 09:50 AM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Code:

KiXtart
KiXtart Version = 4.23
KiXGolf Script = kixgolf_bta.kix

Computer
OS = Windows XP Home Edition
CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz
Speed = 2793 MHz
Memory = 512 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Balanced Terniary Addition
Processing Start = 2005/02/23 10:40:50.515
Processing End = 2005/02/23 10:41:27.437
Duration = 0000/00/00 00:00:36.921
# Tests Run = 106
# Tests Passed = 106
# Tests Failed = 0
Result = passed
KiXGolf Score = 209

Thank you for participating in KiXtart Golf!


Code:

; begin Balanced Terniary Additions
;!
Function BTA($b,$c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$x=bta($x,0)
else
$c=729
while $c
$=1-2*($b<0)
$=$*($*2*$b>$c)
$b=$b-$*$c
if $x | $ | $c=1 $x=$x+""+$ endif
$c=$c/3
loop
endif
$bta=$x
EndFunction
;!
;!
; end Balanced Terniary Additions

_________________________
!

download KiXnet

Top
#134356 - 2005-02-23 09:57 AM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the code where I properly calculated everything, 241 (speed, speed...):
Code:

Function BTA($b,$)
dim $c
if $
$c=bta($b,0)+bta($,0)
$=729
while $
$b=1-2*($c<0)
$b=$b*($b*2*$c>$)
$c=$c-$b*$
if $bta | $b | $=1 $bta=$bta+""+$b endif
$=$/3
loop
else
$=1
while $b
$c=0>right($b,2)
$bta=$bta-2*$*$c+$*right($b,1)
$b=left($b,-1-$c)
$=$*3
loop
endif
EndFunction



Edited by Jooel (2005-02-23 10:36 AM)
_________________________
!

download KiXnet

Top
#134357 - 2005-02-23 11:06 AM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Code:

function bta($a, $b)

dim $,$i,$m,$t

$a = $a+#+$b ; delim operands with #

$b = 1

for $i = 1 to len($a)

$t = left(right($a,$i),1)

if $t = "-" ; was n minus?

$ = $ - $m * 2 ; subtract last $m (*2 because we already added it previous)

else

$m = $b * $t ; multiply base x num (the # in stream has no effect)

$ = $ + $m ; accumulate n

$b = iif($t=#,1,$b*3) ; next base or reset to 1 on delim

endif

next

do

$b = $ mod 3

if $b/2 ; ternary 2 ?

$b = $b/-2 ; change 2 to -1 and -2 to 1

$ = $ - $b ; carry forward

endif

$bta = "" + $b + $bta ; answer (coerce b to string with "")

$ = $ / 3 ; next base

until $=0 ; done?

endfunction



Top
#134358 - 2005-02-23 11:44 AM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, shawn.
you had the way I had my second code that didn't cut under 280.
instead of converting to decimal, go calcing with the provided math.
_________________________
!

download KiXnet

Top
#134359 - 2005-02-23 12:02 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no, not really.
now as I read it, you actually do calculating with base conversions.
_________________________
!

download KiXnet

Top
#134360 - 2005-02-23 12:17 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Code:
KiXtart
KiXtart Version = 4.23
KiXGolf Script = kixgolf_bta.kix

Computer
OS = Windows XP Home Edition
CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz
Speed = 2793 MHz
Memory = 512 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Balanced Terniary Addition
Processing Start = 2005/02/23 13:08:30.437
Processing End = 2005/02/23 13:08:55.125
Duration = 0000/00/00 00:00:24.688
# Tests Run = 106
# Tests Passed = 106
# Tests Failed = 0
Result = passed
KiXGolf Score = 180
Thank you for participating in KiXtart Golf!


Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$ = $b mod 3
if $/2 ; ternary 2 ?
$ = $/-2 ; change 2 to -1 and -2 to 1
$b = $b - $ ; carry forward
endif
$bta = "" + $ + $bta ; answer (coerce b to string with "")
$b = $b / 3 ; next base
until $b=0 ; done?
endif
endfunction

_________________________
!

download KiXnet

Top
#134361 - 2005-02-23 02:51 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
you clever basta!
Top
#134362 - 2005-02-23 03:11 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
177
Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$ = $b mod 3
$c = $/-2
$ = $ + 3*$c
$bta = "" + $ + $bta
$b = ($b-$c) / 3
until $b=0
endif
endfunction

_________________________
!

download KiXnet

Top
#134363 - 2005-02-23 03:28 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Code:
KiXtart
KiXtart Version = 4.23
KiXGolf Script = kixgolf_bta.kix

Computer
OS = Windows XP Home Edition
CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz
Speed = 2793 MHz
Memory = 512 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Balanced Terniary Addition
Processing Start = 2005/02/23 16:17:20.218
Processing End = 2005/02/23 16:17:49.625
Duration = 0000/00/00 00:00:29.406
# Tests Run = 106
# Tests Passed = 106
# Tests Failed = 0
Result = passed
KiXGolf Score = 176

Thank you for participating in KiXtart Golf!


Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$c = $b mod 3
$ = $c/-2
$bta = "" + ($c + 3*$) + $bta
$b = ($b-$) / 3
until $b=0
endif
endfunction

_________________________
!

download KiXnet

Top
#134364 - 2005-02-23 05:17 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
175
Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$ = $b mod 3
$c = $/2
$bta = "" + ($ - 3*$c) + $bta
$b = ($b+$c) / 3
until $b=0
endif
endfunction

_________________________
!

download KiXnet

Top
#134365 - 2005-02-23 05:20 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Code:

KiXtart
KiXtart Version = 4.23
KiXGolf Script = kixgolf_bta.kix

Computer
OS = Windows XP Home Edition
CPU = Intel(R) Pentium(R) 4 CPU 2.80GHz
Speed = 2793 MHz
Memory = 512 MB

KiXGolf Scoring Engine
Scoring Engine = 3.0.3

KiXtart Golf Score
Tournament = KiXtart Golf: Balanced Terniary Addition
Processing Start = 2005/02/23 18:10:47.390
Processing End = 2005/02/23 18:11:16.531
Duration = 0000/00/00 00:00:29.141
# Tests Run = 106
# Tests Passed = 106
# Tests Failed = 0
Result = passed
KiXGolf Score = 171

Thank you for participating in KiXtart Golf!


Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$ = $b mod 3
$bta = "" + ($ - $/2*3) + $bta
$b = ($b+$/2) / 3
until $b=0
endif
endfunction

_________________________
!

download KiXnet

Top
#134366 - 2005-02-23 11:29 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Pfew,

compliments on the script Jooel; took me a while to understand.

Tried to take off some strokes, but wasn't successfull yet...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#134367 - 2005-02-24 03:23 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
it looks like there is a bug in kix... hmm... looking into it...

if I "fix" the line:
$ = $b mod 3

to say:
$=$b mod 3

the code dies silently...
afaik, the code remains the same, thus it's definitely a bug.
_________________________
!

download KiXnet

Top
#134368 - 2005-02-24 04:33 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
you using the 4.50 alpha or the new beta ?
Top
#134369 - 2005-02-24 05:09 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
4.23 gold.
haven't seen no alpha nor beta fall into my mailbox.
_________________________
!

download KiXnet

Top
#134370 - 2005-02-24 07:33 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you trying to say that it does not die silently for you?

me using 4.23 wkix32.exe
_________________________
!

download KiXnet

Top
#134371 - 2005-02-24 07:41 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
This contest has already given me enough silent deaths - don't need to be bringing any more upon myself ;0)
Top
#134372 - 2005-02-25 01:09 PM Re: KiXgolf: Balanced Ternary Addition - Public Coding
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
today, it works fine again
Code:

function bta($b, $c)
dim $,$x
if $c
for $=-729 to -$
$x=$x+$*($b=bta($,0))+$*($c=bta($,0))
next
$bta=bta($x,0)
else
do
$=$b mod 3
$bta=""+($-$/2*3)+$bta
$b=($b+$/2)/3
until $b=0
endif
endfunction

_________________________
!

download KiXnet

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.244 seconds in which 0.211 seconds were spent on a total of 12 queries. Zlib compression enabled.

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