Skip to content

Instantly share code, notes, and snippets.

void Main()
{
string dict = @"C:\Users\Trinitek\Downloads\hunspell-en_US-2020.12.07\en_US.dic";
var words = File.ReadLines(dict)
.Skip(1)
.Select(l => string.Concat(l.ToLower().TakeWhile(c => c != '/')))
.Where(l => l.Length == 5)
.ToList();
@Trinitek
Trinitek / 01p1.cs
Last active December 14, 2021 05:33
Advent of Code 2021
void Main()
{
var measurements = Input.Trim().Split("\n").Select(s => int.Parse(s));
//measurements.Take(5).Dump();
//GetDeltas(measurements).Take(5).Dump();
var deltas = GetDeltas(measurements);
deltas.Count(d => d >= 0).Dump();
@Trinitek
Trinitek / advent2019-1.cs
Last active December 6, 2020 03:15
Advent of Code 2019
void Main()
{
var masses = Input.Split("\n", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).Select(i => int.Parse(i));
masses.Sum(m => GetRequiredFuel(m)).Dump();
}
int GetRequiredFuel(int mass)
{
int fuelMass = (mass / 3) - 2;
@Trinitek
Trinitek / advent2020-10.cs
Last active December 10, 2020 15:10
Advent of Code 2020
void Main()
{
IList<Adapter> GetAdapters(string input)
{
var parsedAdapters = input
.Split("\n", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(i => new Adapter(int.Parse(i)))
.OrderBy(a => a.Rating);
var adapters = parsedAdapters.Append(new Adapter(parsedAdapters.Last().Max)).ToList();
@Trinitek
Trinitek / advent2017-2.cs
Last active December 4, 2020 04:28
AdventOfCode 2017
void Main()
{
var lines = Input.Trim().Split("\n").Select(l => l.Trim());
int checksum = 0;
foreach (var line in lines)
{
var row = Row.Parse(line);
//row.cells.Dump();
//checksum += row.Difference;
public class EnumToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (Enum.IsDefined(value.GetType(), value) == false)
{
Debug.WriteLine("{0}: {1}: {2}: Value not defined in enum. Fallback to UnsetValue. {3}, {4}", nameof(EnumToBooleanConverter), GetHashCode(), nameof(Convert), value, value.GetType());
return DependencyProperty.UnsetValue;
}
[STAThread]
static void Main(string[] args)
{
while(true)
{
Console.WriteLine("ID?");
var id = Console.ReadLine();
Console.WriteLine(Decrement(id));
}
string BytesAsString(byte[] input)
{
var sb = new StringBuilder();
sb.Append("{\n ");
int i;
for (i = 0; i < input.Length; i++)
{
@Trinitek
Trinitek / Day3.cs
Created December 4, 2017 19:17
Advent of Code 2017 Day 3
using System;
namespace AdventOfCode2017
{
public static class Day3
{
public static string GetSolution()
{
int input = 277678;
@Trinitek
Trinitek / union.c
Last active October 25, 2016 06:21
#include <stdio.h>
/*
* Here, we define a structure that groups 2 chars together as an
* addressable unit.
*
* Due to the nature of the way x86 processors copy multi-byte values
* to and from memory (this trait is known as endianness), the high
* and low bytes are flipped here in this structure. The x86
* architecture is a "little-endian" architecture, which means that