day04 part 1

This commit is contained in:
Gabe Venberg 2023-12-04 11:08:53 -06:00
parent 5bd1d16259
commit 436f6c56c3
8 changed files with 430 additions and 0 deletions

15
Cargo.lock generated
View file

@ -15,6 +15,12 @@ dependencies = [
name = "aoc_libs"
version = "0.1.0"
[[package]]
name = "collection_literals"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186dce98367766de751c42c4f03970fc60fc012296e706ccbb9d5df9b6c1e271"
[[package]]
name = "day01"
version = "0.1.0"
@ -32,6 +38,15 @@ dependencies = [
"nom",
]
[[package]]
name = "day04"
version = "0.1.0"
dependencies = [
"aoc_libs",
"collection_literals",
"nom",
]
[[package]]
name = "memchr"
version = "2.6.4"

View file

@ -19,3 +19,4 @@ regex = "1"
once_cell = "1.16"
thiserror = "1.0"
nom = "7.1"
collection_literals = "1.0.1"

11
days/day04/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "day04"
authors.workspace = true
description.workspace = true
version.workspace = true
edition.workspace = true
[dependencies]
aoc_libs.workspace = true
nom.workspace = true
collection_literals.workspace = true

193
days/day04/src/input.txt Normal file
View file

@ -0,0 +1,193 @@
Card 1: 17 15 5 75 36 13 16 66 92 39 | 13 92 16 5 87 78 15 94 21 48 30 62 70 41 3 39 22 17 77 58 75 52 83 34 24
Card 2: 72 64 18 5 58 94 25 59 75 51 | 34 17 48 75 25 8 2 94 64 29 33 92 73 12 51 38 27 4 1 60 31 85 59 18 5
Card 3: 71 16 97 6 68 38 82 93 33 24 | 31 75 7 99 10 70 79 61 5 80 1 33 58 30 22 48 73 72 50 16 56 4 98 43 3
Card 4: 68 80 44 96 43 20 11 18 85 48 | 96 99 38 29 36 28 77 68 47 70 98 80 63 65 11 12 43 3 54 92 18 90 58 16 51
Card 5: 27 61 28 60 50 59 43 96 85 9 | 3 45 14 55 39 6 93 82 96 31 70 22 8 98 88 46 72 9 79 28 23 81 87 15 30
Card 6: 32 69 24 83 40 39 19 42 17 11 | 68 26 28 71 22 50 64 20 53 82 7 36 58 78 73 51 6 48 97 30 99 61 84 34 5
Card 7: 99 14 25 95 31 62 1 65 59 30 | 8 9 58 73 6 2 44 11 43 4 34 70 78 90 16 24 23 39 30 69 74 59 91 84 42
Card 8: 88 48 85 67 73 33 96 57 47 86 | 35 17 85 97 46 50 77 23 4 31 76 34 12 59 14 42 72 64 44 96 90 65 73 69 88
Card 9: 99 17 38 77 73 71 59 86 11 97 | 60 14 19 4 6 78 51 48 87 36 88 66 30 13 94 45 97 69 62 40 47 32 7 77 57
Card 10: 82 35 83 64 60 84 67 62 24 77 | 93 32 7 12 84 24 94 43 65 44 17 45 38 62 80 95 77 26 73 28 91 57 60 55 4
Card 11: 9 95 29 15 88 33 58 49 83 45 | 31 38 55 62 86 60 21 97 74 53 94 19 40 50 77 26 63 43 3 52 85 8 73 35 42
Card 12: 54 33 34 57 29 64 40 30 3 11 | 78 86 92 70 91 93 32 79 12 13 97 63 28 66 77 85 51 36 35 3 4 23 30 11 42
Card 13: 16 49 93 29 96 23 64 57 3 42 | 56 11 53 20 72 67 26 5 4 63 8 70 97 52 6 81 62 80 12 98 33 35 77 84 58
Card 14: 20 32 49 55 63 74 33 51 66 40 | 43 29 70 48 61 13 96 73 67 27 15 6 46 56 45 30 97 76 1 77 12 26 39 78 42
Card 15: 65 67 7 43 83 36 24 46 16 29 | 76 12 69 27 26 71 84 11 22 86 33 63 50 49 14 40 6 4 47 34 90 21 19 74 97
Card 16: 78 43 11 21 53 35 86 85 27 68 | 98 43 53 66 52 62 21 91 81 69 93 76 73 86 17 31 27 40 85 12 68 83 65 36 71
Card 17: 52 55 3 69 20 96 57 67 10 38 | 91 16 3 30 52 34 78 71 55 36 48 89 79 20 37 69 67 57 18 68 46 10 25 38 96
Card 18: 23 46 90 44 85 19 49 30 8 43 | 72 34 75 48 74 33 88 41 78 65 98 60 3 19 26 63 69 83 89 21 66 5 37 53 58
Card 19: 69 24 83 60 59 45 51 74 93 34 | 45 83 1 8 28 60 27 38 81 36 69 24 73 90 88 59 93 16 98 34 74 48 10 61 51
Card 20: 41 83 4 44 28 90 16 69 86 88 | 7 41 28 4 5 73 97 30 70 88 69 2 38 55 86 60 14 83 16 90 15 49 78 44 27
Card 21: 41 61 99 59 48 8 26 92 19 85 | 35 17 49 14 94 6 29 43 55 88 63 26 13 53 66 67 8 32 18 24 7 70 86 96 38
Card 22: 57 29 37 75 42 88 68 67 92 18 | 8 6 54 77 75 18 68 26 67 87 92 31 72 29 37 21 42 17 88 93 84 57 9 63 66
Card 23: 70 3 75 17 64 68 53 45 23 10 | 27 7 59 68 97 72 64 30 61 29 86 45 63 53 17 3 44 87 23 75 70 10 15 4 43
Card 24: 89 81 36 9 73 27 31 8 77 11 | 14 71 9 87 47 39 26 29 24 74 42 58 17 51 19 68 32 46 52 78 64 12 35 45 72
Card 25: 82 3 92 95 29 14 52 41 15 98 | 21 17 51 55 77 34 72 59 78 30 5 58 92 4 85 15 91 75 26 53 25 94 7 90 22
Card 26: 51 55 33 59 66 42 43 92 85 96 | 2 66 92 24 50 33 63 96 54 51 13 1 42 98 73 88 57 84 94 7 93 78 59 43 55
Card 27: 19 80 30 31 15 4 65 13 66 29 | 93 75 36 26 5 14 21 49 97 43 96 54 45 57 25 55 71 95 1 27 60 61 9 59 34
Card 28: 57 79 99 54 72 18 33 34 87 1 | 56 99 55 17 87 80 72 79 88 31 38 63 42 33 10 23 76 4 67 21 98 68 93 57 65
Card 29: 85 26 24 34 21 35 49 92 89 73 | 70 39 73 44 67 50 43 63 4 82 14 64 22 25 2 41 8 36 89 10 54 79 87 40 6
Card 30: 21 33 62 4 57 9 50 49 95 13 | 12 84 86 49 26 42 20 37 30 57 44 96 62 6 4 65 15 59 60 73 19 28 89 39 55
Card 31: 7 61 76 92 70 15 45 71 98 20 | 4 33 26 63 73 52 7 3 62 60 89 28 86 55 45 90 41 83 74 31 48 27 11 65 72
Card 32: 9 35 67 79 85 46 14 42 84 45 | 63 51 64 5 81 70 36 47 33 30 54 83 85 34 35 32 1 79 7 96 82 28 3 89 91
Card 33: 76 48 44 64 41 62 4 25 11 8 | 15 22 10 80 59 82 89 81 2 57 31 25 50 34 53 39 86 19 47 95 23 30 88 91 51
Card 34: 17 12 86 82 70 16 19 11 42 57 | 78 49 72 18 25 35 58 81 26 6 84 87 67 60 61 13 53 56 4 14 90 11 29 34 33
Card 35: 16 65 64 28 25 50 73 95 20 10 | 6 4 12 77 41 98 2 74 29 15 52 91 83 49 14 40 69 88 82 22 21 89 9 70 90
Card 36: 68 38 59 63 30 32 14 97 77 17 | 6 23 49 75 12 76 58 22 74 29 24 48 56 54 41 26 69 90 70 93 66 42 78 33 60
Card 37: 49 37 88 55 20 95 11 86 53 18 | 53 95 18 80 25 2 88 17 11 20 22 63 45 70 55 37 86 81 28 61 47 74 49 79 48
Card 38: 82 38 13 70 48 52 91 6 46 47 | 6 91 78 43 16 48 61 29 80 92 82 13 44 90 9 87 40 54 52 46 58 38 70 65 47
Card 39: 82 50 67 89 49 18 24 93 98 76 | 95 61 1 91 52 86 89 53 38 98 44 67 50 49 33 66 21 18 93 82 60 76 40 24 19
Card 40: 15 34 17 87 51 5 98 26 71 99 | 15 40 70 98 96 1 45 14 94 28 39 87 56 51 89 17 77 64 26 5 99 71 83 27 34
Card 41: 1 98 55 28 10 14 57 62 88 96 | 96 52 8 34 88 41 73 23 16 43 98 45 55 97 1 14 28 10 62 81 33 57 32 53 99
Card 42: 98 75 42 34 59 41 11 69 45 44 | 28 98 54 65 41 51 16 49 45 60 44 69 82 37 67 46 34 71 78 61 50 43 38 90 85
Card 43: 42 98 96 75 68 2 23 36 37 40 | 93 59 36 33 16 68 24 42 13 75 53 2 6 86 1 98 23 70 89 5 37 40 96 84 39
Card 44: 44 31 83 28 66 80 84 17 73 65 | 39 73 95 33 74 66 31 28 17 2 65 12 84 91 83 15 22 44 53 90 29 56 80 57 69
Card 45: 13 90 67 40 48 54 52 53 64 9 | 17 57 67 65 45 30 95 96 3 18 52 90 7 98 21 73 8 92 59 75 5 13 6 76 64
Card 46: 95 21 68 93 77 40 47 48 20 31 | 74 90 43 4 41 40 24 72 2 56 88 44 38 45 15 29 79 46 17 39 75 42 69 92 49
Card 47: 25 87 64 94 99 47 29 34 89 23 | 29 25 99 58 94 7 33 6 34 36 76 5 39 64 56 87 17 52 47 50 89 16 91 23 69
Card 48: 37 75 82 29 91 2 85 23 76 80 | 23 33 80 85 89 46 94 15 2 43 51 62 91 79 37 76 29 56 40 26 9 63 75 82 31
Card 49: 99 80 21 7 14 27 24 13 76 70 | 36 32 16 28 30 37 73 59 42 47 40 29 19 84 18 23 79 44 93 45 87 62 60 69 65
Card 50: 89 87 92 61 59 58 90 24 70 22 | 3 81 53 61 55 82 52 85 66 44 74 98 6 56 33 13 63 25 65 67 47 26 35 27 64
Card 51: 65 15 62 72 92 57 1 87 55 86 | 1 47 49 98 93 38 53 68 96 59 11 4 52 84 86 94 51 13 95 29 65 16 91 45 54
Card 52: 3 72 69 39 77 36 55 13 56 95 | 35 61 77 36 40 65 64 13 58 27 55 12 94 66 42 37 5 78 62 84 56 39 69 95 48
Card 53: 78 57 27 16 17 55 59 56 73 40 | 65 31 20 18 64 89 44 52 92 11 62 76 13 48 72 79 94 8 82 77 5 74 30 46 98
Card 54: 22 17 28 78 59 87 52 47 41 2 | 74 94 38 25 58 89 20 99 71 14 86 95 10 63 18 35 24 67 85 80 7 50 6 33 72
Card 55: 78 83 54 87 55 68 77 38 34 48 | 87 23 51 75 83 86 43 93 18 34 53 56 76 72 29 27 45 85 89 36 65 84 19 88 39
Card 56: 50 89 10 79 86 37 27 16 56 54 | 2 59 91 50 8 39 90 46 37 36 27 15 10 9 85 92 83 35 45 74 19 61 63 17 96
Card 57: 50 39 84 22 17 73 57 77 80 85 | 8 57 15 74 38 83 32 67 99 28 63 16 30 49 75 26 55 48 47 91 33 14 62 21 20
Card 58: 63 26 97 45 9 24 65 66 59 14 | 42 81 39 62 45 46 23 49 98 34 72 64 17 11 96 15 6 88 78 93 20 33 66 95 37
Card 59: 46 91 3 4 70 21 2 13 19 10 | 95 56 84 16 66 7 91 11 69 89 87 29 60 47 37 40 15 55 38 80 20 81 23 64 18
Card 60: 32 65 89 23 54 36 49 18 26 78 | 16 11 14 20 76 33 72 45 94 87 85 2 74 99 3 67 57 37 75 96 82 95 73 77 52
Card 61: 41 42 4 27 89 64 80 28 35 92 | 97 50 88 13 19 45 49 42 85 36 4 92 29 80 77 47 91 27 46 89 68 16 35 11 28
Card 62: 30 27 17 63 59 11 78 74 75 57 | 88 57 5 61 1 56 24 99 10 39 48 15 89 82 95 9 45 71 54 83 3 28 27 98 91
Card 63: 86 91 21 10 84 47 83 62 90 35 | 11 16 90 10 31 84 36 74 89 5 35 47 21 40 62 63 77 67 65 83 91 86 70 85 44
Card 64: 39 55 92 80 17 2 66 97 33 70 | 92 22 85 6 88 4 46 57 71 40 89 15 49 48 66 11 93 28 37 5 30 23 27 98 43
Card 65: 62 94 36 40 23 61 34 46 47 63 | 6 44 23 74 97 96 62 94 61 46 93 34 47 31 87 54 26 67 56 40 27 81 63 99 36
Card 66: 64 45 78 34 32 29 62 84 90 28 | 42 6 80 66 10 13 41 55 50 40 72 90 25 24 93 98 46 73 52 14 61 86 49 89 71
Card 67: 9 89 2 82 42 8 78 90 59 7 | 69 55 58 2 95 78 43 26 11 75 50 22 44 4 9 59 82 68 19 32 63 49 35 42 45
Card 68: 72 9 87 26 17 43 58 8 45 74 | 8 85 9 7 73 21 92 74 28 5 33 25 50 60 26 1 65 78 24 69 87 19 46 58 67
Card 69: 51 69 81 71 32 59 85 29 39 5 | 68 16 31 47 29 86 50 62 98 14 22 80 56 91 35 49 51 21 36 67 52 6 15 48 58
Card 70: 67 1 31 29 16 71 69 54 15 11 | 91 49 76 87 14 13 58 23 19 20 82 48 98 79 66 35 38 22 67 96 43 55 52 92 12
Card 71: 73 20 52 53 61 17 87 78 82 37 | 28 21 95 74 77 58 25 84 68 75 47 49 9 18 65 51 63 12 56 50 98 23 57 69 90
Card 72: 39 66 35 93 62 28 9 13 56 30 | 29 1 39 54 10 33 40 99 91 65 16 28 37 23 77 43 61 64 11 55 69 85 63 47 78
Card 73: 9 10 84 56 6 14 54 36 94 61 | 89 33 88 23 87 46 47 31 55 29 69 90 11 65 19 84 35 2 32 95 80 12 3 7 50
Card 74: 59 27 84 1 11 63 39 57 62 65 | 41 75 83 51 13 91 93 79 66 23 70 86 16 52 26 50 72 5 48 80 74 47 38 97 8
Card 75: 38 65 93 30 12 64 31 10 37 81 | 8 76 72 3 52 89 32 60 73 40 85 55 49 43 45 42 83 58 61 47 86 67 82 94 50
Card 76: 26 83 4 70 88 7 50 34 36 76 | 64 49 4 77 83 39 34 50 79 24 22 6 70 85 7 75 80 26 38 36 68 63 29 17 88
Card 77: 31 97 45 39 24 5 87 26 75 15 | 38 36 10 57 39 8 45 74 24 94 31 17 25 27 92 75 60 87 12 26 69 15 70 63 7
Card 78: 44 21 15 91 62 67 47 24 95 90 | 26 1 62 42 71 43 91 95 59 37 16 3 56 14 21 15 17 87 86 51 39 19 46 36 4
Card 79: 67 84 14 87 21 22 91 17 88 72 | 92 82 94 31 85 54 55 93 46 35 77 67 74 96 36 50 68 19 3 40 15 69 72 6 49
Card 80: 11 36 90 64 51 31 83 30 18 69 | 36 86 90 43 8 3 65 49 31 78 30 18 79 52 51 88 80 63 24 77 16 1 13 83 55
Card 81: 47 2 72 59 87 30 58 68 63 61 | 55 49 42 39 99 94 50 72 90 54 29 37 21 41 48 8 82 7 63 30 62 70 87 26 14
Card 82: 22 17 64 40 89 67 83 71 43 50 | 89 12 52 32 42 78 38 3 51 26 2 67 96 81 77 13 48 7 73 28 62 1 82 22 24
Card 83: 53 4 35 89 23 36 8 92 32 49 | 35 52 92 73 23 64 80 32 53 4 65 20 42 31 8 39 89 95 62 44 45 77 36 68 49
Card 84: 86 48 90 55 79 57 31 40 3 74 | 85 67 62 4 33 23 60 43 19 14 32 34 6 56 59 9 87 47 54 26 88 66 65 41 11
Card 85: 82 66 31 3 87 19 89 57 59 8 | 15 8 31 58 53 22 89 59 63 96 40 85 3 82 35 33 49 30 75 87 66 64 83 57 19
Card 86: 22 4 55 97 13 54 65 51 86 9 | 11 73 5 63 36 23 27 13 15 75 22 85 38 99 54 44 32 41 12 47 82 51 8 77 17
Card 87: 27 91 1 77 75 8 76 99 88 85 | 55 46 50 2 4 27 54 10 89 3 14 91 22 75 13 77 8 6 76 69 44 19 88 1 99
Card 88: 54 96 19 2 73 48 50 82 18 23 | 95 12 16 73 35 48 60 31 50 98 19 17 32 47 2 55 44 93 11 41 23 82 74 9 51
Card 89: 91 89 35 65 33 19 94 76 77 45 | 99 32 96 64 31 44 45 80 71 51 83 97 21 5 20 35 40 93 39 54 29 56 23 70 66
Card 90: 31 87 35 2 89 24 59 13 4 15 | 18 87 65 59 71 31 98 26 68 96 3 13 80 36 25 47 2 4 7 37 92 83 73 23 58
Card 91: 28 85 49 44 87 17 56 74 25 53 | 96 23 18 27 17 72 84 29 32 85 91 86 62 94 55 49 37 56 28 59 78 88 25 1 30
Card 92: 1 94 54 67 51 21 79 6 93 5 | 9 51 13 91 68 59 19 41 76 20 57 55 54 72 48 21 83 95 44 56 71 80 28 85 25
Card 93: 53 86 2 60 56 18 21 22 63 59 | 79 86 73 9 32 80 7 76 26 63 48 17 90 36 91 31 69 50 49 87 37 43 92 10 55
Card 94: 91 59 76 78 48 56 7 51 52 97 | 36 15 31 62 65 64 34 79 92 53 29 60 9 3 75 26 14 46 59 35 85 52 2 77 67
Card 95: 59 49 67 43 82 13 19 7 58 69 | 5 65 21 86 4 3 64 72 51 94 73 88 78 98 28 85 29 96 36 1 97 37 89 62 58
Card 96: 95 88 64 65 12 15 3 50 44 79 | 53 72 74 60 22 7 75 19 10 3 49 23 33 29 57 31 82 84 16 37 32 21 77 28 47
Card 97: 3 85 7 2 51 27 67 32 46 9 | 60 45 11 49 13 62 76 56 63 1 37 96 20 55 24 89 31 50 19 10 6 72 30 38 54
Card 98: 25 92 5 7 90 2 84 79 34 65 | 30 20 86 33 63 84 65 92 38 5 43 12 2 73 98 81 82 94 51 25 88 75 54 22 15
Card 99: 59 57 36 90 26 81 15 78 49 2 | 81 26 91 47 77 46 65 59 90 57 72 99 2 98 15 5 78 36 49 63 45 9 16 92 64
Card 100: 18 9 41 19 57 82 73 48 62 2 | 41 42 3 82 73 83 91 48 94 96 20 9 19 90 45 54 13 67 62 44 37 51 18 2 57
Card 101: 56 35 62 52 89 60 19 71 15 50 | 60 21 39 71 45 64 73 25 80 54 50 13 6 20 1 51 42 93 92 87 96 61 16 77 40
Card 102: 40 33 78 80 79 47 57 3 17 64 | 85 17 94 78 20 47 58 3 37 40 68 75 81 79 21 64 97 70 80 33 8 57 95 35 4
Card 103: 99 22 60 2 93 8 46 50 90 79 | 46 2 67 62 30 93 50 99 79 8 33 34 81 98 90 78 60 92 42 80 28 89 22 16 74
Card 104: 93 3 98 99 1 90 20 70 67 91 | 98 85 78 51 26 71 10 92 90 35 94 66 21 1 70 18 13 93 8 91 5 4 50 33 15
Card 105: 63 86 21 98 76 18 35 7 23 41 | 88 86 53 89 31 67 55 82 3 35 18 32 76 42 23 98 7 27 79 41 14 71 83 6 93
Card 106: 71 48 3 34 73 72 85 76 69 66 | 66 7 22 76 65 25 46 69 96 34 3 35 14 45 21 23 36 5 17 60 98 71 33 93 59
Card 107: 49 42 7 79 31 18 97 45 6 36 | 6 43 18 51 1 39 36 76 92 88 59 26 45 5 73 7 97 55 44 21 31 49 82 42 79
Card 108: 48 16 51 41 23 59 65 80 89 26 | 1 75 35 5 80 2 51 23 45 16 30 44 26 89 64 65 91 11 59 48 69 21 77 93 41
Card 109: 70 63 17 48 93 67 59 22 16 89 | 28 48 22 16 79 56 21 19 89 62 67 4 17 64 49 63 59 93 60 70 1 7 43 94 81
Card 110: 89 87 31 97 33 7 66 96 24 37 | 5 8 53 71 99 96 88 74 39 20 62 67 11 64 70 47 37 95 77 86 27 61 97 89 60
Card 111: 27 48 31 61 39 80 81 36 87 12 | 80 43 5 12 84 67 70 91 8 39 10 48 61 27 86 16 54 22 40 90 9 36 87 44 81
Card 112: 20 22 17 89 26 55 43 49 75 30 | 51 58 71 28 29 15 26 8 99 48 61 4 54 75 13 46 78 68 86 22 56 20 33 69 65
Card 113: 18 40 34 27 32 15 65 19 60 87 | 32 34 60 90 24 92 51 2 91 35 27 14 15 93 88 75 48 58 65 97 87 63 94 55 56
Card 114: 46 19 51 7 25 85 30 73 31 27 | 40 25 90 58 2 12 59 68 8 9 88 21 63 46 37 51 52 75 84 89 93 3 20 87 80
Card 115: 70 81 83 98 66 69 72 44 1 45 | 30 40 13 80 55 77 7 85 97 18 78 53 59 31 9 45 6 21 16 63 65 27 33 49 90
Card 116: 89 46 58 68 38 59 13 85 28 92 | 59 81 23 86 18 6 73 78 11 74 48 40 13 97 27 52 38 9 16 47 26 29 54 60 14
Card 117: 43 38 54 63 44 95 4 64 25 57 | 43 44 94 58 54 51 56 21 6 89 30 31 8 11 46 53 5 79 16 72 90 76 67 49 34
Card 118: 47 72 23 74 29 37 45 69 89 40 | 27 79 36 40 10 87 92 41 22 1 90 21 57 28 38 53 82 32 43 70 19 96 97 4 47
Card 119: 11 81 28 95 53 51 90 33 8 68 | 88 74 49 27 58 57 97 4 34 2 18 22 29 99 66 28 55 7 94 41 24 60 5 14 1
Card 120: 9 67 89 55 59 96 15 90 37 54 | 70 98 77 71 6 95 34 60 48 18 69 72 36 35 22 27 76 83 30 99 80 63 12 47 82
Card 121: 63 50 70 62 14 22 97 65 5 53 | 24 99 55 58 47 87 77 37 5 19 83 33 42 40 45 54 46 62 28 81 95 85 23 57 49
Card 122: 40 80 69 62 14 73 47 87 91 37 | 16 47 37 93 40 91 34 17 36 98 69 60 15 49 90 92 80 87 14 62 82 4 25 56 73
Card 123: 51 36 72 40 53 99 69 8 96 24 | 93 74 54 8 52 59 3 57 69 85 31 72 44 89 23 9 2 27 71 48 35 17 19 96 28
Card 124: 14 75 17 70 48 82 93 39 99 98 | 66 55 6 33 34 32 25 65 20 86 90 87 93 46 42 89 24 43 23 30 64 94 62 61 5
Card 125: 36 96 78 58 75 87 25 28 76 52 | 7 47 46 13 3 90 35 18 53 60 30 78 74 77 33 58 22 57 80 63 92 87 76 93 70
Card 126: 75 30 35 7 63 65 13 42 78 26 | 30 71 35 26 6 42 90 63 12 36 75 9 7 96 67 93 18 2 25 77 94 47 99 62 60
Card 127: 7 40 79 33 52 3 21 1 71 5 | 44 14 19 29 56 25 34 41 64 12 93 70 66 94 54 97 58 59 18 27 77 17 15 38 88
Card 128: 99 87 2 95 67 33 73 52 22 23 | 65 91 97 11 34 36 56 38 79 52 82 22 26 83 12 1 95 9 23 99 81 42 92 27 86
Card 129: 98 68 59 25 58 27 20 23 38 46 | 97 91 59 41 70 18 36 38 46 42 58 48 53 60 81 75 83 23 15 86 89 68 69 39 88
Card 130: 85 72 65 71 14 25 22 53 12 28 | 67 9 27 94 96 30 86 83 4 59 91 79 7 60 31 39 36 77 23 38 40 51 84 16 57
Card 131: 6 77 45 51 48 46 21 52 84 62 | 70 74 83 39 26 27 86 96 56 33 79 18 76 34 22 32 68 59 35 66 38 71 3 20 88
Card 132: 66 80 84 9 59 23 64 44 71 36 | 63 49 73 62 68 48 80 32 99 29 24 61 40 35 20 1 57 58 15 92 87 18 47 71 67
Card 133: 19 94 9 45 91 35 36 60 34 26 | 72 47 82 86 88 69 6 17 7 8 21 78 90 9 12 24 85 28 15 31 98 76 35 10 39
Card 134: 8 79 4 31 6 88 7 57 40 23 | 66 74 93 26 98 54 87 82 48 63 19 11 68 3 85 88 80 25 15 64 99 77 47 71 43
Card 135: 86 31 63 82 83 78 19 55 20 73 | 36 98 68 52 99 8 39 60 70 80 64 41 92 91 62 85 27 32 9 97 22 46 34 23 81
Card 136: 57 94 7 14 49 18 80 67 85 25 | 59 28 82 38 40 5 64 69 41 70 23 91 56 32 6 71 12 75 22 98 11 16 79 37 54
Card 137: 60 88 68 93 6 98 16 17 7 62 | 59 78 54 41 98 1 66 13 71 68 45 60 70 19 96 93 77 99 95 42 55 21 30 86 7
Card 138: 17 93 77 84 65 31 60 7 45 76 | 7 45 60 42 9 25 65 77 16 70 93 34 37 12 76 17 84 40 49 74 96 88 31 54 79
Card 139: 15 68 80 74 33 50 57 93 78 16 | 95 96 50 71 16 99 17 58 83 72 4 80 98 11 41 63 73 62 33 37 26 70 24 29 93
Card 140: 74 32 6 69 33 13 85 82 80 87 | 62 66 98 20 67 77 86 31 2 9 18 39 92 28 59 45 4 87 84 46 6 99 80 85 27
Card 141: 42 52 60 31 22 99 49 61 43 72 | 55 61 81 65 97 31 60 23 6 70 62 80 58 72 56 43 98 96 87 42 53 63 52 99 45
Card 142: 5 72 15 50 65 28 87 94 96 37 | 62 38 37 23 65 80 67 96 50 72 8 60 46 28 33 94 13 52 15 1 32 78 14 43 5
Card 143: 57 65 29 27 41 55 94 56 73 49 | 55 84 57 56 27 72 93 41 33 28 88 75 94 51 76 98 26 32 49 36 7 44 63 20 97
Card 144: 31 20 97 50 17 67 80 91 78 95 | 76 16 26 38 48 90 32 93 5 68 56 78 25 87 85 40 97 12 21 96 47 10 49 75 36
Card 145: 36 58 11 92 51 32 76 39 80 62 | 6 62 37 83 40 94 81 36 2 69 45 91 8 95 78 55 27 70 22 73 53 13 67 64 63
Card 146: 25 28 30 81 1 51 49 59 10 48 | 20 9 66 36 50 65 78 27 87 88 7 94 63 97 39 14 67 71 76 11 60 93 13 15 61
Card 147: 18 21 81 36 33 19 99 88 24 78 | 16 19 5 40 55 12 90 44 67 20 59 71 51 32 93 2 15 22 54 87 26 92 89 49 96
Card 148: 84 78 26 66 35 31 10 3 32 57 | 73 30 6 27 43 76 58 63 29 19 92 41 93 70 46 16 38 53 11 77 68 21 18 33 12
Card 149: 3 20 48 92 4 37 68 54 61 42 | 64 24 23 97 65 73 1 39 14 99 51 36 2 46 30 87 79 19 49 38 52 53 40 90 88
Card 150: 64 45 47 50 19 69 39 48 56 3 | 93 70 65 37 58 32 57 5 35 10 72 18 51 36 44 31 46 34 11 1 97 8 92 86 23
Card 151: 29 55 30 72 6 78 56 70 36 10 | 49 28 64 13 1 24 51 5 62 17 43 48 91 38 89 59 18 54 44 86 79 46 9 53 58
Card 152: 40 68 80 77 81 50 79 13 67 1 | 79 43 60 15 86 49 67 85 66 13 40 12 48 6 82 14 37 1 80 23 65 72 96 73 84
Card 153: 67 29 26 94 28 52 35 69 8 81 | 35 98 78 94 11 95 87 37 42 93 82 58 4 43 47 1 19 54 3 64 7 22 27 36 74
Card 154: 4 45 27 92 75 31 93 54 16 83 | 45 81 67 92 1 61 93 59 37 20 54 55 63 6 44 29 33 27 70 31 24 51 58 75 19
Card 155: 17 75 37 60 72 96 40 95 3 10 | 51 58 60 40 24 2 84 37 72 41 45 78 6 28 74 64 3 75 97 89 10 96 95 83 17
Card 156: 78 54 82 93 16 77 50 46 69 29 | 89 21 6 82 38 80 44 40 76 74 18 90 83 59 42 33 57 53 1 73 94 20 35 37 63
Card 157: 51 24 57 3 87 90 35 27 77 34 | 12 11 7 2 84 75 6 40 23 86 91 4 32 78 83 76 48 80 8 53 98 16 38 97 79
Card 158: 86 29 64 32 66 61 20 75 8 27 | 5 61 4 8 66 99 20 32 25 96 64 45 51 19 75 29 6 13 27 91 2 86 55 33 12
Card 159: 59 64 39 53 10 74 35 89 84 15 | 25 1 39 49 23 90 84 61 91 30 35 76 68 24 64 6 83 15 40 54 87 98 10 52 2
Card 160: 7 86 13 48 73 70 47 91 39 93 | 47 56 65 41 30 93 87 73 27 91 18 86 62 63 50 32 48 77 16 7 54 22 49 43 34
Card 161: 71 95 97 94 34 37 50 98 60 28 | 78 64 99 45 40 93 31 28 24 17 56 49 18 3 25 34 59 82 97 91 68 85 75 1 96
Card 162: 20 76 42 79 77 19 6 90 69 48 | 23 17 20 92 4 72 66 52 69 2 97 75 57 78 95 94 88 61 1 80 59 10 91 84 11
Card 163: 63 61 5 81 67 8 30 33 2 51 | 50 53 35 67 61 84 37 97 79 49 39 34 45 17 76 41 86 81 42 14 30 38 18 8 13
Card 164: 95 85 44 84 60 64 24 57 48 65 | 34 33 8 16 99 5 19 30 55 21 81 98 67 88 36 90 35 4 28 43 61 62 52 13 70
Card 165: 88 31 3 71 61 37 35 51 38 76 | 42 19 63 31 40 11 56 1 27 97 22 74 79 6 4 49 35 37 45 32 93 46 52 34 24
Card 166: 93 29 1 76 94 87 10 25 68 81 | 8 80 58 62 66 93 39 75 77 30 29 63 31 19 92 18 34 67 33 35 97 44 89 40 71
Card 167: 48 3 58 31 26 47 66 51 35 5 | 84 33 45 90 83 9 51 68 49 29 18 50 86 25 6 34 93 82 39 24 98 23 96 89 69
Card 168: 36 95 30 50 22 29 25 64 35 5 | 79 56 54 1 70 12 7 42 76 99 90 15 61 55 23 81 93 60 49 26 88 40 89 58 2
Card 169: 65 35 39 95 71 16 1 6 7 34 | 59 57 27 48 97 17 87 30 75 41 19 55 99 93 54 98 86 2 81 31 4 25 69 22 39
Card 170: 84 78 94 24 11 40 60 50 33 91 | 11 78 24 55 46 67 65 52 66 69 14 91 33 1 23 60 45 40 50 34 84 16 94 70 62
Card 171: 38 48 45 3 11 28 43 58 4 74 | 41 21 96 58 94 97 45 95 91 28 3 43 69 70 4 99 25 48 64 38 74 86 98 11 7
Card 172: 73 29 25 36 78 93 21 76 55 32 | 34 42 55 64 29 35 13 77 76 94 75 32 89 38 33 25 73 21 20 36 52 92 30 41 17
Card 173: 81 61 78 38 98 2 82 51 13 21 | 82 17 51 73 8 35 77 36 68 38 26 76 2 88 53 98 9 86 97 18 95 13 21 31 45
Card 174: 26 71 44 62 58 34 94 6 63 56 | 94 30 35 65 93 49 21 31 33 36 58 34 76 62 16 44 63 26 71 64 56 90 9 6 43
Card 175: 48 28 15 21 81 27 25 12 36 32 | 75 61 62 92 54 24 7 23 45 89 96 67 46 57 5 47 14 30 4 90 52 72 63 76 98
Card 176: 72 22 84 56 28 15 44 62 55 12 | 30 11 24 62 52 56 84 73 38 55 22 31 36 15 72 12 28 88 51 91 44 60 26 95 89
Card 177: 53 85 34 5 38 82 93 51 30 28 | 80 5 28 53 70 31 63 85 89 44 7 51 33 43 93 30 34 46 49 82 26 24 69 38 54
Card 178: 65 14 66 63 85 86 89 30 84 32 | 92 24 76 86 38 56 82 84 66 89 42 32 63 43 14 65 79 99 70 85 80 6 97 83 61
Card 179: 85 59 18 22 15 29 2 55 16 10 | 91 48 16 15 74 75 44 77 62 58 22 88 40 34 54 55 30 2 29 18 45 51 76 79 10
Card 180: 45 13 56 71 79 75 86 16 95 32 | 30 91 39 85 79 35 5 12 4 90 53 95 47 1 75 15 9 3 50 45 10 32 22 24 13
Card 181: 47 13 85 45 98 21 78 68 80 27 | 64 46 42 85 82 60 8 47 69 91 15 33 52 7 95 34 86 53 40 49 27 76 63 26 78
Card 182: 78 84 43 31 86 90 13 83 7 29 | 51 64 67 82 39 87 49 93 69 12 29 36 47 84 18 96 77 10 91 92 60 16 53 81 88
Card 183: 28 78 55 47 42 63 49 25 76 33 | 35 15 41 37 49 50 69 70 87 88 73 77 30 6 97 61 7 38 98 1 32 48 99 47 16
Card 184: 96 39 9 10 41 91 42 89 8 55 | 94 53 33 12 81 88 42 87 39 1 92 10 98 26 48 29 72 54 96 91 47 13 78 83 68
Card 185: 62 93 55 27 14 24 52 1 9 48 | 58 62 35 88 45 46 24 82 12 27 77 25 10 81 6 60 71 41 52 37 50 48 28 80 75
Card 186: 90 95 45 20 89 88 34 55 25 2 | 89 31 34 8 86 5 91 90 25 84 45 81 24 65 60 64 19 94 49 55 75 20 47 44 61
Card 187: 43 2 16 46 75 68 71 15 45 9 | 30 7 14 37 44 48 65 62 99 89 87 75 10 69 56 78 25 76 59 1 39 23 79 70 68
Card 188: 67 81 88 51 13 5 61 45 27 10 | 35 39 80 10 30 27 38 3 36 22 52 7 40 49 45 79 9 63 42 13 96 31 23 78 98
Card 189: 9 6 93 60 97 95 81 94 15 35 | 95 28 17 2 52 47 5 3 86 57 59 81 21 23 41 80 34 51 53 70 68 62 83 74 22
Card 190: 65 67 94 63 74 34 48 36 27 20 | 1 91 37 3 49 16 18 7 31 53 25 96 68 88 90 95 27 6 19 58 66 45 73 26 32
Card 191: 33 50 17 66 25 78 56 26 93 58 | 24 27 1 28 84 63 8 54 12 39 10 17 65 51 68 37 43 85 42 38 7 96 92 2 71
Card 192: 4 6 53 67 24 7 31 98 51 64 | 23 89 13 77 22 40 20 88 21 44 49 41 93 64 15 56 50 62 57 80 3 82 70 48 18
Card 193: 77 56 76 24 35 51 22 43 31 34 | 86 38 36 63 58 91 87 73 66 67 61 95 28 16 42 39 41 9 83 37 59 97 92 5 6

14
days/day04/src/main.rs Normal file
View file

@ -0,0 +1,14 @@
mod part1;
mod part2;
mod parse;
fn main() {
let input = include_str!("./input.txt");
let structured_input = parse::parse(input);
println!("Part One");
println!("Result: {}", part1::part1(&structured_input));
println!("Part Two");
println!("Result: {}", part2::part2());
}

122
days/day04/src/parse.rs Normal file
View file

@ -0,0 +1,122 @@
use std::collections::BTreeSet;
use nom::{
bytes::complete::tag,
multi::{many1, separated_list1},
sequence::{preceded, terminated},
IResult,
};
#[derive(Debug, PartialEq, Eq,)]
pub struct Card {
pub id: usize,
pub winning_numbers: BTreeSet<u8>,
pub numbers: BTreeSet<u8>,
}
impl Card {
pub fn parse(input: &str) -> IResult<&str, Card> {
let mut game_id = terminated(
preceded(
preceded(tag("Card"), many1(tag(" "))),
nom::character::complete::u8,
),
preceded(tag(":"), many1(tag(" "))),
);
let mut number_list = separated_list1(many1(tag(" ")), nom::character::complete::u8);
let seperator = preceded(tag(" |"), many1(tag(" ")));
let (input, id) = game_id(input)?;
let (input, winning_numbers) = number_list(input)?;
let (input, numbers) = preceded(seperator, number_list)(input)?;
let winning_numbers: BTreeSet<u8> = winning_numbers.into_iter().collect();
let numbers: BTreeSet<u8> = numbers.into_iter().collect();
Ok((
input,
Card {
id: id as usize,
winning_numbers,
numbers,
},
))
}
pub fn winning_number_matches(&self) -> BTreeSet<u8> {
self.numbers
.intersection(&self.winning_numbers)
.cloned()
.collect()
}
}
pub fn parse(input: &str) -> Vec<Card> {
input.lines().map(|l| Card::parse(l).unwrap().1).collect()
}
#[cfg(test)]
mod tests {
use super::*;
use collection_literals::collection;
#[test]
fn test_parse() {
let input = concat!(
"Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53\n",
"Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19\n",
"Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1\n",
"Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83\n",
"Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36\n",
"Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11\n",
);
assert_eq!(
parse(input),
vec![
Card {
id: 1,
winning_numbers: collection! {17, 41, 48, 83, 86},
numbers: collection! {6, 9, 17, 31, 48, 53, 83, 86}
},
Card {
id: 2,
winning_numbers: collection! {13, 16, 20, 32, 61},
numbers: collection! {17, 19, 24, 30, 32, 61, 68, 82}
},
Card {
id: 3,
winning_numbers: collection! {1, 21, 44, 53, 59},
numbers: collection! {1, 14, 16, 21, 63, 69, 72, 82}
},
Card {
id: 4,
winning_numbers: collection! {41, 69, 73, 84, 92},
numbers: collection! {5, 51, 54, 58, 59, 76, 83, 84}
},
Card {
id: 5,
winning_numbers: collection! {26, 28, 32, 83, 87},
numbers: collection! {12, 22, 30, 36, 70, 82, 88, 93}
},
Card {
id: 6,
winning_numbers: collection! {13 , 18, 31, 56, 72},
numbers: collection! {10, 11, 23, 35, 36, 67, 74, 77}
}
]
);
}
#[test]
fn test_card_parse() {
let input = "Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53";
assert_eq!(
Card::parse(input).unwrap(),
(
"",
Card {
id: 1,
winning_numbers: collection! {41, 48, 83, 86, 17},
numbers: collection! {83, 86, 6, 31, 17, 9, 48, 53},
}
)
)
}
}

59
days/day04/src/part1.rs Normal file
View file

@ -0,0 +1,59 @@
use crate::parse::*;
pub fn part1(input: &[Card]) -> usize {
input
.iter()
.map(|c| {
let len = c.winning_number_matches().len();
if len >=1{
2_usize.pow((len-1).try_into().unwrap())
} else {
0
}
})
.sum()
}
#[cfg(test)]
mod tests {
use collection_literals::collection;
use super::*;
#[test]
fn test_part1() {
let input = vec![
Card {
id: 1,
winning_numbers: collection! {17, 41, 48, 83, 86},
numbers: collection! {6, 9, 17, 31, 48, 53, 83, 86},
},
Card {
id: 2,
winning_numbers: collection! {13, 16, 20, 32, 61},
numbers: collection! {17, 19, 24, 30, 32, 61, 68, 82},
},
Card {
id: 3,
winning_numbers: collection! {1, 21, 44, 53, 59},
numbers: collection! {1, 14, 16, 21, 63, 69, 72, 82},
},
Card {
id: 4,
winning_numbers: collection! {41, 69, 73, 84, 92},
numbers: collection! {5, 51, 54, 58, 59, 76, 83, 84},
},
Card {
id: 5,
winning_numbers: collection! {26, 28, 32, 83, 87},
numbers: collection! {12, 22, 30, 36, 70, 82, 88, 93},
},
Card {
id: 6,
winning_numbers: collection! {13 , 18, 31, 56, 72},
numbers: collection! {10, 11, 23, 35, 36, 67, 74, 77},
},
];
assert_eq!(part1(&input), 13);
}
}

15
days/day04/src/part2.rs Normal file
View file

@ -0,0 +1,15 @@
use crate::parse::*;
pub fn part2() -> usize {
unimplemented!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_part2() {
assert_eq!(0, 0);
}
}