From d036b3714e7bbb0825b25d28ed3a6a947085e0d7 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 6 Jan 2022 16:00:32 +0100 Subject: day06 --- day06/day06 | Bin 0 -> 76512 bytes day06/day06.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ day06/day06_input.txt | 1 + day06/day06_input_ez.txt | 1 + day06/makefile | 2 ++ 5 files changed, 51 insertions(+) create mode 100755 day06/day06 create mode 100644 day06/day06.cpp create mode 100644 day06/day06_input.txt create mode 100644 day06/day06_input_ez.txt create mode 100644 day06/makefile (limited to 'day06') diff --git a/day06/day06 b/day06/day06 new file mode 100755 index 0000000..ccf553a Binary files /dev/null and b/day06/day06 differ diff --git a/day06/day06.cpp b/day06/day06.cpp new file mode 100644 index 0000000..38d602b --- /dev/null +++ b/day06/day06.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#include "../utils.h" + +long sum (std::vector vec) { + long s = 0; for (long v : vec) s += v; return s; +} + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + std::vector strfish; + split(strfish, raw, ","); + + std::vector fish; + for (int i=0; i<9; i++) { fish.push_back(0); } + for (std::string str : strfish) fish[std::stoi(str)] += 1; + + int days = 80; + if (argc > 2) days = std::stoi(std::string(argv[2])); + for (int i=0; i 3 && std::string(argv[3]) == "-w") { + std::cout << "day " << i+1 << "/" << days + << " current fish: " << sum(fish) << std::endl; + } + if (argc > 3 && std::string(argv[3]) == "-v") { + std::cout << "day " << i+1 << ": "; + for (auto f : fish) std::cout << f << ","; + std::cout << std::endl; + } + } + + std::cout << "fish: " << sum(fish) << std::endl; + return 0; +} diff --git a/day06/day06_input.txt b/day06/day06_input.txt new file mode 100644 index 0000000..5b38bce --- /dev/null +++ b/day06/day06_input.txt @@ -0,0 +1 @@ +4,1,1,4,1,1,1,1,1,1,1,1,3,4,1,1,1,3,1,3,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,5,1,2,1,1,5,3,4,2,1,1,4,1,1,5,1,1,5,5,1,1,5,2,1,4,1,2,1,4,5,4,1,1,1,1,3,1,1,1,4,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,2,1,1,1,1,1,1,1,2,4,4,1,1,3,1,3,2,4,3,1,1,1,1,1,2,1,1,1,1,2,5,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,3,1,2,1,2,1,3,4,5,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,3,1,1,3,1,1,4,1,1,1,1,1,2,1,1,1,1,3,2,1,1,1,4,2,1,1,1,4,1,1,2,3,1,4,1,5,1,1,1,2,1,5,3,3,3,1,5,3,1,1,1,1,1,1,1,1,4,5,3,1,1,5,1,1,1,4,1,1,5,1,2,3,4,2,1,5,2,1,2,5,1,1,1,1,4,1,2,1,1,1,2,5,1,1,5,1,1,1,3,2,4,1,3,1,1,2,1,5,1,3,4,4,2,2,1,1,1,1,5,1,5,2 diff --git a/day06/day06_input_ez.txt b/day06/day06_input_ez.txt new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/day06/day06_input_ez.txt @@ -0,0 +1 @@ +3,4,3,1,2 diff --git a/day06/makefile b/day06/makefile new file mode 100644 index 0000000..2bc132f --- /dev/null +++ b/day06/makefile @@ -0,0 +1,2 @@ +all day06.cpp: + g++ -std=c++20 -o day06 day06.cpp -- cgit v1.2.3-54-g00ecf