OZONE Asylum
Forums
Server-Side Scripting - Oh my!
Creating Sudoku 3x3x3x3
This page's ID:
33324
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Okay, so here is some code that starts with the template and does the Deadly Pattern thing. I completely stripped the code of all non-essentials (including comments) and hard-coded a few parts here-n-there. Noticed that the only import is 'random' and the rest is stock Python. Another thing to notice is that my main data structure is 4d. I did this because interating over a block is so much easier than doing 2d acrobatics. Egads, I can't imagine trying to do this in 2d. This is why I titled this thread 3x3x3x3. One thing that I did not include is a way to validate that the state is a valid sudoku grid. They are all valid because of the way that this algorithm works. No need to validate. Boom. Another thing that I did not include is permutations.... to an extent. No row/col swaps, mirroring, et al. I'll get into this later. However, I did include value re-mapping because it is inconsquential to do so on several levels. Value re-mapping is whatever in terms of code and symbols. Completely cheeky, so why not? I'll get into the other perms later. Things like rol/col swaps, mirroring, flips, and all that. Later. Nerd rant me thinks. Pretty much do whatever with this code and/or algorithm in general. Give it a few runs, modify, and share. I think it would be great if somebody implemented in their own way and really gave it a go. [code] #!/usr/bin/env python import random dr_inter=30 def cout(cme): bseq=['1','2','3','4','5','6','7','8','9'] random.shuffle(bseq) f='' print('') for by in range(3): for cy in range(3): c='' for bx in range(3): for cx in range(3): c=c+bseq[cme[by][bx][cy][cx]] f=f+bseq[cme[by][bx][cy][cx]] c=c+' ' print(c) print('') print(f) print('') return def deadly_scan(drgrid): cas=[[0, 1], [0, 2], [1, 2]] sdr=[] for by in range(3): for cy in cas: cy0=cy[0] cy1=cy[1] for bx in cas: bx0=bx[0] bx1=bx[1] for cx0 in range(3): for cx1 in range(3): t0=drgrid[by][bx0][cy0][cx0] t1=drgrid[by][bx1][cy1][cx1] t2=drgrid[by][bx0][cy1][cx0] t3=drgrid[by][bx1][cy0][cx1] if (t0==t1) and (t2==t3): if t0<t2: sdr.append([ by,bx0,cy0,cx0, by,bx1,cy1,cx1, t0,t2 ]) else: sdr.append([ by,bx0,cy0,cx0, by,bx1,cy1,cx1, t2,t0 ]) for bx in range(3): for cx in cas: cx0=cx[0] cx1=cx[1] for by in cas: by0=by[0] by1=by[1] for cy0 in range(3): for cy1 in range(3): t0=drgrid[by0][bx][cy0][cx0] t1=drgrid[by1][bx][cy1][cx1] t2=drgrid[by0][bx][cy0][cx1] t3=drgrid[by1][bx][cy1][cx0] if (t0==t1) and (t2==t3): if t0<t2: sdr.append([ by0,bx,cy0,cx0, by1,bx,cy1,cx1, t0,t2 ]) else: sdr.append([ by0,bx,cy0,cx0, by1,bx,cy1,cx1, t2,t0 ]) return sdr def scan_dr(mgrid): dr_sig=[] for i in range(dr_inter): rlist=[] rlist2=deadly_scan(mgrid) random.shuffle(rlist2) for dr in rlist2: if dr not in dr_sig: rlist.append(dr) rmask=[[[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]], [[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]], [[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]]] for dr in rlist: by0=dr[0];bx0=dr[1] cy0=dr[2];cx0=dr[3] by1=dr[4];bx1=dr[5] cy1=dr[6];cx1=dr[7] val0=dr[8];val1=dr[9] if by0==by1: m0=rmask[by0][bx0][cy0][cx0] m1=rmask[by1][bx1][cy1][cx1] m2=rmask[by0][bx0][cy1][cx0] m3=rmask[by1][bx1][cy0][cx1] mbit=m0&m1&m2&m3 if mbit: nval0=mgrid[by0][bx0][cy0][cx0] nval2=mgrid[by0][bx0][cy1][cx0] mgrid[by0][bx0][cy0][cx0]=nval2 mgrid[by1][bx1][cy1][cx1]=nval2 mgrid[by0][bx0][cy1][cx0]=nval0 mgrid[by1][bx1][cy0][cx1]=nval0 rmask[by0][bx0][cy0][cx0]=0 rmask[by1][bx1][cy1][cx1]=0 rmask[by0][bx0][cy1][cx0]=0 rmask[by1][bx1][cy0][cx1]=0 dr_sig.append(dr) else: m0=rmask[by0][bx0][cy0][cx0] m1=rmask[by1][bx1][cy1][cx1] m2=rmask[by0][bx0][cy0][cx1] m3=rmask[by1][bx1][cy1][cx0] mbit=m0&m1&m2&m3 if mbit: nval0=mgrid[by0][bx0][cy0][cx0] nval2=mgrid[by0][bx0][cy0][cx1] mgrid[by0][bx0][cy0][cx0]=nval2 mgrid[by1][bx1][cy1][cx1]=nval2 mgrid[by0][bx0][cy0][cx1]=nval0 mgrid[by1][bx1][cy1][cx0]=nval0 rmask[by0][bx0][cy0][cx0]=0 rmask[by1][bx1][cy1][cx1]=0 rmask[by0][bx0][cy0][cx1]=0 rmask[by1][bx1][cy1][cx0]=0 dr_sig.append(dr) return mgrid def main(): state=[[[[1,0,5],[6,4,2],[3,8,7]],[[4,3,8],[0,7,5],[6,2,1]],[[7,6,2],[3,1,8],[0,5,4]]], [[[2,1,3],[7,5,0],[4,6,8]],[[5,4,6],[1,8,3],[7,0,2]],[[8,7,0],[4,2,6],[1,3,5]]], [[[0,2,4],[8,3,1],[5,7,6]],[[3,5,7],[2,6,4],[8,1,0]],[[6,8,1],[5,0,7],[2,4,3]]]] state=scan_dr(state) cout(state) return 0 if __name__ == '__main__': main() [/code] Up next: Perms and Nerd Rant
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail