From 4b7e027f5ac3cf1f62f986573708f3a85aa1d955 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 20 Dec 2022 23:12:30 +0100 Subject: day 20 part 1 --- 22.20/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 22.20/main.py | 16 ++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 22.20/main.cpp create mode 100644 22.20/main.py diff --git a/22.20/main.cpp b/22.20/main.cpp new file mode 100644 index 0000000..753cdf5 --- /dev/null +++ b/22.20/main.cpp @@ -0,0 +1,47 @@ +/* The reason I gave up on this: + * I thought I'd need to somehow track the first "node", so I wanted to + * experiment on a more naive implementation. I don't. + * Also, the dumb algorithm is still by far fast enough. So, Python it is. */ +#include +#include +using namespace std; + +struct CNode +{ + size_t id; + CNode *prev = NULL, *next = NULL; +}; + +struct Circular +{ + vector nodes; + Circular(size_t size) { + for (size_t i = 0; i < size; i++) { + nodes.push_back(CNode{i}); + } + + // pointers to stuff in a vector? how risque! + for (size_t i = 0; i < size - 1; i++) { + nodes[i].next = &nodes[i+1]; + nodes[i+1].prev = &nodes[i]; + } + CNode *f = &nodes.front(); + CNode *b = &nodes.back(); + f->prev = b; + b->next = f; + } + + void print() { + } +}; + +int +main() +{ + int n; + vector input; + while (scanf("%d ", &n) == 1) { + input.push_back(n); + } + Circular c(input.size()); +} diff --git a/22.20/main.py b/22.20/main.py new file mode 100644 index 0000000..7cb46de --- /dev/null +++ b/22.20/main.py @@ -0,0 +1,16 @@ +from sys import stdin +a = [int(n) for n in stdin.readlines()] + +p = list(range(len(a))) + +for i, n in enumerate(a): + og_idx = p.index(i) + p.pop(og_idx) + og_idx = (og_idx + n) % len(p) + if og_idx == 0 and n < 0: og_idx = len(p) + p.insert(og_idx, i) + +a = [a[i] for i in p] +def g(n): return a[(a.index(0) + n) % len(a)] + +print(g(1000) + g(2000) + g(3000)) -- cgit 1.4.1-2-gfad0