This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = |