Compare commits
2 commits
40fd202244
...
5ce9c707d3
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ce9c707d3 | |||
| c851361c45 |
4 changed files with 66 additions and 11 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
input.txt
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82
|
||||
|
|
@ -1 +0,0 @@
|
|||
197-407,262128-339499,557930-573266,25-57,92856246-93001520,2-12,1919108745-1919268183,48414903-48538379,38342224-38444598,483824-534754,1056-1771,4603696-4688732,75712519-75792205,20124-44038,714164-782292,4429019-4570680,9648251-9913729,6812551522-6812585188,58-134,881574-897488,648613-673853,5261723647-5261785283,60035-128980,9944818-10047126,857821365-857927915,206885-246173,1922-9652,424942-446151,408-1000
|
||||
65
2025/3/main.go
Normal file
65
2025/3/main.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// iterate over all IDs
|
||||
joltages := Decode("input.txt")
|
||||
|
||||
var joltagessum int = 0
|
||||
|
||||
for _, i := range joltages {
|
||||
var tensColumn int = 0
|
||||
var onesColumn int = 0
|
||||
|
||||
for iteration, x := range i {
|
||||
num, err := strconv.Atoi(string(x))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if tensColumn == 0 {
|
||||
tensColumn = num
|
||||
} else if num > tensColumn && iteration != len(i)-1 {
|
||||
tensColumn = num
|
||||
onesColumn = 0
|
||||
} else if num > onesColumn && onesColumn >= tensColumn {
|
||||
tensColumn = onesColumn
|
||||
onesColumn = num
|
||||
} else if num > onesColumn {
|
||||
onesColumn = num
|
||||
}
|
||||
}
|
||||
|
||||
sum := tensColumn*10 + onesColumn
|
||||
fmt.Printf("joltage found for %s, %d%d %d\n", i, tensColumn, onesColumn, sum)
|
||||
joltagessum = joltagessum + sum
|
||||
}
|
||||
|
||||
fmt.Println("total joltage sum", joltagessum)
|
||||
}
|
||||
|
||||
func Decode(filename string) []string {
|
||||
f, err := os.Open(filename)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
var joltages []string
|
||||
|
||||
for scanner.Scan() {
|
||||
// extract joltage numbers into struct to go over
|
||||
joltages = append(joltages, scanner.Text())
|
||||
}
|
||||
|
||||
return joltages
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue