Skip to content

Instantly share code, notes, and snippets.

open System.Collections
open System.Collections.Generic
let inline (<+>) (left : string) (right : string) =
if left.Contains(right) then left
elif right.Contains(left) then right
else
let nLeft = left.Length
let rec merge depth =
@SpaceAntelope
SpaceAntelope / obliques.fsx
Last active February 29, 2016 23:26
A bit of a roundabout sort of way of turning a matrix to a set of obliques, and then turning it back to a matrix again
type ObliqueKind = Wide | Tall | Square
let (|FirstGreater|FirstLesser|BothEqual|) = function 1 -> FirstGreater | -1 -> FirstLesser | 0 -> BothEqual
let ParseTextInput (input : string ) =
input.Split('\n')
|> Array.where (fun line -> System.String.IsNullOrEmpty(line) |> not )
|> Array.map (fun line -> System.Text.RegularExpressions.Regex.Split(line.Trim(),"\s+") |> Array.map(int))
let TraceObliqueFromStartingPoint rowCount (rowIndex,colIndex) =
@SpaceAntelope
SpaceAntelope / Presidents.csx
Last active March 8, 2016 07:31
Paste into a C# Interactive window and press enter.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static LifeBoundary;
/*
* The idea is to use a stack to keep track of how many presidents
* are alive at a given time.
*
let CreateEmptySquare dim = Array.init dim (fun _ -> Array.create dim ' ')
// Needed to remove letters from the available letter set at each step
let MultisetSubtraction (source: 'a[]) (toRemove:'a[]) =
let filterIndex = System.Collections.Generic.Dictionary<'a,int>()
toRemove |> Array.iter(fun c-> if filterIndex.ContainsKey(c) then filterIndex.[c] <-filterIndex.[c] + 1 else filterIndex.Add(c,1))
source |> Array.choose (fun item ->
if filterIndex.ContainsKey(item) && filterIndex.[item] > 0
then
filterIndex.[item] <- filterIndex.[item] - 1