Browse Source

day 1

master
mid-kid 2 years ago
commit
c323acf703
  1. 24
      Makefile
  2. 41
      d01.cc
  3. 2246
      d01_input.txt
  4. 2
      d01_output.txt

24
Makefile

@ -0,0 +1,24 @@
CXXFLAGS := -std=c++11 -Wall -Wextra -O2
progs := $(patsubst %.cc,%,$(wildcard *.cc))
.PHONY: all
all: $(addsuffix _output.txt,$(progs))
.PHONY: clean
clean:
rm -f $(progs) $(addsuffix _test.txt,$(progs))
.PHONY: ok-%
ok-%: %_test.txt
@cp -v $< $*_output.txt
.PHONY: test-%
test-%: %_output.txt
%_output.txt: %_test.txt
@test -f $@ || (echo $<:; cat $<)
@test -f $@ && (diff -u $@ $< && touch $@)
$(addsuffix _test.txt,$(progs)): %_test.txt: %
./$< < $*_input.txt > $@

41
d01.cc

@ -0,0 +1,41 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<unsigned> parse()
{
vector<unsigned> elves;
string line;
unsigned elf = 0;
while (getline(cin, line)) {
if (line.empty()) {
elves.push_back(elf);
elf = 0;
continue;
}
elf += stoul(line);
}
sort(elves.begin(), elves.end(), greater<int>());
return elves;
}
unsigned p1(vector<unsigned> &input)
{
return input[0];
}
unsigned p2(vector<unsigned> &input)
{
return input[0] + input[1] + input[2];
}
int main()
{
auto input = parse();
cout << p1(input) << endl;
cout << p2(input) << endl;
}

2246
d01_input.txt

File diff suppressed because it is too large

2
d01_output.txt

@ -0,0 +1,2 @@
69836
207968
Loading…
Cancel
Save