Created
May 8, 2012 23:17
-
-
Save joshz/2640305 to your computer and use it in GitHub Desktop.
2sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* User: jz | |
* Date: 4/23/12 | |
* Time: 5:00 PM | |
*/ | |
package main | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
"strconv" | |
) | |
func find_in_map(nums map[int] int, num int) bool{ | |
for v := range nums{ | |
_, ok := nums[num - v] | |
if ok{ | |
return true | |
} | |
} | |
return false | |
} | |
func main() { | |
fn := "ints.txt" | |
infile, err := os.Open(fn) | |
if err != nil { | |
panic(err) | |
} | |
var nums = map[int]int{} | |
for { | |
var num int | |
_, err := fmt.Fscanln(infile, &num) | |
if err != nil { | |
break | |
} | |
nums[num] = num | |
} | |
sums := [...]int{231552,234756,596873,648219,726312,981237,988331,1277361,1283379} | |
var btoi = map[bool] int {false: 0, true: 1} | |
var targetconfirm string; | |
for i := range sums { | |
fmt.Print("checking:", sums[i], "\n") | |
s := []string {targetconfirm, strconv.Itoa(btoi[find_in_map(nums, sums[i])])} | |
targetconfirm = strings.Join(s, "") | |
} | |
fmt.Print(targetconfirm) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment