-
Notifications
You must be signed in to change notification settings - Fork 0
/
03p1.go
51 lines (38 loc) · 1.06 KB
/
03p1.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
package main
import (
"fmt"
"aoc2022/utils"
)
func D03P1() {
lines := utils.ReadLines("./inputs/03.txt")
priorityTotal := 0
var rucksacks []map[string]string
for _, line := range lines {
halfLine := len(line) / 2
rucksack := make(map[string]string)
rucksack["CompartmentOne"] = line[:halfLine]
rucksack["CompartmentTwo"] = line[halfLine:]
for _, compartmentOneItem := range rucksack["CompartmentOne"] {
if rucksack["SharedItem"] != "" {
continue
}
for _, compartmentTwoItem := range rucksack["CompartmentTwo"] {
if compartmentOneItem != compartmentTwoItem {
continue
}
rucksack["SharedItem"] = string(compartmentOneItem)
// Print Items numberic value
itemPriority := compartmentOneItem - 96
// Check if item is uppercase
if itemPriority < 0 {
itemPriority = itemPriority + 58
}
priorityTotal += int(itemPriority)
rucksack["SharedItemPriority"] = fmt.Sprintf("%v", itemPriority)
break
}
}
rucksacks = append(rucksacks, rucksack)
}
fmt.Printf("Priority Total: %v\n", priorityTotal)
}