Browse Source

Remove error handling, it works

master
Jan-Lukas Else 4 months ago
parent
commit
e7ba4605a0
2 changed files with 4 additions and 24 deletions
  1. +2
    -12
      1/1/main.go
  2. +2
    -12
      1/2/main.go

+ 2
- 12
1/1/main.go View File

@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
@ -34,25 +33,16 @@ import (
// Of course, your expense report is much larger. Find the two entries that sum to 2020; what do you get if you multiply them together?
func main() {
file, err := os.Open("../input.txt")
if err != nil {
log.Fatal(err)
}
file, _ := os.Open("../input.txt")
defer file.Close()
numbers := []int{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
n, err := strconv.Atoi(scanner.Text())
if err != nil {
log.Fatal(err)
}
n, _ := strconv.Atoi(scanner.Text())
numbers = append(numbers, n)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
for _, i := range numbers {
for _, j := range numbers {


+ 2
- 12
1/2/main.go View File

@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)
@ -15,25 +14,16 @@ import (
// In your expense report, what is the product of the three entries that sum to 2020?
func main() {
file, err := os.Open("../input.txt")
if err != nil {
log.Fatal(err)
}
file, _ := os.Open("../input.txt")
defer file.Close()
numbers := []int{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
n, err := strconv.Atoi(scanner.Text())
if err != nil {
log.Fatal(err)
}
n, _ := strconv.Atoi(scanner.Text())
numbers = append(numbers, n)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
for _, i := range numbers {
for _, j := range numbers {


Loading…
Cancel
Save