Day 2 solutions!
This commit is contained in:
parent
3533c418cf
commit
fd827e58ed
File diff suppressed because it is too large
Load Diff
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -11,3 +11,4 @@ public import std.conv;
|
|||
public import std.path;
|
||||
public import std.uni;
|
||||
public import std.array;
|
||||
public import std.format;
|
||||
|
|
Loading…
Reference in New Issue