This file contains hidden or 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
| #time "on" | |
| module Cup = | |
| let build (inp:string) count = | |
| let input = inp |> Seq.map (string >> int) |> Seq.toList | |
| let first = input |> List.head | |
| let arr0 = | |
| let a0 = Array.init(input.Length + 1) (fun _ -> 0) | |
| input |> List.pairwise |> List.iter(fun (a, b) -> a0.[a] <- b) | |
| a0 |
This file contains hidden or 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
| #time "on" | |
| let cpk, dpk = System.IO.File.ReadLines( __SOURCE_DIRECTORY__ + "/input.txt") |> Seq.toList |> fun [a;b] -> int64 a, int64 b | |
| let magic = 20201227L | |
| let rec transform no sn n = seq { | |
| yield no, n | |
| let n' = (n * sn) % magic | |
| yield! transform (no + 1) sn n' |
This file contains hidden or 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
| #time "on" | |
| let txt = System.IO.File.ReadLines( __SOURCE_DIRECTORY__ + "/input.txt") |> Seq.toList | |
| type Directions = E | SE | SW | W | NW | NE | |
| type P = {x : int; y : int} | |
| module Directions = | |
| let move p = function | |
| | E -> {p with x = p.x + 2} |
This file contains hidden or 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
| #time "on" | |
| let txt = System.IO.File.ReadAllText( __SOURCE_DIRECTORY__ + "/input.txt").Trim() | |
| let player1, player2 = | |
| let m = txt.Split("\n\n") |> Array.map(fun s -> s.Split("\n") |> Array.tail |> Array.map int |> Array.toList) | |
| m.[0], m.[1] | |
| let pressPlay1 () = | |
| let rec play p1 p2 = |
This file contains hidden or 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
| #time "on" | |
| let lines = System.IO.File.ReadAllLines ( __SOURCE_DIRECTORY__ + "/input.txt") | |
| let pars (l: string array) = | |
| l | |
| |> Array.map(fun line -> | |
| let [|f; a|] = line.Split("(") | |
| f.Trim().Split(" ") |> Array.toList, a.TrimEnd(')').Split(" ") | |
| |> Array.map(fun s -> s.TrimEnd(',')) |> Array.tail |> Array.toList) |
This file contains hidden or 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
| #time "on" | |
| let txt = System.IO.File.ReadAllText( __SOURCE_DIRECTORY__ + "/input.txt").Trim() | |
| type Image = char [,] | |
| type Tile = { Image: Image; Title: string } | |
| module Image = | |
| let size (img:Image) = img.[0.. ,0].Length | |
| let rotate (img:Image) = |
This file contains hidden or 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
| #time "on" | |
| let txt = System.IO.File.ReadAllText( __SOURCE_DIRECTORY__ + "/input.txt").Trim() | |
| type Rule = A | B | Rules of int list | OrRules of (int list) * (int list) | |
| module Rule = | |
| let parse (s:string) = | |
| let [|number; r|] = s.Split(":") | |
| let rule = |
This file contains hidden or 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
| #time "on" | |
| let lines = System.IO.File.ReadAllLines ( __SOURCE_DIRECTORY__ + "/input.txt") | |
| let parseLine l = l |> Seq.map id |> Seq.toList |> List.filter (fun c -> c <> ' ') | |
| let calc1 line = | |
| let rec calc (acc:int64) op = function | |
| | [] -> acc, [] | |
| | '+'::t -> calc acc (+) t | |
| | '*'::t -> calc acc ( * ) t |
This file contains hidden or 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
| main :- | |
| read_file_to_string("day04/input.txt", Input, []), | |
| atomic_list_concat(PStrings, '\n\n', Input), | |
| maplist(parse, PStrings, Passports), | |
| length(Passports, PCount), | |
| format('Parsed ~d passports.', [PCount]), nl, | |
| firstValidation(Passports, ValiderPassports), | |
| length(ValiderPassports, ValiderCount), nl, | |
| format('first validation count: ~d passports.', [ValiderCount]), |
This file contains hidden or 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
| #time "on" | |
| open System | |
| let lines = System.IO.File.ReadAllLines ( __SOURCE_DIRECTORY__ + "/input.txt") | |
| module Cube = | |
| let neighbours (x,y,z,w) = | |
| let n = [-1 .. 1] | |
| n |> List.collect(fun x' -> | |
| n |> List.collect(fun y' -> | |
| n |> List.collect(fun z' -> |
NewerOlder