From 6f96b2014b053a2e6e5a37464ca6fc578607fda7 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 6 Jan 2022 18:44:53 +0100 Subject: rm --- day03/day03 | Bin 83112 -> 0 bytes day03/day03.cpp | 96 ----- day03/day03_input.txt | 1000 ---------------------------------------------- day03/day03_input_ez.txt | 12 - day03/makefile | 2 - 5 files changed, 1110 deletions(-) delete mode 100755 day03/day03 delete mode 100644 day03/day03.cpp delete mode 100644 day03/day03_input.txt delete mode 100644 day03/day03_input_ez.txt delete mode 100644 day03/makefile (limited to 'day03') diff --git a/day03/day03 b/day03/day03 deleted file mode 100755 index ccb1732..0000000 Binary files a/day03/day03 and /dev/null differ diff --git a/day03/day03.cpp b/day03/day03.cpp deleted file mode 100644 index 036cd07..0000000 --- a/day03/day03.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include -#include -#include - -int bin_to_dec (std::string bin) { - int dec = 0, pow = 1; - for (std::size_t i=bin.size(); i > 0; i--) { - dec += pow * (bin[i-1] == '0' ? 0 : 1); - pow *= 2; - } - return dec; -} - -std::vector get_freq (std::vector bits) { - std::vector freq; - for (std::size_t i=0; i filter (std::vector bits, int inv, int sel) { - std::vector res; - auto freq = get_freq(bits); - - for (auto b : bits) { - int f = freq[sel] * inv; - if (f == 0) f += inv; - if ((f > 0 ? '0' : '1') == b[sel]) { - res.push_back(b); - } - } - - return res; -} - -int main (int argc, char *argv[]) { - if (argc != 2) return 1; - - std::string raw; - std::getline(std::ifstream(argv[1]), raw, '\0'); - - std::vector bits; - - while (1) { - auto token = raw.find("\n"); - if (token != std::string::npos) { - bits.push_back(raw.substr(0, token)); - raw = raw.substr(token+1); - } else { - if (raw.size() > 0) bits.push_back(raw); - break; - } - } - - auto freq = get_freq(bits); - - std::string gamma = "", epsilon = ""; - for (std::size_t i=0; i 0 ? "1" : "0"; - epsilon += freq[i] > 0 ? "0" : "1"; - } - - int g = bin_to_dec(gamma); - int e = bin_to_dec(epsilon); - std::cout << "power level " << e*g << ", " - << "epsilon " << e << " (" << epsilon << "), " - << "gamma " << g << " (" << gamma << ")" << std::endl; - - std::vector o2 = bits; - for (std::size_t i=0; i co2 = bits; - for (std::size_t i=0; i