adjust bound factory method to set open end of interval

This commit is contained in:
onyx-and-iris 2024-01-02 09:18:14 +00:00
parent cc452c76a4
commit 5b225a9166

View File

@ -15,8 +15,9 @@ type bound struct {
}
// newBound returns a bound type
// it defines an open ended interval
func newBound(lower, upper int) bound {
return bound{lower: lower, upper: upper}
return bound{lower: lower, upper: upper - 1}
}
// nextTransform recursively calculates each new set of seed ranges for each set of data in dataMap
@ -41,10 +42,10 @@ func nextTransform(i int, in []bound) []bound {
// append unmatched portions of seed range back into queue
if start > r.lower {
q.enqueue(newBound(r.lower, start-1))
q.enqueue(newBound(r.lower, start))
}
if r.upper > end {
q.enqueue(newBound(end, r.upper-1))
q.enqueue(newBound(end, r.upper))
}
return true
}
@ -68,7 +69,7 @@ func two(lines []string) int {
wg.Add(1)
go func(i int) {
defer wg.Done()
seedRanges = append(seedRanges, nextTransform(0, []bound{newBound(seeds[i], seeds[i]+seeds[i+1]-1)})...)
seedRanges = append(seedRanges, nextTransform(0, []bound{newBound(seeds[i], seeds[i]+seeds[i+1])})...)
}(i)
}