Day 4
This commit is contained in:
parent
eedde02b59
commit
c933fa53c7
5 changed files with 321 additions and 4 deletions
11
Main.hs
11
Main.hs
|
@ -5,14 +5,17 @@ module Main where
|
|||
import Day1
|
||||
import Day2
|
||||
import Day3
|
||||
import Day4
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "AoC 2023"
|
||||
--putStrLn "Day 1"
|
||||
--Day1.main
|
||||
--putStrLn "Day 2"
|
||||
--Day2.main
|
||||
putStrLn "Day 1"
|
||||
Day1.main
|
||||
putStrLn "Day 2"
|
||||
Day2.main
|
||||
putStrLn "Day 3"
|
||||
Day3.main
|
||||
putStrLn "Day 4"
|
||||
Day4.main
|
||||
|
||||
|
|
6
inputs/day4-test.input
Normal file
6
inputs/day4-test.input
Normal file
|
@ -0,0 +1,6 @@
|
|||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
214
inputs/day4.input
Normal file
214
inputs/day4.input
Normal file
|
@ -0,0 +1,214 @@
|
|||
Card 1: 29 21 67 44 6 13 68 15 60 79 | 75 44 60 30 10 68 40 70 36 79 3 13 64 15 4 46 21 22 67 47 73 86 29 53 6
|
||||
Card 2: 15 61 5 39 42 79 4 81 72 89 | 74 79 20 81 72 85 25 76 36 49 51 18 34 90 57 17 11 24 89 73 19 37 61 54 2
|
||||
Card 3: 75 31 33 22 49 70 37 98 92 94 | 1 87 73 92 57 94 84 10 5 79 69 74 96 37 40 55 18 21 85 93 71 49 70 22 39
|
||||
Card 4: 76 59 23 34 55 41 47 92 58 5 | 16 70 56 19 79 30 85 58 88 75 71 5 8 64 12 23 9 46 34 4 94 37 48 82 47
|
||||
Card 5: 48 77 74 18 44 34 71 38 67 1 | 8 78 73 19 39 50 11 54 69 37 79 18 66 77 52 94 74 34 71 1 48 85 67 95 93
|
||||
Card 6: 1 30 41 34 51 23 64 14 18 74 | 38 98 13 67 39 65 1 29 28 75 95 71 60 88 20 86 59 63 36 3 15 57 58 4 42
|
||||
Card 7: 70 27 20 85 2 34 55 49 24 5 | 19 20 15 48 70 26 89 7 55 44 76 53 63 49 93 68 23 59 72 73 52 41 9 11 94
|
||||
Card 8: 64 17 56 38 85 53 88 22 51 92 | 22 10 37 24 65 25 63 82 64 5 1 88 17 73 39 78 53 36 71 92 23 9 85 33 38
|
||||
Card 9: 99 7 22 85 41 15 84 10 42 34 | 16 52 65 26 95 37 28 44 21 36 13 89 48 51 71 83 49 86 9 12 33 32 61 72 73
|
||||
Card 10: 19 86 25 64 6 95 74 55 68 12 | 51 46 95 84 27 87 7 12 18 81 19 66 33 26 94 16 97 86 74 31 55 6 30 60 85
|
||||
Card 11: 45 6 14 25 88 1 5 26 91 28 | 10 42 34 19 28 18 91 47 71 29 66 94 43 82 65 70 3 30 64 52 83 27 85 4 60
|
||||
Card 12: 33 47 56 8 42 95 24 15 83 93 | 93 56 53 95 43 55 73 77 67 47 81 27 3 19 15 79 46 7 42 54 91 10 24 6 5
|
||||
Card 13: 2 18 45 43 56 82 7 23 16 4 | 70 56 74 4 83 23 98 57 20 86 87 30 28 89 77 37 75 10 41 58 32 21 35 84 66
|
||||
Card 14: 33 91 58 32 75 37 88 51 83 8 | 92 35 91 56 10 75 52 64 97 16 58 9 26 15 86 99 13 69 70 6 40 12 51 93 95
|
||||
Card 15: 18 94 82 39 93 70 90 85 37 91 | 29 94 68 22 47 4 64 1 37 75 90 95 54 56 12 48 80 6 40 38 55 2 30 49 92
|
||||
Card 16: 78 98 80 34 43 51 90 25 26 59 | 83 31 37 79 54 99 98 96 27 16 50 36 4 15 14 80 2 6 33 81 3 24 92 52 45
|
||||
Card 17: 6 74 89 4 22 95 54 97 28 99 | 32 24 60 83 89 62 79 82 91 25 43 40 52 23 50 71 6 86 64 51 58 63 36 1 41
|
||||
Card 18: 28 73 36 17 42 26 15 79 13 80 | 11 24 85 84 93 63 42 16 7 19 1 38 44 54 98 59 88 91 35 81 82 95 77 30 26
|
||||
Card 19: 45 38 16 35 25 72 97 19 96 46 | 21 9 83 49 93 50 92 88 62 46 4 61 69 85 82 51 43 86 81 47 20 53 15 84 91
|
||||
Card 20: 36 9 7 26 53 48 25 66 76 59 | 90 16 20 79 27 40 86 77 41 15 67 52 34 51 95 64 29 2 47 57 58 24 4 50 84
|
||||
Card 21: 26 89 64 53 45 95 32 90 24 65 | 80 46 34 33 8 19 94 47 5 21 9 68 73 29 48 82 26 36 4 15 10 74 14 42 79
|
||||
Card 22: 95 78 69 14 44 54 97 58 66 43 | 75 95 64 54 3 53 20 69 86 22 52 23 59 31 78 45 61 90 50 66 76 63 91 38 79
|
||||
Card 23: 46 59 36 40 60 10 38 72 20 91 | 21 40 99 22 27 20 57 59 76 78 10 85 97 71 98 1 24 6 72 58 60 36 38 63 46
|
||||
Card 24: 75 92 32 12 23 89 48 35 28 95 | 23 75 59 58 25 70 18 48 27 92 35 32 53 83 89 64 79 87 10 68 28 30 95 61 78
|
||||
Card 25: 64 30 37 36 70 35 26 75 80 7 | 11 10 28 40 64 94 31 98 73 57 70 8 88 30 20 80 85 75 92 14 37 27 77 41 76
|
||||
Card 26: 9 15 4 90 10 67 44 72 3 20 | 64 41 96 2 69 73 61 67 84 58 34 13 3 46 99 48 55 79 31 38 75 12 8 76 32
|
||||
Card 27: 48 15 97 86 38 37 75 64 27 10 | 96 85 54 88 80 64 11 70 37 50 86 24 75 63 15 3 48 27 17 65 83 97 22 74 10
|
||||
Card 28: 15 48 89 62 35 81 17 77 16 28 | 92 22 2 78 74 80 12 85 73 42 17 38 11 46 79 69 65 82 47 28 30 62 96 76 66
|
||||
Card 29: 97 84 88 6 87 4 9 23 43 39 | 64 35 18 36 33 32 39 61 63 93 84 23 49 3 31 60 81 97 17 37 57 79 74 30 65
|
||||
Card 30: 83 80 61 52 28 84 98 91 79 57 | 62 40 82 31 8 23 95 2 71 93 48 36 43 39 32 87 81 60 18 6 64 90 26 47 85
|
||||
Card 31: 98 40 94 66 28 32 46 88 36 24 | 4 50 3 21 61 57 63 85 39 11 27 52 7 96 25 91 34 95 71 76 67 23 22 19 99
|
||||
Card 32: 58 64 75 63 21 77 74 47 71 87 | 71 82 95 17 6 18 14 87 63 65 39 97 79 2 90 21 48 15 23 33 62 67 31 57 88
|
||||
Card 33: 35 53 67 16 68 20 60 39 47 13 | 71 38 80 7 94 95 44 18 27 64 86 23 81 46 31 56 52 73 97 37 58 29 79 40 6
|
||||
Card 34: 8 44 93 30 31 81 10 51 1 96 | 73 99 72 32 36 53 28 44 42 29 48 19 34 15 92 75 60 97 39 78 63 43 4 91 95
|
||||
Card 35: 74 83 62 26 55 81 84 90 53 2 | 77 3 75 54 71 32 18 21 56 70 65 61 4 96 31 72 11 35 6 91 64 38 87 73 30
|
||||
Card 36: 51 54 86 95 90 64 41 18 83 9 | 2 45 4 92 1 62 50 63 78 44 27 58 94 74 30 59 36 71 79 93 52 77 66 80 65
|
||||
Card 37: 94 67 88 44 25 18 99 14 63 89 | 17 89 32 71 18 63 19 85 88 91 65 25 14 30 75 48 94 72 99 9 67 36 44 16 62
|
||||
Card 38: 59 19 11 51 28 64 91 93 60 85 | 93 95 35 84 58 12 15 85 28 56 59 94 27 6 29 51 41 18 22 7 19 11 13 97 4
|
||||
Card 39: 19 47 29 82 31 27 44 66 67 45 | 1 36 31 67 11 54 8 3 45 56 66 73 27 47 53 14 86 82 30 29 44 60 77 7 19
|
||||
Card 40: 93 99 27 65 16 26 72 42 71 76 | 16 96 72 68 15 27 89 26 51 29 69 65 98 93 37 22 99 76 50 91 88 71 47 32 42
|
||||
Card 41: 23 42 80 53 72 98 95 11 21 93 | 47 80 4 30 23 27 82 3 58 93 66 54 35 8 2 53 14 42 75 61 7 17 36 45 89
|
||||
Card 42: 8 28 34 38 71 92 60 51 23 80 | 60 12 15 67 47 97 86 26 90 80 85 54 92 31 64 98 7 55 66 9 82 1 10 35 34
|
||||
Card 43: 77 83 18 61 56 78 46 48 80 45 | 41 61 93 45 16 9 38 51 11 48 99 22 3 27 56 66 46 24 80 78 83 75 77 67 18
|
||||
Card 44: 43 88 33 17 40 90 5 9 94 42 | 97 42 37 62 32 92 43 64 29 88 40 45 18 58 14 36 46 94 77 82 87 52 71 17 9
|
||||
Card 45: 26 76 46 27 66 8 63 67 2 99 | 11 76 8 80 62 46 92 67 74 18 54 2 63 9 99 66 57 27 26 51 58 73 12 50 59
|
||||
Card 46: 47 77 74 14 85 90 60 17 53 54 | 98 6 96 8 67 24 74 50 97 7 42 81 20 17 26 16 1 3 62 92 41 90 83 78 44
|
||||
Card 47: 52 48 72 1 47 55 36 91 89 82 | 35 62 93 40 36 47 43 82 48 72 89 13 69 99 1 52 2 97 18 55 24 86 9 91 90
|
||||
Card 48: 76 75 21 23 91 58 26 7 86 16 | 6 27 86 85 75 21 24 9 46 84 79 89 65 69 53 10 64 28 74 66 43 20 67 99 87
|
||||
Card 49: 13 53 58 15 69 68 19 30 48 43 | 13 48 1 41 68 93 34 43 26 15 53 17 91 51 50 19 6 79 39 61 47 30 96 69 58
|
||||
Card 50: 24 44 29 16 92 57 86 76 88 3 | 46 30 10 55 4 6 48 41 21 8 67 64 59 13 72 77 22 19 15 27 7 66 84 96 1
|
||||
Card 51: 90 36 71 21 76 64 86 79 48 98 | 76 64 53 42 71 59 23 90 9 79 98 27 48 91 13 96 7 21 5 36 33 8 6 86 31
|
||||
Card 52: 98 86 23 13 94 8 4 16 96 58 | 23 11 32 34 37 28 76 87 96 42 99 67 35 98 26 36 81 8 65 33 24 60 25 43 45
|
||||
Card 53: 81 16 7 78 24 48 84 26 42 61 | 81 78 90 18 24 96 62 61 65 38 54 3 84 26 73 30 6 43 20 49 10 36 8 16 89
|
||||
Card 54: 30 80 89 63 7 25 39 68 37 27 | 46 92 78 50 14 33 9 3 95 81 88 98 67 90 94 29 60 39 21 79 11 75 64 61 23
|
||||
Card 55: 87 43 58 6 69 78 56 19 64 16 | 87 48 69 53 77 26 31 2 78 19 73 57 76 23 70 44 29 13 80 56 92 82 79 45 12
|
||||
Card 56: 6 45 94 77 64 44 74 1 22 37 | 63 45 97 2 13 12 62 11 58 46 4 79 70 53 49 24 68 56 87 34 99 32 67 92 28
|
||||
Card 57: 34 1 73 9 87 21 65 39 37 69 | 83 86 41 18 13 32 10 73 75 39 96 52 30 31 63 20 48 33 23 58 17 85 82 71 68
|
||||
Card 58: 41 16 68 44 72 62 34 39 81 79 | 78 87 16 27 1 73 68 60 95 59 42 14 89 92 83 94 75 50 6 3 8 48 26 13 76
|
||||
Card 59: 45 57 86 29 44 51 6 42 88 31 | 22 13 59 94 83 5 66 17 78 92 64 3 72 8 10 2 12 52 27 79 54 58 18 39 70
|
||||
Card 60: 78 56 95 89 68 18 98 42 44 52 | 76 20 51 71 12 22 3 54 70 84 7 39 64 87 86 30 4 83 15 74 37 94 21 82 13
|
||||
Card 61: 18 84 14 96 43 38 85 73 71 53 | 92 98 94 23 32 5 30 58 51 68 78 47 75 36 61 89 34 81 35 37 80 44 93 76 69
|
||||
Card 62: 73 61 14 52 47 97 93 29 40 37 | 94 27 73 29 47 71 52 22 61 81 93 65 78 35 79 75 99 97 72 14 40 2 30 37 55
|
||||
Card 63: 34 13 11 98 36 78 96 31 74 20 | 14 20 85 57 84 88 96 36 50 13 78 34 82 28 62 98 11 52 33 74 55 90 61 31 93
|
||||
Card 64: 98 23 79 37 7 21 14 83 12 87 | 86 30 64 90 34 52 97 42 69 81 79 59 63 36 8 21 44 23 13 87 98 76 49 56 37
|
||||
Card 65: 11 73 35 16 6 27 63 9 74 51 | 54 84 35 11 49 19 91 6 32 73 99 26 53 16 63 27 9 51 7 85 58 59 33 78 74
|
||||
Card 66: 98 95 7 47 92 66 97 11 62 71 | 14 95 11 62 20 4 42 90 51 99 58 97 60 47 71 7 76 66 30 98 57 36 35 92 94
|
||||
Card 67: 33 36 32 60 74 54 41 27 88 93 | 22 82 86 58 30 13 9 61 2 15 80 66 5 29 77 78 53 72 24 89 19 12 1 7 73
|
||||
Card 68: 1 56 31 24 87 4 49 57 72 91 | 61 40 82 34 55 27 57 73 24 31 47 4 90 6 56 91 1 49 32 98 75 72 94 87 63
|
||||
Card 69: 95 32 15 58 27 45 79 23 6 98 | 69 63 18 95 91 8 48 7 38 10 75 26 61 2 12 34 62 22 81 94 67 40 14 25 52
|
||||
Card 70: 98 80 82 66 65 41 42 27 94 77 | 77 41 98 27 42 80 79 62 33 63 82 34 14 61 81 94 59 51 52 65 71 57 39 12 66
|
||||
Card 71: 69 34 98 15 16 82 49 44 10 19 | 43 96 17 53 89 76 94 45 5 81 29 77 83 75 11 60 87 67 47 22 64 88 18 59 1
|
||||
Card 72: 77 18 36 40 80 63 65 14 29 55 | 79 58 7 4 38 85 63 53 65 91 89 2 14 44 55 20 40 26 84 80 35 57 76 74 18
|
||||
Card 73: 63 23 39 12 22 35 48 40 84 75 | 79 61 40 58 23 48 75 97 87 4 81 29 84 68 63 51 74 53 35 39 33 24 22 12 60
|
||||
Card 74: 35 81 48 36 33 42 82 6 30 31 | 35 31 6 82 59 98 97 53 78 96 46 64 94 79 23 14 74 13 16 56 48 47 81 41 32
|
||||
Card 75: 62 43 47 1 15 50 77 14 85 4 | 70 46 16 69 85 3 30 96 62 99 27 47 59 49 26 9 57 1 50 73 94 97 28 20 29
|
||||
Card 76: 95 35 81 12 94 26 61 41 38 29 | 45 16 82 99 40 32 17 86 29 91 21 63 67 19 36 20 2 71 50 89 9 44 8 90 85
|
||||
Card 77: 74 85 93 55 27 86 16 54 73 82 | 13 3 19 49 11 62 68 7 2 77 25 79 71 61 81 29 84 47 78 32 91 34 15 43 20
|
||||
Card 78: 73 62 42 85 54 15 6 95 97 47 | 30 33 51 1 6 47 72 31 5 97 54 17 2 65 49 38 78 82 27 21 36 22 42 24 18
|
||||
Card 79: 20 51 62 17 82 37 90 45 98 95 | 20 2 90 40 43 71 60 62 75 16 77 14 6 15 17 52 8 95 32 66 54 45 84 61 70
|
||||
Card 80: 64 26 54 2 9 18 92 30 97 48 | 30 64 61 7 37 83 89 36 5 46 17 59 87 51 88 50 15 1 71 35 43 11 14 95 28
|
||||
Card 81: 63 57 72 69 11 90 85 30 64 71 | 37 77 13 9 61 60 23 54 62 64 7 56 48 1 85 73 41 68 29 10 3 92 35 12 26
|
||||
Card 82: 33 40 45 39 19 41 57 81 73 30 | 97 62 18 89 17 73 46 63 30 6 59 93 82 69 76 39 13 38 23 8 51 57 68 27 48
|
||||
Card 83: 92 96 72 5 13 6 45 52 57 54 | 56 14 63 29 19 39 62 76 34 91 43 61 42 27 72 71 89 25 99 23 6 12 7 97 30
|
||||
Card 84: 24 62 78 70 93 79 31 95 51 71 | 83 64 12 11 59 29 39 53 26 45 28 74 41 9 89 15 13 37 79 68 95 8 57 96 77
|
||||
Card 85: 71 31 76 93 84 57 72 48 73 74 | 51 11 53 68 87 67 31 91 92 15 24 65 58 2 82 42 18 97 61 7 10 47 75 38 27
|
||||
Card 86: 9 2 73 47 29 25 53 43 32 22 | 46 15 56 94 80 77 16 12 51 23 78 74 71 35 57 96 41 26 62 63 67 17 61 70 99
|
||||
Card 87: 68 37 86 81 50 77 79 76 52 57 | 3 23 65 50 28 29 97 20 48 37 52 38 82 31 66 8 81 86 68 92 79 57 18 76 77
|
||||
Card 88: 35 62 52 81 69 49 50 17 84 44 | 96 75 35 39 47 9 88 79 97 13 21 12 2 31 53 67 71 99 77 24 45 84 40 51 94
|
||||
Card 89: 87 64 77 62 95 22 21 34 40 49 | 82 6 52 87 34 49 86 63 72 40 22 77 56 62 10 37 64 67 21 73 99 91 2 95 17
|
||||
Card 90: 95 78 72 12 23 42 45 73 31 22 | 78 7 10 22 47 29 73 31 97 40 12 15 50 16 87 42 95 45 81 63 69 79 37 23 92
|
||||
Card 91: 37 80 51 67 32 59 40 8 38 25 | 38 8 26 1 20 67 80 54 40 51 85 21 3 37 52 32 14 66 13 25 15 23 59 56 48
|
||||
Card 92: 87 51 29 92 17 55 18 88 73 33 | 33 37 62 7 19 29 16 57 87 18 60 17 93 73 39 92 63 32 48 65 13 51 70 55 1
|
||||
Card 93: 31 40 98 94 45 46 44 83 78 10 | 31 40 68 21 97 45 11 59 98 17 55 10 71 37 46 93 96 78 32 76 39 44 83 48 56
|
||||
Card 94: 50 66 26 72 1 77 41 19 97 81 | 49 59 53 42 86 54 6 35 33 91 85 15 12 45 92 38 96 77 73 65 95 46 50 48 19
|
||||
Card 95: 2 20 92 4 66 97 30 87 17 14 | 20 2 29 46 97 72 93 60 89 39 6 94 12 13 33 96 30 59 1 5 53 22 83 77 78
|
||||
Card 96: 30 73 25 16 48 86 50 54 33 41 | 21 33 26 45 86 37 41 16 48 13 60 58 28 61 76 54 96 25 50 95 2 67 65 68 73
|
||||
Card 97: 54 37 39 24 21 62 26 35 25 2 | 10 11 97 16 39 73 35 55 40 93 87 21 14 90 41 36 61 63 13 23 86 96 6 12 38
|
||||
Card 98: 25 28 75 32 58 13 4 26 43 71 | 86 33 30 28 4 54 26 21 56 75 17 79 69 58 24 13 81 60 32 84 71 18 10 25 43
|
||||
Card 99: 25 86 74 99 26 98 38 59 18 73 | 99 95 10 24 4 20 91 14 46 78 53 34 98 41 73 84 22 43 45 57 86 26 25 74 59
|
||||
Card 100: 58 62 97 63 96 95 2 78 17 11 | 59 20 7 2 43 37 28 69 77 33 1 64 63 82 17 51 42 41 75 95 25 83 14 32 22
|
||||
Card 101: 84 10 35 37 61 80 65 77 13 92 | 87 80 77 7 58 62 26 35 24 96 37 15 36 91 65 84 83 76 32 94 78 31 6 59 48
|
||||
Card 102: 93 24 66 34 86 79 18 68 14 21 | 65 28 80 40 99 67 31 58 71 34 21 19 50 84 64 70 98 74 68 29 87 41 14 5 89
|
||||
Card 103: 11 24 96 69 54 77 33 80 87 34 | 77 63 24 56 58 26 93 86 94 27 33 96 36 92 75 49 43 16 54 29 87 81 28 80 34
|
||||
Card 104: 13 73 49 36 89 35 76 54 66 83 | 71 41 81 72 61 83 70 76 67 64 26 88 19 10 20 16 35 45 12 73 38 66 92 74 79
|
||||
Card 105: 18 74 53 37 19 30 72 84 41 86 | 24 49 23 36 61 12 56 64 85 15 66 40 94 76 2 69 67 38 45 9 48 21 99 20 60
|
||||
Card 106: 39 64 95 30 75 41 17 63 84 94 | 54 41 95 55 74 69 17 85 46 27 6 25 83 93 56 48 49 76 22 61 33 34 31 84 37
|
||||
Card 107: 42 15 62 4 44 48 14 82 97 70 | 19 9 28 77 70 83 71 85 4 76 38 89 30 21 87 65 13 29 97 31 27 64 74 54 93
|
||||
Card 108: 81 38 35 41 74 87 65 46 50 17 | 79 11 58 34 88 35 93 26 84 71 53 56 16 97 77 94 67 54 62 2 90 98 63 28 61
|
||||
Card 109: 29 11 71 84 90 94 1 23 54 88 | 84 77 12 87 14 35 49 89 75 63 37 64 10 1 91 97 98 25 86 3 27 57 58 50 96
|
||||
Card 110: 29 68 4 60 82 97 38 72 78 75 | 33 50 61 25 44 8 13 46 87 83 49 74 76 39 66 36 6 70 73 81 64 18 24 30 79
|
||||
Card 111: 13 86 29 24 16 78 88 98 46 93 | 72 87 69 34 76 56 66 35 81 7 36 95 8 15 53 11 25 99 74 9 67 30 85 91 82
|
||||
Card 112: 33 68 45 62 50 42 38 58 22 34 | 4 78 35 42 50 79 52 77 27 75 38 58 34 68 30 62 39 40 33 22 19 37 15 3 45
|
||||
Card 113: 59 45 81 42 67 36 32 86 66 6 | 42 62 21 14 38 33 55 36 18 78 49 37 6 10 44 19 73 77 97 1 67 43 25 81 13
|
||||
Card 114: 79 82 15 39 3 7 24 71 93 61 | 93 37 3 47 24 31 29 61 68 40 71 34 58 82 79 7 50 83 98 80 74 30 39 18 15
|
||||
Card 115: 11 93 43 52 49 88 28 14 55 39 | 55 28 43 1 16 93 42 49 78 31 11 84 52 3 15 72 88 39 14 85 89 36 19 58 8
|
||||
Card 116: 18 16 75 88 25 62 33 22 97 98 | 40 38 23 34 37 56 68 80 16 75 81 22 85 12 61 4 27 69 1 83 26 98 76 78 29
|
||||
Card 117: 77 39 53 44 81 90 98 52 38 5 | 80 90 69 20 61 35 4 18 83 39 56 36 95 44 98 81 76 23 60 43 38 17 77 55 51
|
||||
Card 118: 13 20 72 41 52 73 17 86 2 84 | 10 22 75 54 33 46 9 18 64 27 56 72 42 67 70 1 2 71 94 40 35 73 55 83 68
|
||||
Card 119: 48 52 33 58 7 56 71 89 10 18 | 7 66 69 5 70 58 84 92 71 89 57 52 37 18 21 31 12 75 62 79 56 30 26 48 11
|
||||
Card 120: 83 74 37 86 32 14 68 60 6 49 | 31 36 83 40 39 47 24 49 68 27 15 82 60 13 38 89 91 85 46 86 37 74 32 6 22
|
||||
Card 121: 24 66 45 22 23 36 70 43 11 80 | 9 56 26 33 8 73 4 18 72 69 78 30 17 96 95 89 12 45 91 77 84 28 79 50 19
|
||||
Card 122: 74 83 69 12 24 60 61 62 70 76 | 91 24 60 43 84 80 53 16 50 71 61 70 83 33 92 4 59 68 99 31 74 67 22 2 36
|
||||
Card 123: 13 79 14 97 25 94 53 99 12 61 | 96 40 67 80 79 1 56 22 25 83 2 72 43 28 64 14 66 65 4 94 59 31 11 21 19
|
||||
Card 124: 9 37 93 79 63 83 85 8 34 91 | 28 31 27 69 17 56 15 34 16 90 25 81 4 52 36 68 93 55 97 2 58 10 66 41 14
|
||||
Card 125: 9 13 1 15 34 77 14 27 69 45 | 11 28 31 76 39 44 47 96 93 5 91 80 17 68 87 98 24 71 34 36 63 72 49 70 30
|
||||
Card 126: 55 85 91 63 19 25 99 48 20 16 | 32 73 77 81 15 19 86 21 29 49 26 33 24 34 69 42 79 11 40 85 18 1 48 90 52
|
||||
Card 127: 41 35 53 27 30 82 23 56 58 84 | 79 9 46 95 32 11 56 82 49 19 72 8 7 13 93 1 67 33 66 18 12 59 28 98 96
|
||||
Card 128: 78 89 61 31 74 19 81 22 24 90 | 94 7 10 52 76 13 51 23 48 79 34 4 66 45 30 82 96 84 16 5 81 57 37 83 35
|
||||
Card 129: 76 15 41 7 79 4 73 12 88 92 | 64 8 58 70 29 56 87 94 59 48 71 53 22 39 81 36 26 45 63 6 54 27 20 47 62
|
||||
Card 130: 9 37 30 6 69 20 72 91 22 50 | 83 91 40 50 72 26 94 29 18 1 65 7 79 31 98 47 63 77 97 89 84 60 82 6 61
|
||||
Card 131: 4 84 24 97 12 27 68 40 71 21 | 69 6 81 50 18 88 59 54 29 32 71 3 8 75 41 68 4 17 99 79 20 27 24 40 21
|
||||
Card 132: 18 17 10 91 62 28 19 97 26 80 | 20 11 95 18 9 38 5 2 97 62 12 30 72 79 86 81 37 7 45 41 17 16 34 52 51
|
||||
Card 133: 2 20 42 44 38 99 78 83 25 30 | 3 59 84 66 12 30 14 76 20 78 45 97 42 79 99 8 16 91 2 40 38 56 89 81 90
|
||||
Card 134: 38 53 13 31 62 39 15 92 6 5 | 38 84 31 1 11 66 12 50 9 35 41 10 20 89 54 82 63 46 39 43 91 32 90 86 34
|
||||
Card 135: 52 5 88 6 18 45 16 19 23 9 | 82 50 3 21 23 64 96 5 17 6 53 36 78 44 66 31 72 15 79 27 86 88 48 18 81
|
||||
Card 136: 21 80 86 17 5 8 27 85 31 7 | 49 18 54 7 2 84 44 43 95 40 87 24 17 81 78 56 30 79 9 71 46 76 33 29 85
|
||||
Card 137: 46 28 18 88 71 63 78 58 50 33 | 75 20 53 56 30 64 10 11 47 59 91 24 67 76 8 1 43 37 87 52 16 39 84 69 89
|
||||
Card 138: 1 95 44 97 17 20 46 40 3 18 | 43 64 44 29 36 61 95 62 50 41 10 72 67 5 82 42 70 55 3 30 24 12 78 81 47
|
||||
Card 139: 87 57 36 27 16 3 53 79 66 69 | 83 16 77 41 50 87 8 66 5 91 30 61 82 38 67 24 96 11 17 89 36 45 65 12 27
|
||||
Card 140: 45 94 91 85 24 52 16 76 96 75 | 15 35 87 57 23 56 68 97 70 17 3 83 89 60 11 95 79 5 63 80 66 30 72 25 2
|
||||
Card 141: 32 34 70 25 16 98 59 64 69 62 | 87 34 22 96 20 19 8 9 61 68 35 28 75 16 88 42 77 6 43 85 14 66 44 67 36
|
||||
Card 142: 72 73 81 37 90 31 83 91 95 32 | 82 14 62 45 77 31 17 46 20 36 92 8 1 74 42 84 26 60 88 48 66 95 18 85 30
|
||||
Card 143: 23 94 85 5 75 22 39 80 34 58 | 73 40 64 54 42 56 93 26 94 33 71 55 82 72 31 2 59 60 29 41 15 17 76 99 52
|
||||
Card 144: 1 26 98 7 44 92 87 6 37 24 | 13 39 11 95 3 93 74 43 8 60 30 40 15 5 78 19 57 99 64 16 83 90 80 63 4
|
||||
Card 145: 69 82 7 40 94 28 75 85 74 10 | 98 36 56 86 95 9 16 20 49 6 24 84 83 15 17 57 19 72 89 34 4 2 61 77 44
|
||||
Card 146: 9 69 16 74 25 27 11 79 20 10 | 85 69 27 31 21 4 7 13 9 20 37 11 43 83 10 74 16 48 56 79 33 58 96 70 25
|
||||
Card 147: 75 14 66 51 86 50 34 57 16 18 | 83 4 68 1 38 84 73 58 86 76 74 66 75 72 44 22 26 87 34 60 95 14 45 40 90
|
||||
Card 148: 59 44 21 64 50 60 71 43 11 86 | 66 64 44 85 90 16 74 60 71 6 32 21 91 24 95 36 89 77 7 50 27 86 22 65 43
|
||||
Card 149: 64 70 95 44 86 90 19 87 47 15 | 98 9 14 82 17 67 25 60 26 10 95 5 81 39 76 85 52 43 49 23 27 99 50 19 6
|
||||
Card 150: 82 35 98 97 53 81 83 96 92 25 | 92 30 57 88 81 68 22 98 82 24 35 53 96 50 36 51 55 83 34 25 56 14 46 54 97
|
||||
Card 151: 68 82 83 72 49 5 78 25 4 9 | 4 27 79 49 68 84 34 78 32 82 21 3 77 86 5 48 33 11 53 19 62 26 52 57 87
|
||||
Card 152: 64 91 43 65 86 72 35 45 60 97 | 45 62 72 22 41 96 43 76 64 86 92 73 2 21 77 91 27 35 63 71 65 10 97 60 36
|
||||
Card 153: 13 82 94 65 49 61 32 31 48 97 | 7 86 75 65 89 22 51 49 77 81 97 37 61 24 34 82 57 6 46 84 12 70 63 94 13
|
||||
Card 154: 51 18 36 95 83 99 7 13 9 31 | 95 54 32 48 15 63 85 51 76 36 6 39 73 58 84 27 99 87 31 50 46 9 52 13 18
|
||||
Card 155: 73 26 15 84 93 70 91 54 92 12 | 22 92 54 6 67 36 13 15 93 89 55 5 70 71 26 9 16 27 91 21 25 73 82 12 84
|
||||
Card 156: 66 88 92 46 57 48 80 40 3 28 | 80 53 66 78 71 95 3 24 90 62 57 64 46 48 88 4 26 31 28 63 19 32 40 23 92
|
||||
Card 157: 14 98 81 93 3 94 39 32 12 25 | 58 30 88 8 54 18 50 78 52 36 68 73 74 9 79 49 39 35 15 86 2 10 3 44 65
|
||||
Card 158: 72 40 66 34 87 20 54 79 69 16 | 53 65 38 67 51 75 99 39 66 76 21 79 77 13 93 48 17 88 85 35 47 58 72 8 83
|
||||
Card 159: 10 83 69 13 53 41 39 37 55 74 | 9 27 90 53 52 2 42 3 62 37 32 61 35 39 95 36 83 26 69 28 29 71 77 16 54
|
||||
Card 160: 63 90 68 4 36 61 56 49 64 32 | 36 18 19 37 42 2 23 39 26 40 96 33 55 94 31 51 54 67 89 76 86 95 24 68 11
|
||||
Card 161: 38 7 25 30 8 39 9 34 19 28 | 3 10 86 85 13 73 61 9 31 43 40 74 60 67 83 70 57 78 81 63 34 27 8 28 97
|
||||
Card 162: 61 38 82 86 51 16 9 17 69 60 | 81 82 12 80 46 65 97 16 49 72 73 71 92 18 1 88 30 26 66 60 74 54 34 13 8
|
||||
Card 163: 61 58 38 73 62 21 25 71 49 44 | 79 21 93 85 90 65 36 78 74 94 24 20 39 14 13 63 75 99 42 28 55 40 86 38 89
|
||||
Card 164: 25 83 54 70 30 76 50 3 36 21 | 86 3 59 66 9 92 81 48 1 71 6 65 69 50 13 25 88 72 32 2 99 70 61 7 58
|
||||
Card 165: 98 70 26 66 7 42 78 93 84 60 | 30 31 38 22 11 25 10 75 46 41 72 60 40 65 37 33 63 51 36 52 76 73 32 58 79
|
||||
Card 166: 92 53 96 58 8 65 80 90 88 23 | 9 77 98 21 34 60 31 14 44 26 81 90 91 45 69 99 50 12 36 55 8 48 47 24 54
|
||||
Card 167: 14 88 33 30 20 99 64 48 60 5 | 68 2 58 90 63 36 12 94 9 71 96 10 29 1 91 53 67 17 85 8 49 57 69 25 59
|
||||
Card 168: 32 18 96 90 74 64 4 86 25 85 | 98 27 95 22 54 40 59 82 19 10 91 87 60 66 45 43 16 72 47 92 62 29 73 88 93
|
||||
Card 169: 3 47 80 78 17 68 20 36 54 87 | 75 52 73 43 45 29 53 10 65 89 84 37 90 13 15 40 76 91 88 74 9 7 4 22 1
|
||||
Card 170: 28 89 99 67 32 94 21 65 83 1 | 94 2 11 52 27 56 87 1 33 68 99 17 28 44 65 49 83 4 67 32 89 59 23 96 82
|
||||
Card 171: 20 76 49 15 91 67 50 97 96 3 | 70 21 96 8 22 34 67 41 48 20 33 56 47 29 37 3 14 63 17 32 51 76 12 52 65
|
||||
Card 172: 56 58 86 18 16 79 41 67 12 42 | 20 80 89 33 38 76 48 37 64 57 45 27 36 86 58 41 73 50 7 83 51 43 99 97 17
|
||||
Card 173: 15 48 73 6 92 20 50 75 8 32 | 7 55 3 79 44 85 35 30 12 81 60 33 80 56 59 84 70 98 65 61 51 45 99 38 29
|
||||
Card 174: 30 50 22 15 20 99 34 28 72 56 | 20 15 99 28 8 50 40 30 83 56 7 10 74 68 39 58 67 70 47 35 38 37 34 22 72
|
||||
Card 175: 41 77 9 57 1 24 48 6 92 61 | 75 24 61 92 22 84 76 20 88 1 6 14 74 12 59 71 40 77 41 68 57 64 58 9 63
|
||||
Card 176: 18 83 76 28 68 52 50 99 67 90 | 28 99 50 65 90 67 83 76 7 66 38 81 60 36 51 18 27 40 52 56 80 68 91 43 61
|
||||
Card 177: 95 28 89 86 65 42 41 44 92 21 | 93 28 22 86 97 18 14 84 7 42 66 72 33 95 76 69 49 59 45 98 26 57 67 1 24
|
||||
Card 178: 61 7 31 44 69 71 41 65 27 1 | 41 57 75 32 61 4 1 2 65 64 71 81 87 60 67 47 31 69 29 99 45 43 84 15 28
|
||||
Card 179: 80 61 21 75 10 86 36 84 71 43 | 77 80 82 43 84 63 99 21 93 86 60 46 61 36 76 19 3 69 57 75 71 10 13 20 95
|
||||
Card 180: 66 16 8 74 36 9 51 40 20 42 | 82 16 8 51 36 32 20 11 79 13 9 3 97 98 33 68 69 29 66 5 7 25 42 40 74
|
||||
Card 181: 36 32 49 85 15 6 4 56 1 62 | 80 77 45 83 35 62 9 48 43 17 36 27 32 85 11 89 15 49 56 6 47 1 4 22 20
|
||||
Card 182: 15 30 92 9 78 16 38 8 12 34 | 98 52 60 24 80 87 46 13 5 54 23 49 97 89 39 48 40 86 7 32 3 69 81 41 8
|
||||
Card 183: 83 16 69 4 53 41 11 65 6 81 | 12 92 35 51 67 71 55 14 73 1 74 80 82 17 94 43 23 78 63 66 96 30 7 61 29
|
||||
Card 184: 19 92 71 25 97 80 69 96 3 52 | 98 96 56 69 58 13 65 37 19 3 16 71 43 10 14 21 18 92 97 80 38 25 87 66 57
|
||||
Card 185: 38 95 97 10 59 93 98 37 43 81 | 12 34 18 2 14 48 35 86 27 96 82 23 37 21 61 63 68 9 17 69 13 5 43 10 32
|
||||
Card 186: 39 40 17 54 99 94 43 46 28 92 | 82 53 71 25 24 51 97 11 33 16 63 41 9 42 69 88 5 96 73 70 21 95 15 47 19
|
||||
Card 187: 87 31 45 8 75 30 7 62 22 79 | 86 72 36 8 60 63 40 7 38 65 11 29 92 2 28 59 14 19 87 35 91 12 16 41 57
|
||||
Card 188: 97 21 10 3 26 27 15 37 75 62 | 17 16 67 74 76 5 90 95 37 25 33 84 40 10 23 12 98 79 27 3 66 82 97 54 58
|
||||
Card 189: 89 21 23 2 19 93 12 67 58 88 | 66 79 21 16 78 5 12 30 88 83 58 1 6 45 76 95 46 39 31 77 33 19 7 51 69
|
||||
Card 190: 82 94 59 34 86 52 85 29 41 63 | 64 78 89 34 12 22 68 24 30 46 18 84 86 73 23 58 21 8 1 25 42 74 67 62 38
|
||||
Card 191: 71 80 45 39 12 15 24 83 53 33 | 96 23 86 70 52 57 37 75 35 82 61 13 5 87 62 54 16 85 32 53 63 66 30 22 67
|
||||
Card 192: 29 54 14 10 45 83 59 50 95 77 | 60 33 93 82 73 78 4 91 65 29 70 16 69 40 64 36 22 26 77 34 8 17 49 63 99
|
||||
Card 193: 62 71 81 41 93 98 42 73 34 96 | 89 86 51 60 8 87 34 72 35 45 43 67 38 28 46 24 95 97 47 77 20 80 74 2 85
|
||||
Card 194: 13 3 2 66 96 63 94 17 43 4 | 70 82 54 83 77 40 6 38 11 9 7 19 68 1 84 92 56 97 80 75 49 33 27 34 23
|
||||
Card 195: 92 7 61 33 40 95 63 6 96 93 | 41 80 64 81 63 40 57 33 49 24 95 26 89 61 39 92 74 6 1 31 93 29 7 48 56
|
||||
Card 196: 51 16 52 67 39 57 82 71 76 94 | 61 69 82 70 25 52 56 28 31 19 65 16 13 59 74 90 1 99 88 44 85 91 6 62 54
|
||||
Card 197: 87 32 97 31 84 79 24 99 62 12 | 80 3 35 12 32 66 81 62 22 8 20 30 95 61 93 16 73 51 96 15 31 84 19 24 58
|
||||
Card 198: 93 38 58 96 22 29 97 84 56 25 | 5 84 42 56 25 22 10 97 41 58 96 38 64 88 35 93 54 29 81 19 30 91 62 8 47
|
||||
Card 199: 34 58 6 57 29 99 79 47 94 37 | 61 86 4 23 97 47 9 35 53 34 30 13 25 56 79 89 81 93 8 18 91 43 16 80 90
|
||||
Card 200: 87 43 48 95 20 10 51 89 35 21 | 74 75 20 87 50 68 89 12 78 35 10 43 21 95 48 41 51 52 84 42 2 9 26 17 29
|
||||
Card 201: 97 38 88 9 17 29 34 64 20 72 | 39 79 30 17 78 72 4 5 20 95 60 69 28 62 32 85 43 38 87 12 96 7 27 10 6
|
||||
Card 202: 10 77 45 36 43 32 73 75 47 41 | 32 84 45 21 83 87 62 47 10 43 64 7 75 49 42 61 77 19 73 41 23 44 37 27 60
|
||||
Card 203: 97 44 48 40 2 31 28 27 83 73 | 58 82 83 99 17 40 97 96 95 90 72 69 63 21 14 59 62 2 84 6 48 35 93 27 55
|
||||
Card 204: 64 66 23 63 79 99 49 44 39 69 | 12 62 92 9 51 43 31 36 42 20 48 99 16 46 81 93 57 50 32 97 59 73 14 76 10
|
||||
Card 205: 28 52 50 53 43 32 98 97 61 72 | 62 16 18 71 8 44 11 36 59 41 1 57 84 24 15 56 19 81 55 26 30 85 94 52 75
|
||||
Card 206: 93 90 72 22 44 52 8 75 68 73 | 74 33 10 97 99 11 25 36 27 87 79 47 81 95 6 91 55 34 59 67 92 56 23 98 24
|
||||
Card 207: 29 92 17 56 98 84 96 71 13 61 | 68 80 1 66 36 30 46 58 40 12 3 10 82 25 74 97 61 53 56 22 95 57 86 63 11
|
||||
Card 208: 22 30 79 95 51 11 54 23 29 78 | 6 95 18 29 26 54 12 34 87 40 77 90 73 7 5 22 97 43 81 14 33 59 82 23 20
|
||||
Card 209: 58 1 51 44 83 17 70 95 26 66 | 79 62 91 74 25 53 68 87 23 96 88 93 27 21 61 24 75 57 92 46 97 38 59 64 42
|
||||
Card 210: 31 59 3 38 30 69 84 24 48 20 | 82 87 98 38 13 64 63 55 68 49 8 26 76 58 81 22 54 31 3 80 84 4 52 53 41
|
||||
Card 211: 99 37 92 70 2 88 33 84 63 9 | 50 24 57 65 51 15 21 12 7 23 49 77 60 71 67 56 90 69 95 96 18 81 93 82 53
|
||||
Card 212: 38 22 26 25 62 17 71 88 31 86 | 66 64 9 75 74 35 15 33 56 59 98 70 94 73 24 13 20 27 78 28 6 79 51 90 97
|
||||
Card 213: 67 96 40 18 19 51 28 23 36 47 | 61 99 58 43 95 81 16 24 65 9 54 4 87 84 32 42 69 64 45 52 20 72 13 66 62
|
||||
Card 214: 11 74 92 36 26 68 78 73 5 80 | 67 15 3 22 46 41 87 64 53 89 52 85 99 61 84 31 28 86 77 19 75 1 9 72 82
|
|
@ -23,4 +23,6 @@ library:
|
|||
exposed-modules:
|
||||
- Day1
|
||||
- Day2
|
||||
- Day3
|
||||
- Day4
|
||||
|
||||
|
|
92
src/Day4.hs
Normal file
92
src/Day4.hs
Normal file
|
@ -0,0 +1,92 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
{-# OPTIONS_GHC -Wno-unused-do-bind #-}
|
||||
|
||||
module Day4 where
|
||||
|
||||
import Data.Attoparsec.ByteString.Char8
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.List (unfoldr)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
pile <- pileFromFile
|
||||
putStrLn "Part 1 result:"
|
||||
print $ part1 pile
|
||||
putStrLn "Part 2 result:"
|
||||
print $ part2 pile
|
||||
|
||||
pileFromFile :: IO [Scratchcard]
|
||||
pileFromFile = do
|
||||
Right pile <- parseOnly parsePile <$> BS.readFile "inputs/day4.input"
|
||||
pure pile
|
||||
|
||||
pileFromTestFile :: IO [Scratchcard]
|
||||
pileFromTestFile = do
|
||||
Right pile <- parseOnly parsePile <$> BS.readFile "inputs/day4-test.input"
|
||||
pure pile
|
||||
|
||||
data Scratchcard = Scratchcard
|
||||
{ scratchCardNumber :: Int
|
||||
, scratchCardWinning :: [Int]
|
||||
, scratchCardOther :: [Int]
|
||||
}
|
||||
deriving Show
|
||||
|
||||
type Pile = [Scratchcard]
|
||||
|
||||
parsePile :: Parser Pile
|
||||
parsePile = scratchcard `sepBy` endOfLine
|
||||
|
||||
-- Card 169: 3 47 80 78 17 68 20 36 54 87 | 75 52 73 43 45 29 53 10 65 89 84 37 90 13 15 40 76 91 88 74 9 7 4 22 1
|
||||
scratchcard :: Parser Scratchcard
|
||||
scratchcard = do
|
||||
cardNb <- "Card" *> many1 space *> decimal
|
||||
":" *> many1 space
|
||||
win <- decimal `sepBy` many1 space
|
||||
many1 space *> "|" *> many1 space
|
||||
othr <- decimal `sepBy` many1 space
|
||||
pure $ Scratchcard cardNb win othr
|
||||
|
||||
score :: Scratchcard -> Int
|
||||
score (Scratchcard _ wx ox) = points $ map (`elem` wx) ox
|
||||
where
|
||||
points xs = case length (filter id xs) of
|
||||
0 -> 0
|
||||
n -> 2^(n-1)
|
||||
|
||||
part1 :: [Scratchcard] -> Int
|
||||
part1 = sum . map score
|
||||
|
||||
score2 :: Scratchcard -> Int
|
||||
score2 (Scratchcard _ wx ox) = points $ map (`elem` wx) ox
|
||||
where
|
||||
points xs = length (filter id xs)
|
||||
|
||||
data CardState = CardState
|
||||
{ number :: Int
|
||||
, matchingNb :: Int
|
||||
, occurences :: Int
|
||||
}
|
||||
deriving Show
|
||||
|
||||
mkCardState :: Scratchcard -> CardState
|
||||
mkCardState s@(Scratchcard n _ _) = CardState n (score2 s) 1
|
||||
|
||||
part2 :: [Scratchcard] -> Int
|
||||
part2 sx = sum . map occurences $ unfoldr f initialState
|
||||
where
|
||||
initialState = map mkCardState sx
|
||||
f :: [CardState] -> Maybe (CardState, [CardState])
|
||||
-- No new cards, just update the state
|
||||
f (c@(CardState _ 0 _):cs) = Just (c,cs)
|
||||
f (c@(CardState n m o):cs) = do
|
||||
-- add duplicates
|
||||
let cs' = map (\ e@(CardState n' m' o') ->
|
||||
if n' `elem` [n+1..n+m]
|
||||
then CardState n' m' (o + o')
|
||||
else e
|
||||
) cs
|
||||
-- return updated state
|
||||
Just (c,cs')
|
||||
f [] = Nothing
|
Loading…
Reference in a new issue