Skip to content

Instantly share code, notes, and snippets.

View saucecode's full-sized avatar

Julian saucecode

  • New Zealand
View GitHub Profile
@saucecode
saucecode / aoc8_ugly.py
Created December 8, 2017 07:16
AoC day 8 feat. the ugliest code I've ever written -- script generates scripts that generate solutions to both parts
# generates a python script which runs the challenge input as code then prints out
# the largest integer in `locals()` and the largest value seen
with open('day8challengeinput','r') as f:
lines = f.read().split('\n')
def generate_code_from_input():
headcode = 'largest = 0'
excode = ''
symbols = []
@saucecode
saucecode / AoC7Solution.java
Created December 7, 2017 17:36
AoC day 7 part 2 solution
import java.io.File;
-snip-
public class AoC7Solution {
static List<Node> nodes = new ArrayList<>();
public static void main(String[] args) {
// Read input
try {
@saucecode
saucecode / aoc4.2.py
Created December 4, 2017 07:27
my AoC day 4 part 2 prime-products solution
import string
challenge = '''nyot babgr babgr kqtu kqtu kzshonp ylyk psqk
iix ewj rojvbkk phrij iix zuajnk tadv givslju ewj bda
-snip-
'''.split('\n')
primes = [int(x) for x in '2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101'.split(', ')]
letters = string.ascii_letters[:26]
@saucecode
saucecode / aoc3.c
Created December 3, 2017 11:59
my C99 solution to advent of code 2017 day 3 part 2
#include <stdint.h>
#include <stdio.h>
#include <string.h>
// returns the sum of all 8 adjacent cells to element [cy][cx] in a 2D array, with bounds checking
uint32_t setdata(uint32_t root_max, uint32_t data[][root_max], uint32_t cx, uint32_t cy){
uint32_t counter = 0;
if(cx + 1 < root_max){
counter += data[cy][cx+1];
if(cy - 1 >= 0)
@saucecode
saucecode / threeshears.py
Created June 12, 2017 09:58
an attempt at the three shears image rotation problem. Reads from first.png, outputs to out.png
import math
from PIL import Image, ImageDraw
input_image = Image.open("first.png")
width,height = input_image.size
second_image = Image.new('RGB', input_image.size)
third_image = Image.new('RGB', input_image.size)
output_image = Image.new('RGB', input_image.size)
# draw = ImageDraw.Draw(output_image)
@saucecode
saucecode / compile.sh
Created December 30, 2016 17:44
dlopen example
g++ -fPIC -c hello.cpp
g++ -shared -o hello.so hello.o
g++ main.cpp -ldl
std::vector<projectile_t*> projectiles;
// ...
projectiles.erase(
std::remove_if(projectiles.begin(), projectiles.end(),
[](projectile_t *p){ return p->life <= 0.0; }),
projectiles.end()
);
@saucecode
saucecode / challenge277.c
Created July 29, 2016 17:31
julia set generator for /r/dailyprogramming challenge 277 https://redd.it/4v5h3u
// challenge 277 hard 2016-07-29 /r/dailyprogrammer https://redd.it/4v5h3u
// compile: $ gcc -std=c99 challenge277.c -lm
// outputs to: fractal.tga
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <complex.h>
@saucecode
saucecode / challenge248.c
Last active January 5, 2016 20:24
first working version
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define PI 3.14159265
// https://www.reddit.com/r/dailyprogrammer/comments/3zfajl/20160104_challenge_248_easy_draw_me_like_one_of/
struct rgb_t {
unsigned char r;
0 0 7 0 0 0 2 2 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 2 2 2
0 0 7 0 0 0 2 2 2 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 2 2 2 0 0 0
2 2 2 0 0 0 0 0 0 0 0 0 2 2 2