make it parallel, not that it makes it much faster
This commit is contained in:
parent
1d3e59db86
commit
b3bfb86563
21
01/main.go
21
01/main.go
@ -35,12 +35,15 @@ func partOne() {
|
|||||||
numbers = append(numbers, i)
|
numbers = append(numbers, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
solution := make(chan int, 1)
|
||||||
for i := range numbers {
|
for i := range numbers {
|
||||||
if result := checkTwoSums(numbers[i], numbers[i+1:]); result != 0 {
|
go func(a int) {
|
||||||
fmt.Println(result)
|
if r := checkTwoSums(numbers[a], numbers[a+1:]); r != 0 {
|
||||||
return
|
solution <- r
|
||||||
}
|
}
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
|
fmt.Println(<-solution)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkTwoSums(i int, rest []int) int {
|
func checkTwoSums(i int, rest []int) int {
|
||||||
@ -68,14 +71,18 @@ func partTwo() {
|
|||||||
numbers = append(numbers, i)
|
numbers = append(numbers, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
solution := make(chan int, 1)
|
||||||
|
|
||||||
for i := range numbers {
|
for i := range numbers {
|
||||||
for j := range numbers[i+1:] {
|
go func(a int) {
|
||||||
if result := checkThreeSums(numbers[i], numbers[j], numbers[j+1:]); result != 0 {
|
for j := range numbers[a+1:] {
|
||||||
fmt.Println(result)
|
if r := checkThreeSums(numbers[a], numbers[j], numbers[j+1:]); r != 0 {
|
||||||
return
|
solution <- r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
|
fmt.Println(<-solution)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkThreeSums(i int, j int, rest []int) int {
|
func checkThreeSums(i int, j int, rest []int) int {
|
||||||
|
Loading…
Reference in New Issue
Block a user