2023 day 01 part 1

This commit is contained in:
Mans Ziesel 2023-12-01 11:02:00 +01:00
parent 6688ec09c3
commit ea298887bd
26 changed files with 1064 additions and 23 deletions

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

View File

@ -1 +0,0 @@
package main

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
View 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
View File

@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet