Skip to content

Instantly share code, notes, and snippets.

View erikaderstedt's full-sized avatar

Erik Aderstedt erikaderstedt

View GitHub Profile
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import numpy as np
m = np.fromfile('8.in', dtype=np.uint8, count=25*6*100).reshape((100,6,25)) - 48
f = m.reshape((m.shape[0], m.shape[1]*m.shape[2]))
best_layer = np.argmin(f.shape[1] - np.count_nonzero(f, axis=1))
print("Pt 1:", (f.shape[1] - np.count_nonzero(f[best_layer,:]-1)) * (f.shape[1] - np.count_nonzero(f[best_layer,:]-2)))
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define IMMEDIATE (1)
#define POSITIONAL (0)
#define RELATIVE (2)
#define ARG0_ADDR (p[i+1] + ((modes[0] == RELATIVE) ? relative_base : 0))
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import numpy as np
from math import gcd, atan2
data = open("10.in","r").read().split("\n")[:48]
def angles_and_distances_as_seen_from(from_r, from_c, m):
r,c = m.shape
ang_dist = []
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "intcode.h"
#define WIDTH 120
#define HEIGHT 120
#define WHITE (1)
#define BLACK (0)
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import numpy as np
from re import compile
from math import gcd
def minsta_gemensamma(a, b):
return abs(a*b) // gcd(a, b)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "intcode.h"
#define WIDTH 50
#define HEIGHT 30
#define MAX_NUM_OUTPUTS 5000
#!/usr/bin/env python3
# -*- coding: utf8 -*-
from aocd import data
from re import compile
import math
x = compile('(.*) => (\d+) (\S+)')
y = compile('(\d+) (\S+)')
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import numpy as np
f = open('16.in').read().strip()
l = np.array([int(s) for s in f], dtype=int)
def get_matrix(llen):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "intcode.h"
#define MAX_NUM_OUTPUTS 10
int find_oxygen_generator(int64_t x, int64_t y, int64_t *visited, size_t *num_visited, struct program *p, int nsteps,
struct program **drone_at_oxygen_generator, int64_t *generator_x, int64_t *generator_y) {
//
// main.c
// p17
//
// Created by Erik Aderstedt on 2019-12-16.
// Copyright © 2019 Aderstedt Software AB-> All rights reserved.
//
#include <stdio.h>
#include "intcode.h"