make it parallel, not that it makes it much faster

This commit is contained in:
David 2020-12-01 22:19:49 -05:00
parent 1d3e59db86
commit b3bfb86563

View File

@ -35,12 +35,15 @@ func partOne() {
numbers = append(numbers, i)
}
solution := make(chan int, 1)
for i := range numbers {
if result := checkTwoSums(numbers[i], numbers[i+1:]); result != 0 {
fmt.Println(result)
return
}
go func(a int) {
if r := checkTwoSums(numbers[a], numbers[a+1:]); r != 0 {
solution <- r
}
}(i)
}
fmt.Println(<-solution)
}
func checkTwoSums(i int, rest []int) int {
@ -68,14 +71,18 @@ func partTwo() {
numbers = append(numbers, i)
}
solution := make(chan int, 1)
for i := range numbers {
for j := range numbers[i+1:] {
if result := checkThreeSums(numbers[i], numbers[j], numbers[j+1:]); result != 0 {
fmt.Println(result)
return
go func(a int) {
for j := range numbers[a+1:] {
if r := checkThreeSums(numbers[a], numbers[j], numbers[j+1:]); r != 0 {
solution <- r
}
}
}
}(i)
}
fmt.Println(<-solution)
}
func checkThreeSums(i int, j int, rest []int) int {