Skip to content

Commit ae7019e

Browse files
authored
GH-321: Solve aco2015day1 (#322)
1 parent faa1f30 commit ae7019e

File tree

20 files changed

+213
-4
lines changed

20 files changed

+213
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ An algorithm is a finite sequence of rigorous instructions, typically used to so
737737

738738
**Competitive Programming Events**
739739

740-
* 🎄 Advent of Code ([2022](collections/advent-of-code-2022/))
740+
* 🎄 Advent of Code ([2015](collections/advent-of-code/2015/), [2022](collections/advent-of-code/2022/))
741741
* 🔰 Google Code Jam ([2022](collections/codejam-2022/))
742742

743743
**Coding Problems Website**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 🎄 Advent of Code 2015
2+
3+
> Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other.
4+
5+
> You don't need a computer science background to participate - just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.
6+
7+
* Website: https://adventofcode.com/2015/
8+
9+
## Problems
10+
11+
<table>
12+
<thead>
13+
<th></th>
14+
<th>Statement</th>
15+
<th>Part 1</th>
16+
<th>Part 2</th>
17+
</thead>
18+
<tbody>
19+
<tr>
20+
<td>Day 1</td>
21+
<td><a href="https://adventofcode.com/2015/day/1">Link</a></td>
22+
<td>
23+
<a href="../../../problems/aoc2015day1/src/main/solution1.cpp"><code>cpp</code></a>
24+
</td>
25+
<td>
26+
<a href="../../../problems/aoc2022day1/src/main/solution1.cpp"><code>cpp</code></a>
27+
</td>
28+
</tr>
29+
</tbody>
30+
</table>

problems/aoc2015day1/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
solution
2+
solution1
3+
solution2
4+
*.dSYM
5+
python/main/__pycache__

problems/aoc2015day1/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# AoC Problem
2+
3+
## Usage
4+
5+
Run program with an example
6+
7+
```
8+
bazel run src/main:solution1 `pwd`/data/1.in
9+
bazel run src/main:solution2 `pwd`/data/2.in
10+
```

problems/aoc2015day1/data/1.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
()()(()()()(()()((()((()))((()((((()()((((()))()((((())(((((((()(((((((((()(((())(()()(()((()()(()(())(()((((()((()()()((((())((((((()(()(((()())(()((((()))())(())(()(()()))))))))((((((((((((()())()())())(())))(((()()()((((()(((()(()(()()(()(()()(()(((((((())(())(())())))((()())()((((()()((()))(((()()()())))(())))((((())(((()())(())(()))(()((((()())))())((()(())(((()((((()((()(())())))((()))()()(()(()))))((((((((()())((((()()((((()(()())(((((()(()())()))())(((()))()(()(()(()((((()(())(()))(((((()()(()()()(()(((())())(((()()(()()))(((()()(((())())(()(())())()()(())()()()((()(((()(())((()()((())()))((()()))((()()())((((()(()()(()(((()))()(()))))((()(((()()()))(()(((())()(()((()())(()(()()(()())(())()(((()(()())()((((()((()))))())()))((()()()()(())()())()()()((((()))))(()(((()()(((((((())()))()((((()((())()(()())(())()))(()(()())(((((((())))(((()))())))))()))())((())(()()((())()())()))))()((()()())(())((())((((()())())()()()(((()))())))()()))())(()()()(()((((((()()))())()))()(((()(((())((((()()()(()))())()()))))())()))())((())()())(((((())())((())())))(((())(((())(((((()(((((())(()(()())())(()(())(()))(()((((()))())()))))())))((()(()))))())))(((((())()))())()))))()))))(((()))()))))((()))((()((()(()(())()())))(()()()(())()))()((((())))))))(())(()((()()))(()))(()))(()((()))))))()()((((()()))()())()))))))()()()))(()((())(()))((()()()())()(((()((((())())))()((((()(()))))))())))()()())()))(()))))(()())()))))))((())))))))())()))()((())())))(()((()))()))(())))))(()))()())()()))((()(()))()()()()))))())()()))())(())()()))()))((()))))()()(()())))))()()()))((((()))()))))(()(())))(()())))((())())(()))()))))()())))()())()())))))))))()()))))())))((())((()))))())))(((()())))))))(()))()()))(()))()))))()())))))())((((()())))))))())))()()))))))))()))()))))()))))))(())))))))))())))))))))))))))())())((())))))))))()))((())))()))))))))())()(()))))))())))))()()()())()(()()()(()())(()))()()()(()())))())())))()))))())))))))()()()()())(())())()())()))))(()()()()()))))()))())())))((()())()())))()))()))))(()())))()))))))))(((()))()()))))))))))))))))))))(()))(()((()))())))())(()))(()(()(())))))()(()))()))()()))))))))))))()((()())(())())()(())))))())()())((()()))))(()()))))())()(())()))))))))))))))))))))()))(()(()())))))))()()((()))()))))))((())))()))))))))((()))())()()))())()()))((()))())))))))))))(()())()))(())((()(()()))(()())(())))()())(()(())()()))))()))()(()))))))(()))))))))))(()))())))))))))())))))())))(())))))()))))(())())))))))))()(()))))()())))())(()))()())))))))))))))())()()))))()))))))())))))()))))(())(()()()()((())()))())(()))((())()))())())(())(()()))))()))(())()()((())(())))(())))()))())))))))))()(((((())())))(())()))))(())))((()))()(((((((()))))()()))(())))))()(()))))(()()))()))())))))))(()())()))))))))())))(()))())()))(())()((())())()())())(()(()))))()))))))((()())(())()()(()())))()()))(())(())(()))())))()))(()))()()))((((()))))()))((()()()))))()))()))())))(()))()))))(())))()))())()(()))()())))())))))))())))())))()()))))))(()))())())))()))()()())())))))))))))))())))()))(()()))))())))())()(())))())))))))))))))))))()()())())))))()()()((()(()))()()(())()())()))()))))()()()))))))((()))))))))()(()(()((((((()()((()())))))))))))()))())))))((())())(()))())))())))))())()()())(())))())))()())())(())))))))()()(())))()))())))())())())()))))))))()))(()()()())())())))(())())))))))()()())()))))())))())()(())())))))))()())()))(()()(())())))()(()((()()((()()(((((())(()())()))(())()))(())))(())))))))()))()))((()))()))()))))))))()))))))))((()()())(()))(((()))(())))()))((())(((())))()())))())))))((())))))(())())((((((())())()(()))()(()((()())))((())()(()(()))))(())(()()())(())))())((()(((())())))(((()())())))())()(())())((((()()))))())((()))()()()()(())(((((((()()()((()))())(()())))(())())((((()()(()))))()((())))((())()))()(((()))())))()))((()(()))(())(()((((())((((()()(()()))(((())(()))))((((()(()))(())))))((()))(()))((()(((()(()))(()(()((()(())(()(()(()(()()((()))())(((())(()(()))))(()))()()))(())))(())()(((())(()))()((((()()))))())(()))))((())()((((()(((()))())())(((()))()())((())(())())(())()(())()(()()((((((()()))))()()(((()()))))()())()(((()(()))(()(()())(()(()))))(((((()(((())())))))(((((()((()()((())())((((((()(())(()()((()()()()()()()(()()))()(((()))()))(((((((())(((()((()())()((((())(((()(())))()((()(()()()((())((()())()))()))())))())((((((()))(()(()()()))(()((()(()(()))()((()(((()()()((())(((((())()(()))())())((()(())))(()(()())(())((())())())(((()()()(())))))())(()))))))()))))))())((()()()))((()((((((()))(((()((((()()()(((()))())()(()()(((()((()()()()())()()))()()()(()(())((()))))(()))())))))))()(()()(((((())()(()(((((()((()(()()())(()((((((((()((((((())()((((()()()((()((()((((((()))((())))))))())()))((()(()))()(()()(()((())((()()((((((((((((()())(()()()))((((()((((((())(()))())(()()((()()))()(((((((()((()()((((((()(((())))((())))((((((((()()(((((((())(((((()())(((())((())()((((()(((((((()(()(((()((((((()(((()(((((((((((()()((()()(()))((()()(((()(((())))((((())()(()(((())()(()(((())(((((((((((()))())))((((((())((()()((((()())())((((()()))((())(((((()(()()(()()()((())(()((()()((((()(((((()((()(()((((()())((((((()(((((()()(()(()((((())))(())(())(())((((()(()()((((()((((()()((()((((((())))(((((()))))()))(()((((((((()(((())())(((())))(()(()((())(((()((()()(((((()((()()(((())()(()))(((((((())(()(((((()))((()((()((()))(())())((((()((((())()(()))(((()(((((((((((((((())(((((((((()))(((()(()()()()((((((()((())()((((((((()(())(((((((((((()(()((())()((()()(()(()()((((()()((())(()((()()(()()((((()(((((((())))((((())(())()(((()()((()()((((()((()(((()((())(((()()()((((()((((()()(()(()((((((((())(()(((((())(()())(((((((()())()(()((((()((())(()()())((((()()(((()((((())(())(()()(((((((((()()))()(((())(()(()((((((())(()()())(()))()()(((()(((()((())(()(((((((()(()(()((()(((((()(()((()(()((((((()((((()()((((()(((()((())(()(()((()()((((()()(())()(())(((())(()((((((((()())(((((((((()(())()((((())))()))()()(((((()()((((((())(()()(((()(()(((((((()(()(((((((())(())((((()((()(())))((((()()())(()))((()())((((()(((((()(()(())(()(()()())(((((()(((((()((((()()((((((((()()))(()((((((())((((())()(()(((()()()(((()(()(())(())(((((()(())())((((())(())(()(((()(((((())((((())())((()(((((((()(((())(()(()))(((((((((()((()((()()(()((((())(((()((())((((())(()(((()(((()(()((((()(((())(()(((()(()()(()(()((()()(()())(())())((()(()(((()(((()(((()()(((((((((()(((((((((()()(((()(((()())((((()(()(((()()()((())((((((((((())(()(((()((((()())((((()((()))(((()()()(((((()(((((((())((()())(()((((())((((((((())(()((()((((((((((()()((()((()()))(((()())()())()(((()())()()(()(()(((((((())()))(())()))())()()((())()((()((((()((()((())(((((()((((((()(())))(()))())(((()))((()()(()(((()))((((())()(((()))))()(()(())()(((((())(()(()(())(())()((()()()((((()(())((()())(()(()))(()(()(()()(())()()(()((())()((()))))()))((()(()()()()((()())(()))())()(()(((((((((())())((()((()((((((())()((((())(((())((()(()()()((())(()((())(((()((((()()((()(()(((((())()))()((((((()))((())(((()()))(((())(())()))(((((((())(())())()(())(((((()))()((()))()(()()((()()()()()())(((((((

problems/aoc2015day1/data/1.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
280

problems/aoc2015day1/src/main/BUILD

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
3+
cc_binary(
4+
name = "solution1",
5+
srcs = ["solution1.cpp", "helpers.h"],
6+
visibility = ["//visibility:public"],
7+
copts = ["-std=c++17"]
8+
)
9+
10+
cc_binary(
11+
name = "solution2",
12+
srcs = ["solution2.cpp", "helpers.h"],
13+
visibility = ["//visibility:public"],
14+
copts = ["-std=c++17"]
15+
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
#include <iostream>
6+
#include <stack>
7+
#include <queue>
8+
9+
using namespace std;
10+
11+
/* Temmplate class T should be a Nary Tree Node
12+
* See leetcode 589 (https://leetcode.com/problems/n-ary-tree-preorder-traversal/description/)
13+
* class Node {
14+
* public:
15+
* int val;
16+
* vector<Node*> children;
17+
*
18+
* Node() {}
19+
*
20+
* Node(int _val) { val = _val; }
21+
*
22+
* Node(int _val, vector<Node*> _children) {
23+
* val = _val;
24+
* children = _children;
25+
* }
26+
* };
27+
*/
28+
template <typename T> T* parse_nary_tree(vector<string> s) {
29+
T* fake = new T();
30+
T* current = fake;
31+
queue<T*> q;
32+
for(string e: s){
33+
if(e == "null"){
34+
current = q.front();
35+
q.pop();
36+
} else {
37+
T* child = new T(stoi(e));
38+
q.push(child);
39+
current->children.push_back(child);
40+
}
41+
}
42+
return fake->children[0];
43+
}
44+
45+
vector<string> parse_line(string line) {
46+
vector<string> v;
47+
string s;
48+
for (char c : line) {
49+
if (c == ' ') {
50+
v.push_back(s);
51+
s = "";
52+
} else {
53+
s += c;
54+
}
55+
}
56+
v.push_back(s);
57+
return v;
58+
}
59+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <algorithm>
2+
#include <cmath>
3+
#include <filesystem>
4+
#include <fstream>
5+
#include <iostream>
6+
#include <map>
7+
#include <set>
8+
#include <string>
9+
#include <vector>
10+
11+
#include "helpers.h"
12+
13+
using namespace std;
14+
15+
pair<int, int> solve(string s){
16+
int f = 0; // floor
17+
int p = -1; // position
18+
for(int i=0; i<s.size(); i++){
19+
if(s[i] == '('){
20+
f++;
21+
} else {
22+
f--;
23+
}
24+
if(f == -1 && p == -1){
25+
p = i + 1;
26+
}
27+
}
28+
return make_pair(f, p);
29+
}
30+
31+
int main(int argc, char* argv[]) {
32+
string input = argv[1];
33+
string line;
34+
fstream f(input);
35+
getline(f, line);
36+
f.close();
37+
auto [finalFloor, firstBasementEntry] = solve(line);
38+
cout << "finalFloor = " << finalFloor << endl;
39+
cout << "firstBasementEntry = " << firstBasementEntry << endl;
40+
return 0;
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <algorithm>
2+
#include <cmath>
3+
#include <filesystem>
4+
#include <fstream>
5+
#include <iostream>
6+
#include <map>
7+
#include <string>
8+
#include <vector>
9+
10+
#include "helpers.h"
11+
12+
using namespace std;
13+
14+
int main(int argc, char* argv[]) {
15+
string input = argv[1];
16+
string line;
17+
fstream f(input);
18+
long long sum_c = 0;
19+
vector<long long> v;
20+
while (getline(f, line)) {
21+
if (line.size() == 0) {
22+
v.push_back(sum_c);
23+
sum_c = 0;
24+
} else {
25+
sum_c += stoi(line);
26+
}
27+
}
28+
sort(v.begin(), v.end(), greater<long long>());
29+
long long total = v[0] + v[1] + v[2];
30+
cout << "max_c = " << total << endl;
31+
}

tools/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tools
2+
3+
Craft a problem with the following command:
4+
5+
```
6+
python craft.py
7+
```

tools/craft/templates/aoc/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
solution
1+
solution
2+
solution1
3+
solution2
4+
*.dSYM
5+
python/main/__pycache__

tools/craft/templates/aoc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
Run program with an example
66

77
```
8-
bazel run src/main:solution1 `pwd`/data/input1.txt
9-
bazel run src/main:solution1 `pwd`/data/input2.txt
8+
bazel run src/main:solution1 `pwd`/data/1.in
9+
bazel run src/main:solution2 `pwd`/data/2.in
1010
```

tools/craft/templates/aoc/data/2.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1
2+
2
3+
3
4+
4

tools/craft/templates/aoc/data/2.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

0 commit comments

Comments
 (0)