test_file <- create_test_file("be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce")
input <- read_digits(test_file)
test_that(test_name(day = 8, part = 1), {
patterns <- lapply(input, \(x) x$patterns)
digits <- sapply(input, \(x) x$digits)
counts <- lapply(digits, function(d) sapply(d, nchar)) |> unlist()
expect_true(sum(counts == 2 | counts == 3 | counts == 4 | counts == 7) == 26)
})
test_that(test_name(day = 8, part = 2), {
result <- sapply(input, assign_digits) |> sum()
expect_true(result == 61229)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.