advent hell
This commit is contained in:
parent
9e937d19df
commit
ba6e3749f5
|
@ -34,14 +34,20 @@ func main() {
|
|||
fmt.Println("Part 1:", counts[1] * counts[3])
|
||||
// Part 2: Find number of skippable adapters
|
||||
skippable := 0
|
||||
for i, _ := range ints {
|
||||
if !(i == 0 || i+1 == len(ints)) { // The first and last cannot be removed
|
||||
if ints[i+1] - ints[i-1] <= 3 {
|
||||
skippable += 1
|
||||
}
|
||||
}
|
||||
// Get number of possible skips. Dropping can only happen with multiple 1s in a row.
|
||||
// Find run-lengths of 1s, add that -1 to the skippables.
|
||||
run := 0
|
||||
for _, g := range gaps {
|
||||
if g == 1 {
|
||||
run += 1
|
||||
} else {
|
||||
skippable += (run-1)
|
||||
run = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fmt.Println(gaps)
|
||||
fmt.Println(skippable)
|
||||
fmt.Println(ints)
|
||||
fmt.Printf("Part 2: %f\n", math.Pow(2, float64(skippable))-1) // All possible combinations for n, according to wikipedia
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue