Day 2 Part 1
This commit is contained in:
parent
32e35cd824
commit
ccee86dc80
9 changed files with 279 additions and 0 deletions
1
day_2/test/calibration.txt
Normal file
1
day_2/test/calibration.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124
|
||||
115
day_2/test/day_2_test.gleam
Normal file
115
day_2/test/day_2_test.gleam
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import day_2
|
||||
import gleeunit
|
||||
|
||||
pub fn main() -> Nil {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
pub fn trivial_digits_test() {
|
||||
assert day_2.int_to_half_length_pair(1) == Ok(#([], [1]))
|
||||
}
|
||||
|
||||
pub fn two_digit_number_test() {
|
||||
assert day_2.int_to_half_length_pair(12) == Ok(#([1], [2]))
|
||||
}
|
||||
|
||||
pub fn ten_digit_number_test() {
|
||||
assert day_2.int_to_half_length_pair(1_234_567_890)
|
||||
== Ok(#([1, 2, 3, 4, 5], [6, 7, 8, 9, 0]))
|
||||
}
|
||||
|
||||
pub fn eleven_digit_number_test() {
|
||||
assert day_2.int_to_half_length_pair(12_345_678_901)
|
||||
== Ok(#([1, 2, 3, 4, 5], [6, 7, 8, 9, 0, 1]))
|
||||
}
|
||||
|
||||
pub fn bad_number_test() {
|
||||
assert day_2.int_is_doubled_string(123_123) == Ok(True)
|
||||
}
|
||||
|
||||
pub fn good_number_test() {
|
||||
assert day_2.int_is_doubled_string(123_456) == Ok(False)
|
||||
}
|
||||
|
||||
pub fn list_of_ranges_test() {
|
||||
assert day_2.ranges_to_list_of_ids([#(10, 20), #(30, 40)])
|
||||
== [
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
30,
|
||||
31,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35,
|
||||
36,
|
||||
37,
|
||||
38,
|
||||
39,
|
||||
40,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn ranges_with_bad_ids_test() {
|
||||
assert day_2.ranges_to_bad_ids([
|
||||
#(11, 22),
|
||||
#(95, 115),
|
||||
#(998, 1012),
|
||||
#(1_188_511_880, 1_188_511_890),
|
||||
#(222_220, 222_224),
|
||||
#(1_698_522, 1_698_528),
|
||||
#(446_443, 446_449),
|
||||
#(38_593_856, 38_593_862),
|
||||
])
|
||||
== [11, 22, 99, 1010, 1_188_511_885, 222_222, 446_446, 38_593_859]
|
||||
}
|
||||
|
||||
pub fn sum_of_bad_ids_test() {
|
||||
assert day_2.sum_of_bad_ids([
|
||||
#(11, 22),
|
||||
#(95, 115),
|
||||
#(998, 1012),
|
||||
#(1_188_511_880, 1_188_511_890),
|
||||
#(222_220, 222_224),
|
||||
#(1_698_522, 1_698_528),
|
||||
#(446_443, 446_449),
|
||||
#(38_593_856, 38_593_862),
|
||||
])
|
||||
== 1_227_775_554
|
||||
}
|
||||
|
||||
pub fn range_parse_test() {
|
||||
assert day_2.range_string_to_int_pair("111-333") == #(111, 333)
|
||||
}
|
||||
|
||||
pub fn ranges_parse_test() {
|
||||
let ranges =
|
||||
"11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124"
|
||||
assert day_2.list_of_ranges_to_int_pairs(ranges)
|
||||
== [
|
||||
#(11, 22),
|
||||
#(95, 115),
|
||||
#(998, 1012),
|
||||
#(1_188_511_880, 1_188_511_890),
|
||||
#(222_220, 222_224),
|
||||
#(1_698_522, 1_698_528),
|
||||
#(446_443, 446_449),
|
||||
#(38_593_856, 38_593_862),
|
||||
#(565_653, 565_659),
|
||||
#(824_824_821, 824_824_827),
|
||||
#(2_121_212_118, 2_121_212_124),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn calibrate() {
|
||||
assert day_2.file_to_sum_of_bad_ids("test/calibration.txt") == 1_227_775_554
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue