Skip to content

Instantly share code, notes, and snippets.

@Voltara
Voltara / day04-regex.pl
Created December 4, 2017 05:59
Advent of Code 2017 Day 4, Perl regex
#! /usr/bin/env perl
use strict;
use warnings;
my @part;
for (<>) {
@_ = split;
$part[1]++ unless m/\b(\w+)\b.*\b\1\b/;
$part[2]++ unless m/\b(\w)(\w?+)(\w?+)(\w?+)(\w?+)(\w?+)(\w?+)\b.*\b(?:\1\2\3\4\5\6\7|\1\2\3\4\5\7\6|\1\2\3\4\6\5\7|\1\2\3\4\6\7\5|\1\2\3\4\7\5\6|\1\2\3\4\7\6\5|\1\2\3\5\4\6\7|\1\2\3\5\4\7\6|\1\2\3\5\6\4\7|\1\2\3\5\6\7\4|\1\2\3\5\7\4\6|\1\2\3\5\7\6\4|\1\2\3\6\4\5\7|\1\2\3\6\4\7\5|\1\2\3\6\5\4\7|\1\2\3\6\5\7\4|\1\2\3\6\7\4\5|\1\2\3\6\7\5\4|\1\2\3\7\4\5\6|\1\2\3\7\4\6\5|\1\2\3\7\5\4\6|\1\2\3\7\5\6\4|\1\2\3\7\6\4\5|\1\2\3\7\6\5\4|\1\2\4\3\5\6\7|\1\2\4\3\5\7\6|\1\2\4\3\6\5\7|\1\2\4\3\6\7\5|\1\2\4\3\7\5\6|\1\2\4\3\7\6\5|\1\2\4\5\3\6\7|\1\2\4\5\3\7\6|\1\2\4\5\6\3\7|\1\2\4\5\6\7\3|\1\2\4\5\7\3\6|\1\2\4\5\7\6\3|\1\2\4\6\3\5\7|\1\2\4\6\3\7\5|\1\2\4\6\5\3\7|\1\2\4\6\5\7\3|\1\2\4\6\7\3\5|\1\2\4\6\7\5\3|\1\2\4\7\3\5\6|\1\2\4\7\3\6\5|\1\2\4\7\5\3\6|\1\2\4\7\5\6\3|\1\2\4\7\6\3\5|\1\2\4\7\6\5\3|\1\2\5\3\4\6\7|\1\2\5\3\4\7\6|\1\2\5\3\6\4\7|\1\2\5\3\6\7\4|\1\2\5\3\7\4\6|\1\2\5\3\7\6\4|\1\2\5\4\3\6\7|\1\
@Voltara
Voltara / speedsolving-hotkey-fixer.js
Created September 4, 2018 19:37
Tampermonkey script to work around issues with SpeedSolving forum hotkeys
// ==UserScript==
// @name SpeedSolving Hotkey Fixer
// @namespace https://voltara.org/
// @version 0.1
// @description Work around glitchy SpeedSolving forum hotkeys
// @author Voltara
// @match https://www.speedsolving.com/forum/*
// @grant none
// ==/UserScript==
@Voltara
Voltara / day03.cu
Created December 3, 2018 17:01
Advent of Code 2018 Day 3 Part 1, CUDA
// nvcc -O3 day03.cu
#include <cstdio>
#include <vector>
struct input_t { int id, x0, y0, x1, y1; };
static __device__ void reduce(int *out, int *in) {
volatile int *vin = in;
int tid = threadIdx.x;
__syncthreads();
@Voltara
Voltara / hashsimd.cpp
Created December 4, 2018 07:06
Advent of Code Day 2 Part 2
// clang++ -O3 -march=native -std=c++17 hashsimd.cpp
#include <cstdio>
#include <vector>
#include <array>
#include <algorithm>
#include <x86intrin.h>
#include <inttypes.h>
static uint64_t hash(const __m256i &m);
@Voltara
Voltara / day05-optimized.pl
Created December 5, 2018 19:07
Advent of Code 2018 Day 5 "Optimized" brute force
#! /usr/bin/perl
chomp(my $in = <>);
@_ = sort { $a <=> $b } react($in), map { react($in =~ s/$_//rig) } "a".."z";
print "Part 1: $_[$#_]\n";
print "Part 2: $_[0]\n";
sub react {
@Voltara
Voltara / day14.cpp
Created December 17, 2018 01:37
Advent of Code Day 14 Optimized
// clang++ -O3 -march=native day14.cpp -o day14
#include <string>
#include <array>
#include <cstdint>
#include <algorithm>
#include <x86intrin.h>
// Recipes 0..22 precomputed
static constexpr std::array<uint8_t, 23> BASE = {
3,7,1,0,1,0,1,2,4,5,1,5,8,9,1,6,7,7,9,2,5,1,0 };
@Voltara
Voltara / day23part2.cpp
Created December 28, 2018 05:48
Advent of Code 2018 Day 23 Part 2
// clang++ -march=native -O3 day23part2.cpp -o day23part2
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <functional>
#include <algorithm>
// https://en.wikipedia.org/wiki/Q*bert#/media/File:Qbert.png
@Voltara
Voltara / advent2017d7p2.cpp
Last active December 8, 2019 05:38
Advent of Code 2017 Day 7 Part 2, Dynamic Programming solution
#include <cstdio>
#include <cstdlib>
#include <vector>
using vec = std::vector<int>;
/* Bare bones implementation of the intcode vm for Day 7 Part 2
* When run with a phase setting of 5, 6, 7, 8, or 9, returns
* an array of numbers that represents the effect of each
* amplification stage (i.e., iteration of the feedback loop):
@Voltara
Voltara / day16vanity.cpp
Created December 16, 2019 23:14
Advent of Code 2019 Day 16 Vanity Input Generator
#include <cstdio>
#include <cstdint>
#include <vector>
#include <array>
#include <random>
using int_t = long long;
using vec = std::vector<int_t>;
using arr8 = std::array<int8_t, 8>;
@Voltara
Voltara / day17tricky.intcode
Last active December 17, 2019 20:09
Advent of Code 2019 Day 17 Tricky Input
1,330,331,332,109,3470,1101,1182,0,15,1101,1481,0,24,1002,0,1,570,1006,570,36,1001,571,0,0,1001,570,-1,570,1001,24,1,24,1105,1,18,1008,571,0,571,1001,15,1,15,1008,15,1481,570,1006,570,14,21102,1,58,0,1106,0,786,1006,332,62,99,21101,0,333,1,21102,73,1,0,1105,1,579,1102,0,1,572,1101,0,0,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,102,1,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,0,340,1,1105,1,177,21102,477,1,1,1106,0,177,21101,514,0,1,21101,176,0,0,1106,0,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1002,572,1,1182,21101,375,0,1,21101,0,211,0,1106,0,579,21101,1182,11,1,21102,222,1,0,1105,1,979,21102,388,1,1,21101,233,0,0,1105,1,579,21101,1182,22,1,21102,1,244,0,1105,1,979,21102,401,1,1,21101,255,0,0,1105,1,579,21101,1182,33,1,21101,266,0,0,1106,0,979,21101,414,0,1,21102,1,277,0,1105,1,579,3,575,