Page 1 of 2 12>
Topic Options
#191564 - 2009-01-03 02:18 PM KiXgolf: Latin Squares - public round
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
The public round of KiXgolf: Latin Squares is now open. The corresponding private round can be found at http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=191435 . Please post your code and start the improvements.
_________________________
There are two types of vessels, submarines and targets.

Top
#191565 - 2009-01-03 05:56 PM Re: KiXgolf: Latin Squares - public round [Re: Sealeopard]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
well, here's my code. I wonder if it's the same approach as all the others \:\/

it's a score of 404 instead of 405 because I changed a "" to @, but since it didn't influence the ranking in this round I forgot to post it in the private round.

Well Jooel, your turn to pull this one through the Lonkenizer(tm) \:D

 Code:
; begin KiXgolfUDF
;
;!
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $i = 0 to 3
		For $ = 0 to 3
			$k = iif($i<2,iif($<2,0,1),iif($<2,2,3))
			
			$t = $o[$i,$]
			$r[$] = $r[$] + $t
			$c[$i] = $c[$i] + $t
			$q[$k] = $q[$k] + $t

			$s[$i, $, $x] = $t
		Next
	Next

	if instr(join($r),x)=0
		exit
	endif
	
	For $i = 0 to 3
		For $ = 0 to 3
				$k=@
				for $t = 1 to 4
					if instr($c[$i]+$r[$]+$q[iif($i<2,iif($<2,0,1),iif($<2,2,3))],$t)=0 & $o[$i,$]=x
						$k=$k+$t
					endif
				next

				if ($k^)=1
					$o[$i,$]=$k
					$i=3 $=3
EndFunction
;!
;!
; end KiXgolfUDF



 Code:
Your solution passed all tests

KiXtart
KiXtart Version  = 4.60
KiXGolf Script   = kixgolf_ls.KIX

Computer
OS               = Windows Vista Business Edition
CPU              = Intel Pentium Model 15
Speed            = 2194 MHz
Memory           = 2038 MB

KiXGolf Scoring Engine
Scoring Engine   = 3.3

KiXtart Golf Score
Tournament       = Latin Squares
Processing Start = 2009/01/03 17:49:57.734
Processing End   = 2009/01/03 17:49:58.263
Duration         = 0000/00/00 00:00:00.529
KiXGolf Score    = 404

Thank you for participating in KiXtart Golf!
_________________________
The Code is out there

Top
#191567 - 2009-01-03 11:11 PM Re: KiXgolf: Latin Squares - public round [Re: DrillSergeant]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
i'm currently in a bar, but tomorrow as i get my hands on my laptop, i surely will try to kick some butt...
_________________________
!

download KiXnet

Top
#191568 - 2009-01-03 11:14 PM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hih. I saw something already. Can't test on this phone though...
_________________________
!

download KiXnet

Top
#191571 - 2009-01-04 12:22 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
For everyone else who likes to join, but can't read the code, here's my code with explanation:

 Code:
; begin KiXgolfUDF
;
;!
Function S($o)
Dim $i, $, $k, $t, $x

; Create a loop for the maximum number of x-es. (There are 16 fields)
For $x = 0 to 16

	; empty the row, column and square arrays and add one dimension to the solution array for current encountered x.
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	;loop through each column
	For $i = 0 to 3

		;loop through each row
		For $ = 0 to 3

			; retrieve the field from the original array
			$t = $o[$i,$]

			; find the corresponding square.
			;  0 0  1 1
			;  0 0  1 1
			;  2 2  3 3
			;  2 2  3 3
		
			$k = iif($i<2,iif($<2,0,1),iif($<2,2,3))
		
			; fill the row with all variables on that row
			$r[$] = $r[$] + $t
			
			; fill the column with all variables in that column
			$c[$i] = $c[$i] + $t

			; fill the square with all variables in that square
			$q[$k] = $q[$k] + $t

			; fill the solution array with the current variable 
			$s[$i, $, $x] = $t
		Next
	Next

	; if there are no more x-es in the rows, exit the function
	if instr(join($r),x)=0
		exit
	endif
	
	For $i = 0 to 3
		For $ = 0 to 3
				$k=@
				
				; Loop through each possible number (1,2,3 or 4)
				for $t = 1 to 4
					; If current variable is an x and the number ($t) does not exist in the corresponding row, column or square, add it to the variable $k 

					if instr($c[$i]+$r[$]+$q[iif($i<2,iif($<2,0,1),iif($<2,2,3))],$t)=0 & $o[$i,$]=x
						$k=$k+$t
					endif
				next

				; If there's only one digit in the variable $k, this means that that's the only solution for that x, so we can change that field in the initial array.
				if ($k^)=1
					$o[$i,$]=$k
					
					; we reset the $i and $j so that we exit these loops and start at the beginning of the $x loop again.
					$i=3 $=3
EndFunction
;!
;!
; end KiXgolfUDF
_________________________
The Code is out there

Top
#191588 - 2009-01-05 08:10 AM Re: KiXgolf: Latin Squares - public round [Re: DrillSergeant]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
k, got my computer at hand.
nobody seems to listen when I say iif() is bad...

 Quote:

Your solution passed all tests

KiXtart
KiXtart Version = 4.53
KiXGolf Script = kixgolf_ls.kix

Computer
OS = Windows XP Professional
CPU = AMD Turion(tm) 64 X2 Mobile Technology TL-64
Speed = 2194 MHz
Memory = 1920 MB

KiXGolf Scoring Engine
Scoring Engine = 3.3

KiXtart Golf Score
Tournament = Latin Squares
Processing Start = 2009/01/05 09:09:29.093
Processing End = 2009/01/05 09:09:29.187
Duration = 0000/00/00 00:00:00.093
KiXGolf Score = 366

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $i = 0 to 3
		For $ = 0 to 3
			$k = 3-2*($i<2)-($<2)
			
			$t = $o[$i,$]
			$r[$] = $r[$] + $t
			$c[$i] = $c[$i] + $t
			$q[$k] = $q[$k] + $t

			$s[$i, $, $x] = $t
		Next
	Next

	if instr(join($r),x)=0
		exit
	endif
	For $i = 0 to 3
		For $ = 0 to 3
				$k=@
				for $t = 1 to 4
					if instr($c[$i]+$r[$]+$q[3-2*($i<2)-($<2)],$t)=0 & $o[$i,$]=x
						$k=$k+$t
					endif
				next

				if ($k^)=1
					$o[$i,$]=$k
					$i=3 $=3
EndFunction
_________________________
!

download KiXnet

Top
#191589 - 2009-01-05 08:44 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

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

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $i = 0 to 3
		For $ = 0 to 3
			$k = 3-2*($i<2)-($<2)
			
			$t = $o[$i,$]
			$r[$] = $r[$] + $t
			$c[$i] = $c[$i] + $t
			$q[$k] = $q[$k] + $t

			$s[$i, $, $x] = $t
		Next
	Next

	if instr(join($r),x)=0
		exit
	endif
	For $ = 0 to 3
		For $i = 0 to 3
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$]+$r[$i]+$q[3-2*($<2)-($i<2)],$t) + $o[$,$i]
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$,$i]=$k
					$=3 $i=3
EndFunction
_________________________
!

download KiXnet

Top
#191590 - 2009-01-05 08:47 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn... I like your code very much.
tidy and clean.
_________________________
!

download KiXnet

Top
#191597 - 2009-01-05 10:49 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh.

I bet I forgot something = you got easy picking to do...

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $i = 0 to 7
		For $ = 0 to 3
			if $i<4
				$k = 3-2*($i<2)-($<2)
				$t = $o[$i,$]
				$r[$] = $r[$] + $t
				$c[$i] = $c[$i] + $t
				$q[$k] = $q[$k] + $t

				$s[$i, $, $x] = $t
				if 0=instr(join($r),x) & $i=3 & $=3
					exit
				endif
			else
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$i-4]+$r[$]+$q[3-2*($i<6)-($<2)],$t) + $o[$i-4,$]
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$i-4,$]=$k
					$i=7 $=3
EndFunction
_________________________
!

download KiXnet

Top
#191598 - 2009-01-05 10:53 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep...
361

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $ = 0 to 7
		For $i = 0 to 3
			if $<4
				$k = 3-2*($<2)-($i<2)
				$t = $o[$,$i]
				$r[$i] = $r[$i] + $t
				$c[$] = $c[$] + $t
				$q[$k] = $q[$k] + $t

				$s[$, $i, $x] = $t
				if 0=instr(join($r),x) & $i=3 & $=3
					exit
				endif
			else
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$-4]+$r[$i]+$q[3-2*($<6)-($i<2)],$t) + $o[$-4,$i]
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$-4,$i]=$k
					$=7 $i=3
EndFunction
_________________________
!

download KiXnet

Top
#191599 - 2009-01-05 10:57 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.

352

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $ = 0 to 7
		For $i = 0 to 3
			if $<4
				$k = 3-2*($<2)-($i<2)
				$t = $o[$,$i]
				$r[$i] = $r[$i] + $t
				$c[$] = $c[$] + $t
				$q[$k] = $q[$k] + $t

				$s[$, $i, $x] = $t
			else
				if 0=instr(join($r),x)
					exit
				endif
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$-4]+$r[$i]+$q[3-2*($<6)-($i<2)],$t) + $o[$-4,$i]
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$-4,$i]=$k
					$=7 $i=3
EndFunction
_________________________
!

download KiXnet

Top
#191600 - 2009-01-05 10:59 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

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

 Code:
Function S($o)
Dim $i, $, $k, $t, $x

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $ = 0 to 7
		For $i = 0 to 3
			if $<4
				$k = 3-2*($<2)-($i<2)
				$t = $o[$,$i]
				$r[$i] = $r[$i] + $t
				$c[$] = $c[$] + $t
				$q[$k] = $q[$k] + $t

				$s[$, $i, $x] = $t
			else
				if 0=instr(join($r),x)
					exit
				else
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$-4]+$r[$i]+$q[3-2*($<6)-($i<2)],$t) + $o[$-4,$i]
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$-4,$i]=$k
					$=7 $i=3
EndFunction
_________________________
!

download KiXnet

Top
#191601 - 2009-01-05 11:14 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, now need to get back to work.

350

 Code:
Function S($o)
Dim $i, $, $k, $t, $x,$v

For $x = 0 to 16
	Redim $r[3], $c[3], $q[3], $s[3, 3, $x]
	
	For $ = 0 to 7
		For $i = 0 to 3
			$v = $o[$ mod 4,$i]
			if $<4
				$k = 3-2*($<2)-($i<2)
				$r[$i] = $r[$i] + $v
				$c[$] = $c[$] + $v
				$q[$k] = $q[$k] + $v

				$s[$, $i, $x] = $v
			else
				if 0=instr(join($r),x)
					exit
				else
				$k=@
				for $t = 1 to 4
					if 0=instr($c[$-4]+$r[$i]+$q[3-2*($<6)-($i<2)],$t) + $v
						$k=$k+$t
					endif
				next

				if 1=($k^)
					$o[$-4,$i]=$k
					$=7 $i=3
EndFunction
_________________________
!

download KiXnet

Top
#191606 - 2009-01-05 04:04 PM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
WOW! That is efficient, I couldn't even come up with working code, and Drill's code has been Lonked so I doubt there is much left to be golfed.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#191608 - 2009-01-05 04:14 PM Re: KiXgolf: Latin Squares - public round [Re: Benny69]
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
It could be even more efficient if the array functions SPLIT, JOIN & ASCAN would be dimension aware...
_________________________
The Code is out there

Top
#191610 - 2009-01-05 04:51 PM Re: KiXgolf: Latin Squares - public round [Re: DrillSergeant]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
I can't believe it! I found 2: 348

 Code:
Your solution passed all tests

KiXtart
KiXtart Version  = 4.60
KiXGolf Script   = kixgolf_ls.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       = Latin Squares
Processing Start = 2009/01/05 09:48:23.552
Processing End   = 2009/01/05 09:48:23.725
Duration         = 0000/00/00 00:00:00.172
KiXGolf Score    = 348

Thank you for participating in KiXtart Golf!
Press any key to continue...


 Code:
Function S($o)
  Dim $i, $, $k, $t, $x, $v
  
  For $x = 0 to 16
    ReDim $r[3], $c[3], $q[3], $s[3, 3, $x]
    
    For $ = 0 to 7
      For $i = 0 to 3
        $v = $o[$ mod 4, $i]
        If $ < 4
          $k = 3-2*($<2)-($i<2)
          $r[$i] = $r[$i] + $v
          $c[$] = $c[$] + $v
          $q[$k] = $q[$k] + $v
          $s[$, $i, $x] = $v
        Else
;          If 0 = InStr(Join($r),x)
          If 0 > AScan($r,x,,,1)
            Exit
          Else
            $k = @
            For $t = 1 to 4
              If 0 = InStr($c[$-4]+$r[$i]+$q[3-2*($<6)-($i<2)],$t) + $v
                $k = $k + $t
              EndIf
            Next
    
            If 1=($k^)
              $o[$-4,$i] = $k
              $ = 7
              $i = 3
;            EndIf
;          EndIf
;        EndIf
;      Next
;    Next
;  Next
EndFunction
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#191625 - 2009-01-05 09:20 PM Re: KiXgolf: Latin Squares - public round [Re: Benny69]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn damn.
should have saved some of the shaves to later time.
_________________________
!

download KiXnet

Top
#191627 - 2009-01-05 09:31 PM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
got something different after hours of trying and it ended up as 348! :@
_________________________
!

download KiXnet

Top
#191650 - 2009-01-06 01:05 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
362, going into wrong direction...
_________________________
!

download KiXnet

Top
#191651 - 2009-01-06 01:12 AM Re: KiXgolf: Latin Squares - public round [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
RIGHT, 345

 Code:
; begin KiXgolfUDF
;
;!
Function S($o)
  Dim $i, $, $k, $t, $x, $v, $p
  
  For $x = 0 to 16
    ReDim $r[3], $c[3], $q[3], $s[3, 3, $x]
    
    For $ = 0 to 7
      For $i = 0 to 3
        $v = $o[$ mod 4, $i]
        $k = 3-2*($<2)-($i<2)
        If $ < 4
          $r[$i] = $r[$i] + $v
          $c[$] = $c[$] + $v
          $q[$k] = $q[$k] + $v
          $s[$, $i, $x] = $v
        Else
          If 0 > AScan($r,x,,,1)
            Exit
          Else
            $p = @
            For $t = 1 to 4
              If 0 = InStr($c[$-4]+$r[$i]+$q[$k-2*($<6)],$t) + $v
                $p = $p + $t
              EndIf
            Next
    
            If 1=($p^)
              $o[$-4,$i] = $p
              $ = 7
              $i = 3
EndFunction

;!
;!
; end KiXgolfUDF
_________________________
!

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 686 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.065 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

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