Skip to content

Commit 0b96dd9

Browse files
committed
solved part 1. small mistakes with using practice instead of input and forgetting something or other. solved part 2 but forgot to update the loop iteration count and I was scrolled to the wrong part of the page so I was like "yeah, answer looks correct" but that was part 1's practice answer and then I switched to real input and it was part 1's real answer. had to wait a minute to submit. didn't miss out on the leaderboard because of that luckily, but it did put me at #250 when I'd've gotten much higher with 00:06:48. minor mistakes on part 2: forgot to update the variable and that took a bit to debug.
1 parent 6393121 commit 0b96dd9

File tree

7 files changed

+139
-1
lines changed

7 files changed

+139
-1
lines changed

2021/solutions/day6/day6.1.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
input: string, lines: string[], dblines: string[][]
3+
copy(text: string) → clipboard
4+
error(message: string) → thrown error
5+
-5..mod(3) → @mod(-5, 3)
6+
*/
7+
8+
// Cardinals:
9+
// [[1,0],[-1,0],[0,1],[0,-1]]
10+
// +Diagonals:
11+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
12+
13+
export {};
14+
15+
const practice = `3,4,3,1,2
16+
`;
17+
// input = practice;
18+
19+
let fish = input.trim().split(",").map(w => +w);
20+
21+
function step() {
22+
let newfish: number[] = [];
23+
fish = fish.flatMap(f => {
24+
if(f === 0) {
25+
newfish.push(8);
26+
return [6];
27+
}
28+
return [f - 1];
29+
});
30+
fish = [...fish, ...newfish];
31+
}
32+
33+
for(let i = 0; i < 80; i++) {
34+
step();
35+
}
36+
37+
fish.dwth(log);
38+
console.log(fish.length);

2021/solutions/day6/day6.2.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
input: string, lines: string[], dblines: string[][]
3+
copy(text: string) → clipboard
4+
error(message: string) → thrown error
5+
-5..mod(3) → @mod(-5, 3)
6+
*/
7+
8+
// Cardinals:
9+
// [[1,0],[-1,0],[0,1],[0,-1]]
10+
// +Diagonals:
11+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
12+
13+
export {};
14+
15+
const practice = `3,4,3,1,2
16+
`;
17+
// input = practice;
18+
19+
let fish = input.trim().split(",").map(w => +w);
20+
21+
let counts = new Array(9).fill(0);
22+
23+
for(const fsh of fish) {
24+
counts[fsh]++;
25+
}
26+
27+
function step() {
28+
let nc: number[] = [...counts];
29+
counts.forEach((c, i) => {
30+
if(i == 0) {
31+
nc[i] -= c;
32+
nc[6] += c;
33+
nc[8] += c;
34+
}else{
35+
nc[i] -= c;
36+
nc[i - 1] += c;
37+
}
38+
});
39+
counts = nc;
40+
}
41+
42+
for(let i = 0; i < 256; i++) {
43+
step();
44+
}
45+
46+
counts.dwth(log);
47+
console.log(counts.reduce((t, c) => t + c, 0));

2021/solutions/day6/day6.3.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
input: string, lines: string[], dblines: string[][]
3+
copy(text: string) → clipboard
4+
error(message: string) → thrown error
5+
-5..mod(3) → @mod(-5, 3)
6+
*/
7+
8+
// Cardinals:
9+
// [[1,0],[-1,0],[0,1],[0,-1]]
10+
// +Diagonals:
11+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
12+
13+
export {};
14+
15+
const practice = ``;
16+
17+
// input = practice;

2021/solutions/day6/day6.4.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
input: string, lines: string[], dblines: string[][]
3+
copy(text: string) → clipboard
4+
error(message: string) → thrown error
5+
-5..mod(3) → @mod(-5, 3)
6+
*/
7+
8+
// Cardinals:
9+
// [[1,0],[-1,0],[0,1],[0,-1]]
10+
// +Diagonals:
11+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
12+
13+
export {};
14+
15+
const practice = ``;
16+
17+
// input = practice;

2021/solutions/day6/day6.5.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
input: string, lines: string[], dblines: string[][]
3+
copy(text: string) → clipboard
4+
error(message: string) → thrown error
5+
-5..mod(3) → @mod(-5, 3)
6+
*/
7+
8+
// Cardinals:
9+
// [[1,0],[-1,0],[0,1],[0,-1]]
10+
// +Diagonals:
11+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
12+
13+
export {};
14+
15+
const practice = ``;
16+
17+
// input = practice;

2021/solutions/day6/day6.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1,5,5,1,5,1,5,3,1,3,2,4,3,4,1,1,3,5,4,4,2,1,2,1,2,1,2,1,5,2,1,5,1,2,2,1,5,5,5,1,1,1,5,1,3,4,5,1,2,2,5,5,3,4,5,4,4,1,4,5,3,4,4,5,2,4,2,2,1,3,4,3,2,3,4,1,4,4,4,5,1,3,4,2,5,4,5,3,1,4,1,1,1,2,4,2,1,5,1,4,5,3,3,4,1,1,4,3,4,1,1,1,5,4,3,5,2,4,1,1,2,3,2,4,4,3,3,5,3,1,4,5,5,4,3,3,5,1,5,3,5,2,5,1,5,5,2,3,3,1,1,2,2,4,3,1,5,1,1,3,1,4,1,2,3,5,5,1,2,3,4,3,4,1,1,5,5,3,3,4,5,1,1,4,1,4,1,3,5,5,1,4,3,1,3,5,5,5,5,5,2,2,1,2,4,1,5,3,3,5,4,5,4,1,5,1,5,1,2,5,4,5,5,3,2,2,2,5,4,4,3,3,1,4,1,2,3,1,5,4,5,3,4,1,1,2,2,1,2,5,1,1,1,5,4,5,2,1,4,4,1,1,3,3,1,3,2,1,5,2,3,4,5,3,5,4,3,1,3,5,5,5,5,2,1,1,4,2,5,1,5,1,3,4,3,5,5,1,4,3

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
### 2021
88

99
Total Score: 39
10-
Times On Leaderboard: 1 / 6 (~17%)
10+
Times On Leaderboard: 1 / 8 (~13%)
1111
Highest Leaderboard Position: 62ᵗʰ place
1212
Best Day was Day 2: 39 points, #178/#62
1313

1414
| Day | Time | Rank | Score | Time | Rank | Score |
1515
| --: | -------: | ----: | ----: | -------: | ----: | ----: |
16+
| 6 | 00:03:17 | 128 | | 00:07:48 | 250 | |
1617
| 5 | 18:54:29 | 48349 | | 18:56:16 | 45151 | |
1718
| 4 | 00:09:35 | 172 | | 00:15:19 | 273 | |
1819
| 3 | 00:03:42 | 178 | | 00:13:24 | 276 | |

0 commit comments

Comments
 (0)