Skip to content

Instantly share code, notes, and snippets.

View Karamell's full-sized avatar
:octocat:

Bård Rolstad Henriksen Karamell

:octocat:
View GitHub Profile
@Karamell
Karamell / aoc2020day23.fsx
Last active December 27, 2020 12:25
Advent of Code 2020 day 23
#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
@Karamell
Karamell / aoc2020day25.fsx
Created December 25, 2020 06:21
Advent of Code 2020 day 25 in F#
#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'
@Karamell
Karamell / aoc2020day24.fsx
Created December 24, 2020 07:34
Advent of Code 2020 day 24 in F#
#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}
@Karamell
Karamell / aoc2020day22.fsx
Last active December 22, 2020 06:30
Advent of Code 2020 day 22 in F#
#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 =
@Karamell
Karamell / aoc2020day21.fsx
Created December 21, 2020 07:19
Advent of Coed 2020 day 21 in F#
#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)
@Karamell
Karamell / aoc2020day20.fsx
Last active December 20, 2020 10:51
Advent of Code 2020 day 20
#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) =
@Karamell
Karamell / aoc2020day19.fsx
Created December 19, 2020 16:13
Advent of Code 2020 day 19 in F#
#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 =
@Karamell
Karamell / aoc2020day18.fsx
Created December 18, 2020 10:27
Advent of Code 2020 day 18 in F#
#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
@Karamell
Karamell / aoc2020day4.pl
Created December 17, 2020 19:48
Advent of Code 2020 day 4 in Prolog.
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]),
@Karamell
Karamell / aoc2020-17-2.fsx
Last active December 17, 2020 11:08
Advent of code 2020 day 17 part 2 in F#
#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' ->