Browse Source

Add stub files

master
Elis Hirwing 10 months ago
parent
commit
e9230063b0
Signed by: etu GPG Key ID: D57EFA625C9A925F
  1. 1
      dayXX/example.txt
  2. 1
      dayXX/input.txt
  3. 14
      dayXX/parse.go
  4. 12
      dayXX/solve1.go
  5. 12
      dayXX/solve2.go
  6. 3
      go.mod
  7. 15
      main.go
  8. 28
      utils/perf.go
  9. 32
      utils/readfile.go

1
dayXX/example.txt

@ -0,0 +1 @@

1
dayXX/input.txt

@ -0,0 +1 @@

14
dayXX/parse.go

@ -0,0 +1,14 @@
package dayXX
import (
"git.elis.nu/etu/aoc2020/utils"
)
var rows []string
func ParseFile(input string) {
// Parse file
for _, line := range utils.GetLinesFromFile("dayXX/" + input + ".txt") {
rows = append(rows, line)
}
}

12
dayXX/solve1.go

@ -0,0 +1,12 @@
package dayXX
import (
"fmt"
"log"
)
func Solve1() {
fmt.Println(rows)
log.Printf("2020-12-XX.01: Answer: %d\n", len(rows))
}

12
dayXX/solve2.go

@ -0,0 +1,12 @@
package dayXX
import (
"fmt"
"log"
)
func Solve2() {
fmt.Println(len(rows))
log.Printf("2020-12-XX.02: Answer: %d\n", len(rows))
}

3
go.mod

@ -0,0 +1,3 @@
module git.elis.nu/etu/aoc2020
go 1.15

15
main.go

@ -0,0 +1,15 @@
package main // import "git.elis.nu/etu/aoc2020"
import (
"log"
"os"
)
func main() {
if len(os.Args) != 3 {
log.Fatal("Usage: Missing arguments: [dayXX] [input].txt")
}
switch os.Args[1] {
}
}

28
utils/perf.go

@ -0,0 +1,28 @@
package utils
import (
"log"
"os"
"time"
)
func Perf(date string, parse func(string), solve1 func(), solve2 func()) {
// Store time to print out execution time
start := time.Now()
log.Printf("%s: Starting program to solve %s\n", date, date)
parse(os.Args[2])
log.Printf("%s: Spent %s on parsing input\n", date, time.Since(start))
start = time.Now()
solve1()
log.Printf("%s.01: Spent %s on solving part 1\n", date, time.Since(start))
start = time.Now()
solve2()
log.Printf("%s.02: Spent %s on solving part 2\n", date, time.Since(start))
}

32
utils/readfile.go

@ -0,0 +1,32 @@
package utils
import (
"bufio"
"log"
"os"
)
func GetLinesFromFile(name string) []string {
var rows []string
// Get file handler
fh, err := os.Open(name)
defer fh.Close()
if err != nil {
log.Fatal("Failed to open file:", err)
}
// Parse file
scanner := bufio.NewScanner(fh)
for scanner.Scan() {
rows = append(rows, scanner.Text())
}
// Print eventual error from parsing the file
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return rows
}
Loading…
Cancel
Save