2023 day 01 part 1
This commit is contained in:
parent
6688ec09c3
commit
ea298887bd
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
@ -1 +0,0 @@
|
||||
package main
|
1000
2023/day-01/input
Normal file
1000
2023/day-01/input
Normal file
File diff suppressed because it is too large
Load Diff
60
2023/day-01/main.go
Normal file
60
2023/day-01/main.go
Normal file
@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed *
|
||||
var input embed.FS
|
||||
|
||||
func main() {
|
||||
data, err := fs.ReadFile(input, "input")
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: failed to read input: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
totalVals := 0
|
||||
|
||||
lines := strings.Split(string(data), "\n")
|
||||
|
||||
for _, v := range lines {
|
||||
if v == "" {continue}
|
||||
values := ""
|
||||
|
||||
chars := strings.Split(v, "")
|
||||
|
||||
for i := 0; i < len(chars); i++ {
|
||||
num, err := strconv.ParseInt(chars[i], 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
values = values + fmt.Sprint(num)
|
||||
break
|
||||
}
|
||||
|
||||
for i := len(chars)-1; i >= 0; i-- {
|
||||
num, err := strconv.ParseInt(chars[i], 10, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
values = values + fmt.Sprint(num)
|
||||
break
|
||||
}
|
||||
|
||||
int, err := strconv.Atoi(values)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
totalVals = totalVals + int
|
||||
}
|
||||
|
||||
fmt.Printf("The total is: %d\n", totalVals)
|
||||
}
|
4
2023/day-01/test_input
Normal file
4
2023/day-01/test_input
Normal file
@ -0,0 +1,4 @@
|
||||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
Loading…
x
Reference in New Issue
Block a user