Anonymous user
Sudoku: Difference between revisions
m
→Constraint Satisfaction (Norvig)
Line 4,177:
/// Dictionary of all peer squares in the relevant units wrt square in question
let peers =
[for s in squares do units
|> Map.ofList
/// Eliminate d from values[s] and propagate when values = 1.
/// Return Some values, except return None if a contradiction is detected.
let rec eliminate (values:Map<
let peerElim (vx:Map<
match Seq.length vx[s] with // (1) If a square s is reduced to one value d, then eliminate d from the peers.
| 0 -> None // removed last value
Line 4,191:
let unitsElim vx =
units[s] // (2) If a unit u is reduced to only one place for a value d, then put it there.
|> List.ofArray |> all (fun (st:Map<
let dKeys = [for s in u do if st[s] |> Seq.contains d then s]
match Seq.length dKeys with
Line 4,220:
/// Convert grid to a Map of constraint popagated possible values, or return None if a contradiction is detected.
let applyCPS (parsedGrid:Map<
let values = [for s in squares do s, digits]|> Map.ofList
parsedGrid
|