Skip to content

Instantly share code, notes, and snippets.

List<List<string>> ReadCsv(string fileName) {
using var reader = new StreamReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
return ReadCsv(reader);
}
List<List<string>> ReadCsv(TextReader reader) {
var result = new List<List<string>>();
var currentRow = new List<string>();
var currentCell = new StringBuilder();
int c;
@tomtheisen
tomtheisen / day15
Last active December 20, 2018 17:26
AOC2018 Day15
const bool ShowSteps = false;
static readonly string[] Input = @"
################################
#########...####################
#########...###########.########
#########G..##########....######
##########..###########...######
#########G...##########...######
#########..G.###########..######
########...#.##########..#######
#ip 1
ip0 jmp ip17 // addi 1 16 1
ip1 r[5] = 1 // seti 1 1 5
ip2 r[2] = 1 // seti 1 4 2
ip3 r[3] = r[5] * r[2] // mulr 5 2 3
ip4 r[3] = r[3] == r[4] // eqrr 3 4 3
ip5 r[1] += r[3] // addr 3 1 1
ip6 jmp ip8 // addi 1 1 1
ip7 r[0] += r[5] // addr 5 0 0
ip8 r[2] += 1 // addi 2 1 2
@tomtheisen
tomtheisen / day23-2.linq
Last active January 4, 2019 19:44
AOC2018 day 23 part 2
<Query Kind="Program">
<Namespace>static System.Math</Namespace>
</Query>
struct Point3 {
public int X;
public int Y;
public int Z;
public Point3(int x, int y, int z) => (X, Y, Z) = (x, y, z);
public int ManhattanDist(Point3 other) => Abs(X - other.X) + Abs(Y - other.Y) + Abs(Z - other.Z);
@tomtheisen
tomtheisen / index.html
Last active February 6, 2019 15:02
Vendor Convert
<!DOCTYPE html>
<html>
<head>
<title>Vendor Convert</title>
<meta charset=utf-8>
<style>
body {
font-size: 200%;
font-family: sans-serif;
color: firebrick;
@tomtheisen
tomtheisen / app.ts
Created February 15, 2019 18:43
ts-loader bigint literal repro
let a = 3n;
@tomtheisen
tomtheisen / kolmogorov.stax
Last active August 11, 2019 04:55
This program will produce a stax program that outputs its input.
Ld_X store input in X
c"Initial size: `%"P
{
xx2B
xVp:SY{{Vpxaz:r-f}M keep only substrings that leave an unused ascii char after their removal
|=h#~
%RD{d find the length of the longest substring that occurs the most times
xx_B
y{{Vpxaz:r-f}M keep only substrings that leave an unused ascii char after their removal
|=h#
declare var $: any;
function select2EventDispatch(el: HTMLElement, events: string[]) {
let dispatching = false;
$.fn.select2 && $.fn.select2.amd.require(
["select2/utils"], function (Utils: any) {
const instance = Utils.GetData(el, "select2");
instance && events.forEach(ev => {
instance.on(ev, () => {
if (dispatching) return; else dispatching = true;
@tomtheisen
tomtheisen / gist:0b059caf2889fe54dacfb08ba5d3cf2a
Created August 30, 2019 15:57
Precise ToString() for double
using static System.Double;
using static System.Math;
using static System.Numerics.BigInteger;
using System.Numerics;
public static class DoubleConvert {
public static string Precisely(this double a) {
if (IsInfinity(a) || IsNaN(a)) return a.ToString();
if (a == 0) return 1 / a < 0 ? "-0.0" : "0.0";
BigInteger n = 0, d = 1, p = 1;
@tomtheisen
tomtheisen / aoc2019stax.md
Last active December 15, 2019 05:49
AOC2019 stax solutions

AOC2019 stax solutions

Here are some of my stax solutions for Advent of Code 2019. Input goes verbatim in the input box.

Day 1

Part 1