package day20 import ( "testing" "gitea.paas.celticinfo.fr/oabrivard/aoc2023/utils" ) func TestParseModule(t *testing.T) { lines := []string{ `broadcaster -> a, b, c`, `%a -> b`, `%b -> c`, `%c -> inv`, `&inv -> a`, } result := parseModules(lines) if len(result) != 5 { t.Fatalf("expected 5, got %d", len(result)) } } func Test1Part1(t *testing.T) { lines := []string{ `broadcaster -> a, b, c`, `%a -> b`, `%b -> c`, `%c -> inv`, `&inv -> a`, } result, count := Part1(lines, 1) if count != 32 { t.Fatalf("expected 32, got %d", count) } if result["a"].status || result["b"].status || result["c"].status { t.Fatalf("expected flip-flop a, b and c to be off, got %v %v %v", result["a"].status, result["b"].status, result["c"].status) } } func Test2Part1(t *testing.T) { lines := []string{ `broadcaster -> a, b, c`, `%a -> b`, `%b -> c`, `%c -> inv`, `&inv -> a`, } _, count := Part1(lines, 1000) if count != 32000000 { t.Fatalf("expected 32000000, got %d", count) } } func Test3Part1(t *testing.T) { lines := []string{ "broadcaster -> a", "%a -> inv, con", "&inv -> b", "%b -> con", "&con -> output", } result, _ := Part1(lines, 3) if !result["output"].status || !result["a"].status || result["b"].status { t.Fatalf("expected flip-flop a to be on, b to be off and output to be on, got %v %v %v", result["a"].status, result["b"].status, result["output"].status) } result, _ = Part1(lines, 4) if !result["output"].status || result["a"].status || result["b"].status { t.Fatalf("expected flip-flop a and b to be off and output to be on, got %v %v %v", result["a"].status, result["b"].status, result["output"].status) } } func Test4Part1(t *testing.T) { lines := []string{ "broadcaster -> a", "%a -> inv, con", "&inv -> b", "%b -> con", "&con -> output", } _, count := Part1(lines, 1000) if count != 11687500 { t.Fatalf("expected 11687500, got %d", count) } } func TestPart1WithInput(t *testing.T) { lines := utils.ReadLines("input.txt") _, count := Part1(lines, 1000) if count != 925955316 { t.Fatalf("expected 925955316, got %d", count) } } func TestPart2WithInput(t *testing.T) { lines := utils.ReadLines("input.txt") Part2(lines, 5000) // use firt four different values printed during simulation that starts with "qn from" // then find the LCM of the values. The LCM is the solution to this problem. // Found it thanks to explanation from jwezorek and JuniorBirdman1115 on // https://www.reddit.com/r/adventofcode/comments/18mmfxb/2023_day_20_solutions/ /* qn from jx : 3907 qn from qz : 3911 qn from tt : 3931 qn from cq : 4021 LCM is 241528477694627 (computed it with https://www.calculatorsoup.com/calculators/math/lcm.php) */ }