Skip to content

Instantly share code, notes, and snippets.

View bradleybauer's full-sized avatar

Bradley Bauer bradleybauer

View GitHub Profile
@bradleybauer
bradleybauer / mdarray.hxx
Last active May 4, 2023 18:27
Sweet sweet syntactic sugar for simple multidimensional arrays.
#include <array>
#include <vector>
#include <iostream>
using i64 = long long int;
// first implementation
// template<typename T, int Size, int... Sizes>
// struct mdarray {
// template <typename... Is>
@bradleybauer
bradleybauer / duplicates.py
Last active September 24, 2022 20:14
Find duplicates in a dataset of pytorch tensors that is too large to load entirely into memory.
# BB Note: Because I now store images in PNG format I could just compare PNG byte buffers.
#
# so... this code is not necessary anymore.
from random import randint,shuffle
import hashlib
import shutil
import torchvision as tv
import torch as th
@bradleybauer
bradleybauer / combined_algorithm.py
Last active November 2, 2023 22:38
A single, parameterized, algorithm solves two different enumeration problems: number partitions and k sized subsets of multisets.
# combined_algorithm.py
# A single, parameterized, algorithm solves two different enumeration problems: number partitions and k sized subsets of multisets.
def fill_from_right(k, array, capacities, get_value):
for i in range(len(array)):
assert (array[i] == 0)
while array[i] < capacities[i] and k > 0:
array[i] += 1
k -= get_value(i)
if k == 0:
def partition_enumeration(n):
counts = [0]*(n+1) # n+1 to allow 1 based indexing
counts[1] = n
first_non_empty_slot = 1
while counts[n] == 0:
yield [(length+1, count) for length, count in enumerate(counts[1:]) if count != 0]
# starting from slot i=first_non_empty_slot move enough dots to slot 1
# to create a dot at slot i+1 using dots at slot 1
for i in range(first_non_empty_slot, n+1):
if counts[i] != 0:
Disorderly Escape
=================
Oh no! You've managed to free the bunny prisoners and escape Commander Lambdas exploding space station, but her team of elite starfighters has flanked your ship. If you dont jump to hyperspace, and fast, youll be shot out of the sky!
Problem is, to avoid detection by galactic law enforcement, Commander Lambda planted her space station in the middle of a quasar quantum flux field. In order to make the jump to hyperspace, you need to know the configuration of celestial bodies in the quadrant you plan to jump through. In order to do *that*, you need to figure out how many configurations each quadrant could possibly have, so that you can pick the optimal quadrant through which youll make your jump.
There's something important to note about quasar quantum flux fields' configurations: when drawn on a star grid, configurations are considered equivalent by grouping rather than by order. That is, for a given set of configurations, if you exchange the position of any two colum
class ChainProcessor {
var arg = '';
var didUpdateArg = false;
bool isComputing = false;
void _computation() {
// do stuff
}
void chain() async {
@bradleybauer
bradleybauer / collatz.py
Created November 5, 2021 02:32
Code that halts iff the collatz conjecture is false. Taken from https://www.youtube.com/watch?v=kW8gogF0t38 . It uses the tortoise and the hare algorithm to check for cycles which is pretty cool!.
def f(x):
if x % 2 == 0:
return x // 2
return 3 * x + 1
def check():
n = 1
while 1 > 0:
n = n + 1
a = n
int main() {
Config* config = new Config;
Programs* programs = new Programs;
Renderer* renderer = new Renderer;
Window* window = new Window;
while (true) {
if (user_config_changed()) {
logger.log("Updating state.");
int main() {
Config* config = new Config;
Programs* programs = new Programs;
Renderer* renderer = new Renderer;
Window* window = new Window;
while (true) {
if (user_config_changed()) {
logger.log("Updating state.");
#include <bits/stdc++.h>
using namespace std;
#include <range/v3/all.hpp>
namespace views = ranges::views;
mt19937 generator(1252414);
struct Agent {
int id{};
int score{};