Skip to content

Instantly share code, notes, and snippets.

View theburningmonk's full-sized avatar

Yan Cui theburningmonk

View GitHub Profile
@theburningmonk
theburningmonk / Day17_hash.fsx
Created December 18, 2016 18:34
Advent of Code (Day 17)
open System.Text
open System.Security.Cryptography
let input = "udskfozm"
let width, height = 4, 4
let md5 = CryptoConfig.CreateFromName("MD5") :?> HashAlgorithm
let hash (input : string) =
let bytes = input |> Encoding.UTF8.GetBytes |> md5.ComputeHash
@theburningmonk
theburningmonk / Day17_Part1.fsx
Created December 18, 2016 18:33
Advent of Code (Day 17)
let part1 = findPaths input |> Seq.tryHead
@theburningmonk
theburningmonk / Day17_Part2.fsx
Created December 18, 2016 18:33
Advent of Code (Day 17)
let part2 = findPaths input |> Seq.map String.length |> Seq.max
@theburningmonk
theburningmonk / Day17_common.fsx
Created December 18, 2016 18:32
Advent of Code (Day 17)
open System
open System.Text
open System.Security.Cryptography
let input = "udskfozm"
let width, height = 4, 4
let md5 = CryptoConfig.CreateFromName("MD5") :?> HashAlgorithm
let hash (input : string) =
@theburningmonk
theburningmonk / Day16_common.fsx
Created December 17, 2016 13:41
Advent of Code (Day 16)
let input = "11011110011011101" |> Seq.map ((=) '1') |> Seq.toArray
let solve diskSize input =
let rec dragonCurve (a : bool[]) =
if a.Length >= diskSize
then a.[0..diskSize-1]
else
[|
yield! a
yield false
@theburningmonk
theburningmonk / Day15_Part2.fsx
Created December 16, 2016 03:29
Advent of Code (Day 15)
let input2 = input1 @ [ { Number = 7; Positions = 11; Time0Pos = 0 } ]
let part2 = solve input2
@theburningmonk
theburningmonk / Day15_Part1.fsx
Created December 16, 2016 03:29
Advent of Code (Day 15)
type Disc =
{
Number : int
Positions : int
Time0Pos : int
}
let solve (discs : Disc list) =
// what's the first time we can press and get through the first slot?
let fstDisc = discs.[0]
let hex =
seq {
yield! Seq.zip { 0uy..9uy } { '0'..'9' }
yield! Seq.zip { 10uy..15uy } { 'a'..'f' }
}
|> Map.ofSeq
let hash (input : string) =
let bytes = input |> Encoding.UTF8.GetBytes |> md5.ComputeHash
let chars = Array.zeroCreate<char> (bytes.Length * 2)
@theburningmonk
theburningmonk / Day14_Part2.fsx
Last active December 15, 2016 12:25
Advent of Code (Day 14)
let keyStretch (input : string) =
{ 0..2016 } |> Seq.fold (fun last _ -> hash last) input
let part2 = solve keyStretch
@theburningmonk
theburningmonk / Day14_Part1.fsx
Last active December 15, 2016 12:07
Advent of Code (Day 14)
open System
open System.Collections.Generic
open System.Text
open System.Security.Cryptography
let input = "ahsbgdzn"
let md5 = CryptoConfig.CreateFromName("MD5") :?> HashAlgorithm
let hash (input : string) =