This commit is contained in:
2024-12-01 06:12:25 +02:00
parent c82ee691a1
commit b1816dcbf8
6 changed files with 66 additions and 20 deletions

4
.gitignore vendored
View File

@@ -1,2 +1,4 @@
**/input*.txt
.DS_Store
**/test*.txt
.DS_Store
.env

3
2023/01/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module main
go 1.21.4

44
2023/01/main.go Normal file
View File

@@ -0,0 +1,44 @@
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func main() {
lines := parse()
var first = 0
var last = 0
for _, line := range lines {
fmt.Println(line)
for i := 0; i < len(line); i++ {
//fmt.Println(int(line[i]))
x := strconv.Atoi(line[i])
if x {
first = x
break
}
}
for i := 0; i < len(line); i++ {
//fmt.Println(int(line[i]))
x, err := strconv.Atoi(line[i])
if err == nil {
last = x
break
}
}
}
}
func parse() []string {
filePath := os.Args[1]
data, _ := os.ReadFile(filePath)
chunks := strings.Split(string(data), "\n")
return chunks
}

5
2023/go.work Normal file
View File

@@ -0,0 +1,5 @@
go 1.21.4
use (
./01
)

View File

@@ -1,32 +1,24 @@
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
filePath := os.Args[1]
readFile, err := os.Open(filePath)
lines := parse()
if err != nil {
fmt.Println(err)
}
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
var fileLines []string
for fileScanner.Scan() {
fileLines = append(fileLines, fileScanner.Text())
}
readFile.Close()
for _, line := range fileLines {
for _, line := range lines {
fmt.Println(line)
}
fmt.Println(fileLines)
}
func parse() []string {
filePath := os.Args[1]
data, _ := os.ReadFile(filePath)
chunks := strings.Split(string(data), "\n")
return chunks
}

View File

@@ -1,7 +1,7 @@
#!/bin/bash
source "$(dirname "$0")/../.env"
day=$(date +%d)
day=$(date +%-d)
echo "Getting input for day $day"