Skip to content

Instantly share code, notes, and snippets.

View thquinn's full-sized avatar

Tom Quinn thquinn

View GitHub Profile
@thquinn
thquinn / sympy_juggling.py
Created April 28, 2024 04:33
A not-very-fast symbolic physics simulation using SymPy.
# rewrite in SymEngine? https://github.com/symengine/symengine
# seems to not have an analogue to solve()
# or: https://www.sagemath.org/
# we might be able to specify a range for t in sp.solve to reduce solve times?
# algo:
# - start at t=0 with two line segments and an empty list of circles, and repeat the following
# - find collision times between all pairs of circles and all circle/segment pairs
# - filter out all collisions that don't take place at the min time
# - if the min time is less than or equal to the next spawn time:
@thquinn
thquinn / cantor_order_integers.py
Created August 4, 2023 02:29
List the positive integers in Cantor unpacking order of their prime factorizations.
from numpy import prod
# Can we reorder the positive integers based on a logical ordering of their prime factorizations?
# If we could iterate through all finite-sized tuples of nonnegative integers, we could increment
# the first element of each to uniquely cover all possible prime factorizations.
# We can extend and invert the Cantor pairing function to generate all k-tuples for any positive k,
# but now we're only iterating through the integers with highest prime factor p(k).
@thquinn
thquinn / HilbertCalc.cs
Created August 1, 2023 07:55
In the limit Hilbert curve, what percentage of order 1 Hilbert curves that appear in it are "right side up"?
using System;
// In the limit Hilbert curve, what percentage of order 1 Hilbert curves that appear in it are "right side up"?
namespace HilbertCalc {
class Program {
static void Main(string[] args) {
ulong[] curves = new ulong[] { 1, 0, 0, 0 }; // index 0 is "right side up," each subsequent index is 90 degrees counterclockwise
for (int i = 1; i <= 20; i++) {
Console.WriteLine($"Order {i} Hilbert curve:");
ulong sum = curves[0] + curves[1] + curves[2] + curves[3];
@thquinn
thquinn / gray_coded_partitions.py
Last active February 9, 2023 17:24
Enumerates integer partitions in Gray-code order
# An implementation of Dr. Carla Savage's algorithm described in her
# 1989 paper "Gray code sequences of partitions"
# https://www.sciencedirect.com/science/article/abs/pii/0196677489900072
# Referred to corrections made in a lecture by Dr. Sriram Pemmaraju
# https://homepage.cs.uiowa.edu/~sriram/196/fall01/lecture7.pdf
# Implemented by Tom Quinn (https://thquinn.github.io/)
# I've made my own corrections, see the comments.
@thquinn
thquinn / MTGOTrophyScraper.cs
Last active August 9, 2021 16:58
Scrapes the MTGO trophy leaderboard and keeps a Gist updated
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ManagedWinapi; // this can be found here: http://mwinapi.sourceforge.net/
using System.Windows.Forms;
using System.Drawing;
using Octokit; // this is from NuGet
@thquinn
thquinn / Santaman.cs
Last active July 16, 2023 21:59
Quick 'n' dirty Stitcher Premium bulk downloader. Windows build: https://github.com/thquinn/thquinn.github.io/releases/tag/Santaman
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Xml;
namespace Santaman
{
@thquinn
thquinn / NearWinMonteCarlo.cs
Last active December 8, 2020 18:15
Runs simplified goldfish games of Penny Dreadful Near-Death Experience Combo.
// Runs simplified goldfish games of Penny Dreadful Near-Death Experience Combo. Simplifications include:
// - no interaction from the opponent, obviously
// - doesn't simulate cards besides combo pieces and lands
// - no maximum hand size
// - Lost Auramancers doesn't actually remove NDE from the deck
// - generally poor decision making
// - lots of other stuff (see inline comments)
using System;
using System.Collections.Generic;
@thquinn
thquinn / spiralmelee.py
Created April 13, 2020 00:00
Drawing the patterns of N players' go stones placed in a spiral
import numpy as np, PIL
from PIL import Image
from queue import Queue
def within(board, coor):
return coor[0] >= 0 and coor[1] >= 0 and coor[0] < board.shape[0] and coor[1] < board.shape[1]
def get_neighbors(coor):
return [(coor[0] - 1, coor[1]), (coor[0] + 1, coor[1]), (coor[0], coor[1] - 1), (coor[0], coor[1] + 1)]
def next_diamond_coor(coor):
# Center
@thquinn
thquinn / KabufudaSolver.cs
Created September 25, 2019 13:01
A quick 'n' dirty solver for Eliza's Kabufuda Solitaire
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KabufudaSolver {
class Program {
static void Main(string[] args) {
Board board = new Board(Console.ReadLine(), int.Parse(Console.ReadLine()));
@thquinn
thquinn / waveforms.js
Created July 15, 2018 16:41
Waveform visualizer for the Math Square exhibit at MoMath
/* MoMath Math Square Behavior
*
* Title: Waveforms
* Description: stand on the knobs to combine simple waveforms into something
* more complex, stand on the wave to distort it
* Framework: P5
* Author: Tom Quinn <thquinn.github.io>
* Created: 2017-07
* Status: works
*/