Example #1
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))}
}
Example #2
0
func (b *block) check(cid cellId, v bitset.Element) bool {
	sum := int(b.clue) - int(v)
	used := bitset.Set(v)
	b.cleft = b.cleft[:0]
	for id, c := range b.cells {
		if id != cid {
			switch c.possible.Size() {
			case 0:
				return false
			case 1:
				e := c.possible.Min()
				if used.Contains(e) {
					return false
				}
				sum -= int(e)
				used = used.Add(e)
			default:
				b.cleft = append(b.cleft, c)
			}
		}
	}
	return b.findFeas(0, sum, used)
}