func sat(nvar int, lits, locs []int) []int { var ( assn = make([]int, nvar) head = make([]int, nvar*2) ncls = len(locs) - 1 tail = make([]int, ncls) ) for lit := range head { head[lit] = -1 } for cls, first := range locs[:ncls] { lit := lits[first] tail[cls] = head[lit] head[lit] = cls } for var1 := 0; var1 < nvar; var1++ { falseLit := var1 * 2 if head[falseLit] >= 0 && head[falseLit+1] < 0 { assn[var1] = 1 falseLit++ } for cls := head[falseLit]; ; { if cls < 0 { head[falseLit] = cls break } var ( first = locs[cls] past = locs[cls+1] ) for at := first; ; { if at++; at < past { var ( lit = lits[at] var2 = lit >> 1 ) if var2 <= var1 && (assn[var2]^lit)&1 != 0 { continue } lits[at] = falseLit lits[first] = lit next := tail[cls] tail[cls] = head[lit] head[lit] = cls cls = next break } head[falseLit] = cls was := assn[var1] for ; was >= 2; was = assn[var1] { assn[var1] = 0 if var1--; var1 < 0 { return nil } } assn[var1] = was ^ 3 falseLit = var1*2 + 1 - was cls = head[falseLit] break } } } for var1 := range assn { assn[var1] &= 1 } return assn }
To receive a hint, submit unfixed code.