Skip to content

Instantly share code, notes, and snippets.

@tslater2006
tslater2006 / Day9Rope.cs
Created December 9, 2022 16:45
Advent of Code Day 9 Rope
class Rope
{
public HashSet<Point> VisitedPoints = new HashSet<Point>();
Point[] knots;
public Rope(int knotCount)
{
knots = new Point[knotCount];
for(var x = 0; x < knotCount; x++)
{
@tslater2006
tslater2006 / CodePointUTF8.cs
Created March 31, 2023 14:41
Converts from Unicode codepoint to UTF 8 and vice versa. Courtesy of GPT-4
using System.Text;
static byte[] UnicodeCodepointToUtf8(int codepoint)
{
if (codepoint >= 0 && codepoint <= 127)
{
return new byte[] { (byte)codepoint };
}
else if (codepoint >= 128 && codepoint <= 2047)
{
@tslater2006
tslater2006 / vallejo_color_extract.py
Created April 4, 2023 23:14
Extracts vallejo colors from their released color charts and puts into Real Color Mixer JSON format
import cv2
import pytesseract
from pytesseract import Output
import numpy as np
import re
import json
# Create a JSON object with a JSON array
palette = {
"name": "Vallejo Panzer Aces",
@tslater2006
tslater2006 / Day2.py
Last active December 2, 2023 22:44
OpenAI generated solution to AoC 2023 Day 2. Only change by me was to wrap the answers in a print() and gave a dummy file path
# Function to parse the game data from the input text
def parse_game_data(game_data):
games = {}
for line in game_data.strip().split('\n'):
if not line.startswith('Game'):
continue
game_id_str, *game_reveals_list = line.replace(':', ';').split(';')
game_id = int(game_id_str.split()[1])
game_reveals = []
for reveal in game_reveals_list:
@tslater2006
tslater2006 / OneToTwenty.py
Last active August 20, 2024 14:18
Simulates the 1-20 game found here (https://fleetfoxx.github.io/1-to-20/) to see how often this strategy wins.
"""
This script simulates a game where numbers are drawn randomly between 1 and 1000 and placed into 20 slots.
The goal is to place the numbers in the slots in the most optimal way to win the game.
Numbers cannot be rearranged after placement and must be strictly in ascending order.
The script keeps track of the number of games played and the minimum, maximum, and average number of games required to win.
To see a visual representation of the game, uncomment the replay_game function call and set number of games to 1.
In my testing it takes on average it takes around ~160,000 games to win one.
"""