Skip to content

Instantly share code, notes, and snippets.

@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.
"""
@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 / 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 / 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 / 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 / day7gpt-2.cs
Created December 7, 2022 15:43
Advent of Code 2022 Day 7 Solve with ChatGPT doing the input parsing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdventOfCode
{
/* ChatGPT created class, Renamed by human to not conflict with System.IO.File */
public class AoCFile
/* PROMPT:
Help me parse this terminal output using C#. The output represents a series of `cd` and `ls` commands, these commands start with '$'. if a `cd` command is followed by `..` this means to move up a level. otherwise it means to navigate to the folder whose name is given.
The remaining output is either a file, which is shown by file size and followed by file name, or it is a directory which starts with `dir` and is followed by the directory name.
Here is an example input: */
using System;
// Create a list to store the containers
List<List<string>> containers = new List<List<string>>();
// Split the input string into lines
string[] lines = input.Split('\n');
// Loop through each column in the input
for (int col = 0; col < 35; col += 4)
{
// Create a list to store the entries in the current column
using System;
using System.Collections.Generic;
namespace CrateMover
{
class Program
{
static void Main(string[] args)
{
// Create a list of containers.
/* Creation of the initial image editor on startup */
34.788 PixelPaint(45:45): Image 0x00000018a567b6d0 has Undo Stack 0x00000018a567ba78
34.792 PixelPaint(45:45): Pushed action to 0x00000018a567ba78
34.800 PixelPaint(45:45): Switching tab to editor: ImageEditor(0x00000018a567b6d0)
45.390 PixelPaint(45:45): Completed action for editor 0x00000018a567b6d0, undo stack: 0x00000018a567ba78
/* Drawing and undoing brush on initial image editor */
45.394 PixelPaint(45:45): Pushed action to 0x00000018a567ba78
46.800 PixelPaint(45:45): Undo action for 0x00000018a567ba78
46.800 PixelPaint(45:45): Undo action for 0x00000018a567ba78