Browse Source

day 2

master
mid-kid 2 years ago
parent
commit
3704f645e7
  1. 6
      Makefile
  2. 48
      d02.cc
  3. 2500
      d02_input.txt
  4. 2
      d02_output.txt

6
Makefile

@ -17,8 +17,8 @@ ok-%: %_test.txt
test-%: %_output.txt
%_output.txt: %_test.txt
@test -f $@ || (echo $<:; cat $<)
@test -f $@ && (diff -u $@ $< && touch $@)
@test -f $@ || (echo $*:; cat $<)
@test -f $@ && (diff -u $@ $< && touch $@) || exit 0
$(addsuffix _test.txt,$(progs)): %_test.txt: %
$(addsuffix _test.txt,$(progs)): %_test.txt: % %_input.txt
./$< < $*_input.txt > $@

48
d02.cc

@ -0,0 +1,48 @@
#include <iostream>
#include <vector>
#include <array>
using namespace std;
vector<array<unsigned, 2>> parse()
{
vector<array<unsigned, 2>> input;
string line;
while (getline(cin, line)) {
if (line.size() < 3 || line[1] != ' ') abort();
unsigned oppo = line[0] - 'A';
unsigned user = line[2] - 'X';
if (oppo >= 3 || user >= 3) abort();
input.push_back({oppo, user});
}
return input;
}
unsigned p1(vector<array<unsigned, 2>> &input)
{
unsigned score = 0;
for (array<unsigned, 2> i : input) {
unsigned shape = i[1];
unsigned outcome = (i[1] - i[0] + 4) % 3;
score += shape + 1 + outcome * 3;
}
return score;
}
unsigned p2(vector<array<unsigned, 2>> &input)
{
unsigned score = 0;
for (array<unsigned, 2> i : input) {
unsigned shape = (i[1] + i[0] + 2) % 3;
unsigned outcome = i[1];
score += shape + 1 + outcome * 3;
}
return score;
}
int main()
{
auto input = parse();
cout << p1(input) << endl;
cout << p2(input) << endl;
}

2500
d02_input.txt

File diff suppressed because it is too large

2
d02_output.txt

@ -0,0 +1,2 @@
13009
10398
Loading…
Cancel
Save