Skip to content

Commit

Permalink
added day 10 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
dCubelic committed Dec 10, 2020
1 parent b301bf3 commit f314a01
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 10/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>

int main()
{
int a;
std::vector<int> inputs;
while(int r = scanf("%d", &a) > 0)
{
inputs.push_back(a);
}

std::cout << "out\n";

std::sort(inputs.begin(), inputs.end());

int cur_jolt = 0;
std::map<int, int> m;
for(auto jolt: inputs)
{
m[jolt - cur_jolt]++;
cur_jolt = jolt;
}

std::cout << m[1] * (m[3] + 1);

return 0;
}
45 changes: 45 additions & 0 deletions 10/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>

std::map<std::vector<int>::iterator, long long> m;

long long count(std::vector<int>::iterator b, std::vector<int>::iterator e)
{
if(b+1 == e) return 1;
if(m.find(b) != m.end()) return m[b];

long long val;
if(b+3 < e && *(b+3) - *b <= 3)
{
val = count(b+3, e) + count(b+2, e) + count(b+1, e);
}
else if(b+2 < e && *(b+2) - *b <= 3)
{
val = count(b+2, e) + count(b+1, e);
}
else
{
val = count(b+1, e);
}
m[b] = val;
return val;
}

int main()
{
int a;
std::vector<int> inputs;
while(int r = scanf("%d", &a) > 0)
{
inputs.push_back(a);
}
inputs.push_back(0);

std::sort(inputs.begin(), inputs.end());

printf("%lld", count(inputs.begin(), inputs.end()));

return 0;
}
104 changes: 104 additions & 0 deletions 10/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
49
89
70
56
34
14
102
148
143
71
15
107
127
165
135
26
119
46
53
69
134
1
40
81
140
160
33
117
82
55
25
11
128
159
61
105
112
99
93
151
20
108
168
2
109
75
139
170
65
114
21
92
106
162
124
158
38
136
95
161
146
129
154
121
86
118
88
50
48
62
155
28
120
78
60
147
87
27
7
54
39
113
5
74
169
6
43
8
29
18
68
32
19
133
22
94
47
132
59
83
12
13
96
35

0 comments on commit f314a01

Please sign in to comment.