mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-15 15:10:49 +00:00
adjust bound factory method to set open end of interval
This commit is contained in:
parent
cc452c76a4
commit
5b225a9166
@ -15,8 +15,9 @@ type bound struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newBound returns a bound type
|
// newBound returns a bound type
|
||||||
|
// it defines an open ended interval
|
||||||
func newBound(lower, upper int) bound {
|
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
|
// 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
|
// append unmatched portions of seed range back into queue
|
||||||
if start > r.lower {
|
if start > r.lower {
|
||||||
q.enqueue(newBound(r.lower, start-1))
|
q.enqueue(newBound(r.lower, start))
|
||||||
}
|
}
|
||||||
if r.upper > end {
|
if r.upper > end {
|
||||||
q.enqueue(newBound(end, r.upper-1))
|
q.enqueue(newBound(end, r.upper))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -68,7 +69,7 @@ func two(lines []string) int {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
defer wg.Done()
|
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)
|
}(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user