Day 2 solutions!

This commit is contained in:
Andrew Lalis 2022-12-02 07:05:52 +01:00
parent 3533c418cf
commit fd827e58ed
4 changed files with 2543 additions and 0 deletions

2500
input/2.txt Normal file

File diff suppressed because it is too large Load Diff

15
src/s2a.d Normal file
View File

@ -0,0 +1,15 @@
module s2a;
import util;
void main() {
readText("input/2.txt").strip.splitter("\n")
.map!(l => l.strip.splitter(" ").map!(c => c.to!char).array)
.map!((c) {
int sOp = c[0] - 'A' + 1;
int sMe = c[1] - 'X' + 1;
if (sMe == sOp % 3 + 1) return 6 + sMe;
if (sOp == sMe % 3 + 1) return sMe;
return 3 + sMe;
})
.sum.writeln;
}

27
src/s2b.d Normal file
View File

@ -0,0 +1,27 @@
module s2b;
import util;
const ROCK = 1;
const PAPER = 2;
const SCISSORS = 3;
void main() {
readText("input/2.txt").strip.splitter("\n")
.map!(l => l.strip.splitter(" ").map!(c => c.to!char).array)
.map!((c) {
int sOp = c[0] - 'A' + 1;
int sEnd = c[1];
if (sEnd == 'X') {
int sMe = sOp - 1;
if (sMe < 1) sMe = 3;
return sMe;
}
if (sEnd == 'Z') {
int sMe = sOp + 1;
if (sMe > 3) sMe = 1;
return 6 + sMe;
}
return 3 + sOp;
})
.sum.writeln;
}

View File

@ -11,3 +11,4 @@ public import std.conv;
public import std.path; public import std.path;
public import std.uni; public import std.uni;
public import std.array; public import std.array;
public import std.format;