Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting APL Sudoku solver(s) #15

Closed
shnarazk opened this issue Jun 2, 2023 · 2 comments
Closed

Porting APL Sudoku solver(s) #15

shnarazk opened this issue Jun 2, 2023 · 2 comments
Assignees

Comments

@shnarazk
Copy link
Owner

shnarazk commented Jun 2, 2023

Sudoku{                                         Solution vector for square Sudoku puzzle ⍵.
    BoxNos   {/ *2}                     box numbers for a puzzle of size ⍵*2
    RowColBoxNos   {(),¨BoxNos*0.5}         row/column/box numbers
    ContentionMap  {[2] 1¨.=}             contention map for puzzle ⍵
    CMAP  ContentionMap RowColBoxNos          fixed contention map for current puzzle

    Available   {()~×CMAP}              list of available numbers at position ⍺ for puzzle ⍵
    EmptyCells  {(,=0)/,}                   row & column indices of empty cells
    Placements  {( Available )@()¨}      puzzle ⍵ with all available numbers at position ⍺
    AllPlacements  {,/Placements¨}          all possible Placements at ⍺ based on partial solutions ⍵
    Solutions  {AllPlacements/(EmptyCells ),⊂⊂}   solution vector

    Solutions 
}
@shnarazk shnarazk self-assigned this Jun 2, 2023
@shnarazk
Copy link
Owner Author

shnarazk commented Jun 2, 2023

Converting one by one

Box  {>𝕩/<˘𝕩‿⥊𝕩/1+↕𝕩2}
# (1+44) ∾¨ Box 2
Rcb  {(1+↕𝕩)∾¨Box0.5˜𝕩}
# Rcb 44
Cmap  {<˘˘1 (⊑)¨ =⌜˜𝕩}
Cmap Rcb 44

Avl  {(1+↕⊑𝕩)(¬/)(0)⊸/⥊𝕩×𝕨⊑Cmap Rcb 𝕩}

Why does not Avl respect the initial value???

Avl  {0𝕨⊑𝕩? ⋈𝕨⊑𝕩; (1+↕⊑𝕩)(¬/)(0)⊸/⥊𝕩×𝕨⊑Cmap RCB 𝕩}
Nxt   {w F x:(𝕨 Avl 𝕩) {𝕨˙(w⊸⊑)𝕩}¨ <𝕩}
Nxtv  {∾𝕨⊸Nxt¨𝕩}        # use like (<s44)Nxtv´⟨00,01,10

Wait.
Why does not Avl respect the initial value???

Avl  {0𝕨⊑𝕩? ⋈𝕨⊑𝕩; (1+↕⊑𝕩)(¬/)(0)⊸/⥊𝕩×𝕨⊑Cmap RCB 𝕩}

Now we can do:

(<s44)Nxtv´⥊↕s44

@shnarazk shnarazk closed this as completed Jun 3, 2023
@shnarazk
Copy link
Owner Author

shnarazk commented Jun 4, 2023

https://www.youtube.com/watch?v=YnJ1Yy6gpmA

  • ⍺ nxt ⍵ means 'AssignTheFirstHole of ⍺ to ⍵'
  • is recursion.
Sol  {
    terminated? answer;    # Is there a way to 'break'?
    𝕊¨ nextstates          # This is depth-first search.
}

TIL

  • depth-frist search: {𝕊∘N¨𝕩}
  • width-frist search: {𝕊 N¨𝕩}

What a beautiful world!

@shnarazk shnarazk reopened this Jun 4, 2023
@shnarazk shnarazk changed the title Porting APL Sudoku solver Porting APL Sudoku solver(s) Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant