Skip to content

Commit ef74e94

Browse files
committed
day 10 cleanup
1 parent 2e4e5d0 commit ef74e94

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

2021/Day10/Solution.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ namespace AdventOfCode.Y2021.Day10;
66
[ProblemName("Syntax Scoring")]
77
class Solution : Solver {
88

9-
public object PartOne(string input) => GetScores(input, syntaxError: true).Sum();
10-
public object PartTwo(string input) => Median(GetScores(input, syntaxError: false));
9+
public object PartOne(string input) => GetScores(input, getSyntaxErrorScore: true).Sum();
10+
public object PartTwo(string input) => Median(GetScores(input, getSyntaxErrorScore: false));
1111

1212
public long Median(IEnumerable<long> items) =>
1313
items.OrderBy(x => x).ElementAt(items.Count() / 2);
1414

15-
IEnumerable<long> GetScores(string input, bool syntaxError) =>
16-
input.Split("\n").Select(line => GetScore(line, syntaxError)).Where(score => score > 0);
15+
IEnumerable<long> GetScores(string input, bool getSyntaxErrorScore) =>
16+
input.Split("\n").Select(line => GetScore(line, getSyntaxErrorScore)).Where(score => score > 0);
1717

18-
long GetScore(string line, bool syntaxErrorScore) {
18+
long GetScore(string line, bool getSyntaxErrorScore) {
1919
// standard stack based approach
2020
var stack = new Stack<char>();
2121

@@ -27,16 +27,16 @@ long GetScore(string line, bool syntaxErrorScore) {
2727
case ('{', '}'): stack.Pop(); break;
2828
case ('<', '>'): stack.Pop(); break;
2929
// return early if syntax error found:
30-
case (_, ')'): return syntaxErrorScore ? 3 : 0;
31-
case (_, ']'): return syntaxErrorScore ? 57 : 0;
32-
case (_, '}'): return syntaxErrorScore ? 1197 : 0;
33-
case (_, '>'): return syntaxErrorScore ? 25137 : 0;
30+
case (_, ')'): return getSyntaxErrorScore ? 3 : 0;
31+
case (_, ']'): return getSyntaxErrorScore ? 57 : 0;
32+
case (_, '}'): return getSyntaxErrorScore ? 1197 : 0;
33+
case (_, '>'): return getSyntaxErrorScore ? 25137 : 0;
3434
// otherwise, it's an opening parenthesis:
3535
case (_, _): stack.Push(ch); break;
3636
}
3737
}
3838

39-
if (syntaxErrorScore) {
39+
if (getSyntaxErrorScore) {
4040
return 0;
4141
} else {
4242
return stack

2021/SplashScreen.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@ public void Show() {
99

1010
var color = Console.ForegroundColor;
1111
Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ ");
12-
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ // 2021\n \n ");
13-
Write(0xcc00, false, " ");
12+
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /^2021$/\n \n ");
13+
Write(0xcc00, false, " ");
1414
Write(0xc8ff, false, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ");
1515
Write(0xcccccc, false, " 1 ");
1616
Write(0xffff66, false, "**\n ");
17-
Write(0xb5ed, false, " .. . . . ");
18-
Write(0xffffff, false, ". ");
17+
Write(0xb5ed, false, " .' ~. ' . . . ");
18+
Write(0xffffff, false, ". ");
19+
Write(0xb5ed, false, ". ");
1920
Write(0xa47a4d, false, "..'''' ");
2021
Write(0xcccccc, false, " 2 ");
2122
Write(0xffff66, false, "**\n ");
22-
Write(0xa2db, false, " '. . . ' ' . ");
23+
Write(0xa2db, false, " . .' ");
2324
Write(0xffffff, false, ". ");
2425
Write(0xa47a4d, false, ": ");
2526
Write(0xcccccc, false, " 3 ");
2627
Write(0xffff66, false, "**\n ");
27-
Write(0x91cc, false, ". . .. . ' . . . ");
28+
Write(0x91cc, false, " . . . .. ' . ");
2829
Write(0xffffff, false, ".' ");
2930
Write(0xa47a4d, false, "....' ");
3031
Write(0xcccccc, false, " 4 ");
3132
Write(0xffff66, false, "**\n ");
32-
Write(0x85c0, false, " . ~ ~.. . . ");
33+
Write(0x85c0, false, " .. . . .. ");
3334
Write(0xc74c30, false, ".");
3435
Write(0xff0000, false, ".");
3536
Write(0xffffff, false, "|\\");
@@ -38,31 +39,31 @@ public void Show() {
3839
Write(0xa47a4d, false, "'' ");
3940
Write(0xcccccc, false, " 5 ");
4041
Write(0xffff66, false, "**\n ");
41-
Write(0x79b5, false, " . . . ");
42+
Write(0x79b5, false, " . .. . . .' . ");
4243
Write(0xa47a4d, false, ": ");
4344
Write(0xcccccc, false, " 6 ");
4445
Write(0xffff66, false, "**\n ");
45-
Write(0x6daa, false, " . . .. . ");
46+
Write(0x6daa, false, ".' . . ");
4647
Write(0xa47a4d, false, ":' ");
4748
Write(0xcccccc, false, " 7 ");
4849
Write(0xffff66, false, "**\n ");
49-
Write(0x619f, false, " .. ' ' ' ");
50+
Write(0x619f, false, " . . . ");
5051
Write(0xa47a4d, false, "'''''..... ..");
5152
Write(0xc74c30, false, ".");
5253
Write(0xff0000, false, ". ");
5354
Write(0xcccccc, false, " 8 ");
5455
Write(0xffff66, false, "**\n ");
55-
Write(0x5a98, false, "' . . . ");
56+
Write(0x5a98, false, " ' . ' ' ");
5657
Write(0xa47a4d, false, ":'.. .. '' ");
5758
Write(0xff0000, false, "': ");
5859
Write(0xcccccc, false, " 9 ");
5960
Write(0xffff66, false, "**\n ");
60-
Write(0x5291, false, ". . . . ");
61+
Write(0x5291, false, " . . . ' ");
6162
Write(0xa47a4d, false, ": '' ''''..");
6263
Write(0x666666, false, " '. ");
6364
Write(0xcccccc, false, "10 ");
6465
Write(0xffff66, false, "**\n ");
65-
Write(0x333333, false, " . .. . : ");
66+
Write(0x333333, false, " . . . . . . : ");
6667
Write(0xa47a4d, false, "'.");
6768
Write(0x333333, false, ".'. : ");
6869
Write(0x666666, false, "11\n 12\n ");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy