Skip to content

Instantly share code, notes, and snippets.

View thquinn's full-sized avatar

Tom Quinn thquinn

View GitHub Profile
@thquinn
thquinn / Program.cs
Created June 14, 2024 18:39
LLM text generation without using the letter 'e'.
// .NET 8.0, uses LLamaSharp and LLamaSharp's CUDA backend NuGet packages.
using LLama.Common;
using LLama;
using System.Text;
using Laureate;
using LLama.Native;
using LLama.Batched;
string modelPath = @"C:/Users/Cae/Downloads/noromaid-v0.4-mixtral-instruct-8x7b-zloss.Q3_K_M.gguf";
@thquinn
thquinn / sagemath_juggling.py
Last active June 2, 2024 07:24
A not-very-fast symbolic physics simulation using SymPy.
import os
import sage.all as sage
from itertools import combinations
from PIL import Image, ImageDraw
from typing import cast, Dict
from enum import Enum
os.system("clear")
class SimCircle:
@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()));