Compare commits
No commits in common. "5ce9c707d38a3fddf5ad9c312e38d1f7b943577d" and "40fd20224473cccc49cafee598593b4fb9ace8ec" have entirely different histories.
5ce9c707d3
...
40fd202244
4 changed files with 11 additions and 66 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
input.txt
|
|
||||||
10
2025/1/input.txt
Normal file
10
2025/1/input.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
1
2025/2/input.txt
Normal file
1
2025/2/input.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
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
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
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