Example #1
0
func (cell *ValueCell) prettyString(k int) string {
	s := ""
	for e := 3*k + 1; e <= 3*k+3; e++ {
		if cell.Val.Contains(bitset.Element(e)) {
			s += fmt.Sprintf("%d", e)
		} else {
			s += " "
		}
	}
	return s
}
Example #2
0
func (b *block) checkAll() {
	for _, c := range b.cells {
		c.checked = bitset.EmptySet
	}
	for id, c := range b.cells {
		for e := bitset.Element(1); e <= 9; e++ {
			// read from input channel here
			if c.possible.Minus(c.checked).Contains(e) {
				if b.check(id, e) {
					c.checked = c.checked.Add(e)
				} else {
					c.possible = c.possible.Remove(e)
					// write to output channel here
				}
			}
		}
	}
}
Example #3
0
func parseCell(s string) Cell {
	if len(s) != 5 {
		return nil
	}
	if s == "     " {
		return &ValueCell{Val: bitset.Interval(1, 9)}
	}
	if s[2] == '\\' {
		if v, h := parseClue(s[:2]), parseClue(s[3:]); v == errClue || h == errClue {
			return nil
		} else {
			return &ClueCell{VClue: v, HClue: h}
		}
	}
	e, err := strconv.Atoi(s)
	if err != nil || e < 1 || 9 < e {
		return nil
	}
	return &ValueCell{Val: bitset.Set(bitset.Element(e))}
}