> solve4 :: Grid -> [Grid]

> solve4 = search . prune . choices

>

> search :: Matrix Choices -> [Grid]

> search m

> | blocked m = []

> | complete m = collapse m

> | otherwise = [g | m' <- expand m

> , g <- search (prune m')]


The function expand behaves in the same way as collapse, except that

it only collapses the first square with more than one choice:


> expand :: Matrix Choices -> [Matrix Choices]

> expand m =

> [rows1 ++ [row1 ++ [c] : row2] ++ rows2 | c <- cs]

> where

> (rows1,row:rows2) = break (any (not . single)) m

> (row1,cs:row2) = break (not . single) row



https://github.com/Thecentury/haskell-sudoku/blob/master/src/completed-sudoku.lhs

haskell-sudoku/src/completed-sudoku.lhs at master · Thecentury/haskell-sudoku

An implementation of a sudoku solver in Haskell following the lectures from the Advanced Functional Programming course of Graham Hutton - Thecentury/haskell-sudoku

github.com



https://www.youtube.com/watch?v=6jKiCHuUb44&list=PLF1Z

AFP 2 - Sudoku I: First Steps

To get back into 'thinking in Haskell', the first three lectures show how to develop an efficient Haskell program to solve sudoku puzzles. This lecture expl...

www.youtube.com



https://www.youtube.com/watch?v=06nd2-N2FOA&list=PLF1Z

AFP 3 - Sudoku II: Initial Solvers

This lecture develops our first sudoku solver, based upon the idea of exhaustively enumerating the search space. This turns out to be impractical, so we the...

www.youtube.com



https://www.youtube.com/watch?v=bK1z1Ps0wzc&list=PLF1Z

AFP 4 - Sudoku III: Improving Performance

This lecture shows how to further improve the performance of the sudoku solver so that it can solve any puzzle in an instant, using the idea of rejecting cho...

www.youtube.com


for, if 없이 최적화한 solution을 자료구조와 순수함수만으로 재귀돌면서 구현할 수 있다는게

엄청 간지나긴함


이걸 맨땅에서 생각해내서 구현할정도의 실력은 대체 얼마나 머리가 좋은걸까

가끔씩 다시보는데도 새로움