-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.go
58 lines (49 loc) · 876 Bytes
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/pkg/errors"
)
func catch(err error, args ...interface{}) {
if err == nil {
return
}
if len(args) > 0 {
panic(errors.Wrap(err, fmt.Sprintf(args[0].(string), args[1:]...)))
}
panic(err)
}
func Input() string {
file := "input.txt"
if len(os.Args) > 1 {
file = os.Args[1]
}
input, err := os.ReadFile(file)
catch(err)
return strings.TrimSpace(string(input))
}
func Lines(input string) []string {
return strings.Split(input, "\n")
}
func Ints(lines []string) []int {
var err error
ints := make([]int, len(lines))
for i, line := range lines {
ints[i], err = strconv.Atoi(line)
catch(err, "line %d", i)
}
return ints
}
func main() {
ints := Ints(Lines(Input()))
// Part 1
{
fmt.Printf("Part 1: %d\n", ints[0])
}
// Part 2
{
// fmt.Printf("Part 2: %d\n", ints[0])
}
}