Created
May 22, 2020 12:16
-
-
Save Gasoid/f5ae4b4726cda8560f89fb4313a47c58 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"bufio" | |
"io/ioutil" | |
"os" | |
"strconv" | |
) | |
const ( | |
inputFile string = "input.txt" | |
outputFile string = "output.txt" | |
defaultPerms = 0644 | |
) | |
func main() { | |
vars := make(map[int]int, 0) | |
file, _ := os.Open(inputFile) | |
defer file.Close() | |
reader := bufio.NewReader(file) | |
targetStr, _ := reader.ReadString('\n') | |
target, _ := strconv.Atoi(targetStr[0 : len(targetStr)-1]) | |
for { | |
numStr, err := reader.ReadString(' ') | |
if err != nil { | |
break | |
} | |
num, err := strconv.Atoi(numStr[0 : len(numStr)-1]) | |
if err != nil { | |
break | |
} | |
if _, ok := vars[num]; !ok { | |
vars[target-num] = num | |
} else { | |
ioutil.WriteFile(outputFile, []byte("1"), defaultPerms) | |
return | |
} | |
} | |
ioutil.WriteFile(outputFile, []byte("0"), defaultPerms) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment