Skip to content

Instantly share code, notes, and snippets.

@ksexton
Created April 12, 2018 19:21
Show Gist options
  • Save ksexton/b3ebe88797e997b3f253589c492d7e6a to your computer and use it in GitHub Desktop.
Save ksexton/b3ebe88797e997b3f253589c492d7e6a to your computer and use it in GitHub Desktop.
2018-04-12 daily problem
//
// Given a list of numbers, return whether any two sums to k.
//
// For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.
//
// Bonus: Can you do this in one pass?
package main
import "fmt"
func checkNumbers(numbers []int, total int) bool {
l := len(numbers)
match := false
for k, v := range numbers {
if k == (l - 1) {
break
} else {
for i := k + 1; i < l; i++ {
fmt.Println(v, " + ", numbers[i], "= ", v+numbers[i])
if v+numbers[i] == total {
match = true
}
}
}
}
return match
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment