Compare commits

...

2 Commits

Author SHA1 Message Date
021d16cfd7 test: Add unit test for PartTwo 2025-11-25 22:28:33 +01:00
d13ed719e1 feat: complete PartTwo 2025-11-25 22:28:25 +01:00
2 changed files with 53 additions and 8 deletions

View File

@@ -50,7 +50,36 @@ func PartOne(input []string) int {
return maxSeatID
}
func PartTwo(input []string) int {
seatIDs := make(map[int]bool)
minSeatID := 1000
maxSeatID := 0
for _, pass := range input {
if len(pass) < 10 {
continue
}
seatID := calculateSeatID(pass)
seatIDs[seatID] = true
if seatID < minSeatID {
minSeatID = seatID
}
if seatID > maxSeatID {
maxSeatID = seatID
}
}
for seatID := minSeatID + 1; seatID < maxSeatID; seatID++ {
if !seatIDs[seatID] && seatIDs[seatID-1] && seatIDs[seatID+1] {
return seatID
}
}
return 0
}
func main() {
input := parseInput("input.txt")
fmt.Println("Part 1:", PartOne(input))
fmt.Println("Part 2:", PartTwo(input))
}

View File

@@ -2,17 +2,33 @@ package main
import "testing"
var testInput = []string{
"FBFBBFFRLR",
"BFFFBBFRRR",
"FFFBBBFRRR",
"BBFFBBFRLL",
}
func TestPartOne(t *testing.T) {
input := []string{
"FBFBBFFRLR",
"BFFFBBFRRR",
"FFFBBBFRRR",
"BBFFBBFRLL",
}
expected := 820
got := PartOne(testInput)
got := PartOne(input)
if got != expected {
t.Errorf("PartOne() = %d, want %d", got, expected)
}
}
func TestPartTwo(t *testing.T) {
input := []string{
"FFFFFFFLLL",
"FFFFFFFLLR",
"FFFFFFFLRL",
"FFFFFFFLRR",
"FFFFFFFRLR",
"FFFFFFFRRL",
"FFFFFFFRRR",
}
expected := 4
got := PartTwo(input)
if got != expected {
t.Errorf("PartTwo() = %d, want %d", got, expected)
}
}