Skip to content

Commit 5e41138

Browse files
committed
2022/02 factor out some logic
1 parent e1ae783 commit 5e41138

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

2022/Day02/Solution.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,26 @@ enum Sign {
2222
Scissors = 3,
2323
}
2424

25-
public object PartOne(string input) =>
26-
Total(input, ElfParser, HumanParser1);
25+
public object PartOne(string input) => Total(input, Elf, Human1);
2726

28-
public object PartTwo(string input) =>
29-
Total(input, ElfParser, HumanParser2);
27+
public object PartTwo(string input) => Total(input, Elf, Human2);
3028

31-
Sign ElfParser(string line) =>
29+
Sign Elf(string line) =>
3230
line[0] == 'A' ? Sign.Rock :
3331
line[0] == 'B' ? Sign.Paper :
3432
line[0] == 'C' ? Sign.Scissors :
3533
throw new ArgumentException(line);
3634

37-
Sign HumanParser1(string line) =>
35+
Sign Human1(string line) =>
3836
line[2] == 'X' ? Sign.Rock :
3937
line[2] == 'Y' ? Sign.Paper :
4038
line[2] == 'Z' ? Sign.Scissors :
4139
throw new ArgumentException(line);
4240

43-
Sign HumanParser2(string line) =>
44-
line[2] == 'X' ? Next(Next(ElfParser(line))): // elf wins
45-
line[2] == 'Y' ? ElfParser(line) : // draw
46-
line[2] == 'Z' ? Next(ElfParser(line)) : // you win
41+
Sign Human2(string line) =>
42+
line[2] == 'X' ? Next(Next(Elf(line))): // elf wins
43+
line[2] == 'Y' ? Elf(line) : // draw
44+
line[2] == 'Z' ? Next(Elf(line)) : // you win
4745
throw new ArgumentException(line);
4846

4947
int Total(string input, Func<string, Sign> elf, Func<string, Sign> human) =>

0 commit comments

Comments
 (0)