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
def take(n, seq): | |
return list(islice(seq, n)) | |
def enumerate(iterable): | |
return izip(count(), iterable) | |
def tabulate(function): | |
"Return function(0), function(1), ..." | |
return imap(function, count()) |
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.IO | |
open FParsec | |
// parsers | |
let parseDecimal : Parser<decimal, unit> = puint64 |>> decimal | |
let strWs s = pstring s >>. spaces | |
let parseTerm expression = (parseDecimal .>> spaces) <|> between (strWs "(") (strWs ")") expression | |
let runParser expr str = | |
match run expr str with |
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.IO | |
type InnerBag = { | |
InnerBagName: string | |
InnerBagQuantity: int | |
} | |
let rec parseInnerBags acc = function | |
| [] | "no"::"other"::["bags."] -> acc |
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
module Main where | |
import qualified Data.Map.Strict as M | |
import Data.Maybe (mapMaybe) | |
type Coordinate = (Int, Int) | |
toCoordinateMap :: [[a]] -> M.Map (Int, Int) a | |
toCoordinateMap a = M.fromList $ do | |
(y, row) <- zip [0 ..] a |
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
import math | |
lines = [ | |
"Faerun to Norrath = 129", | |
"Faerun to Tristram = 58", | |
"Faerun to AlphaCentauri = 13", | |
"Faerun to Arbre = 24", | |
"Faerun to Snowdin = 60", | |
"Faerun to Tambi = 71", | |
"Faerun to Straylight = 67", |
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
function () { | |
var concatOptionals; | |
this.set = function (obj, property) { | |
return function (value) { | |
obj[property] = value; | |
return obj; | |
}; | |
}; |
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 puzzleInput = | |
[1;0;0;3;1;1;2;3;1;3;4;3;1;5;0;3;2;10;1;19;1;19;9;23;1;23;6;27;2;27;13;31;1;10;31;35;1;10;35;39;2;39;6;43;1;43;5;47;2;10;47;51;1;5;51;55;1;55;13;59;1;59;9;63;2;9;63;67;1;6;67;71;1;71;13;75;1;75;10;79;1;5;79;83;1;10;83;87;1;5;87;91;1;91;9;95;2;13;95;99;1;5;99;103;2;103;9;107;1;5;107;111;2;111;9;115;1;115;6;119;2;13;119;123;1;123;5;127;1;127;9;131;1;131;10;135;1;13;135;139;2;9;139;143;1;5;143;147;1;13;147;151;1;151;2;155;1;10;155;0;99;2;14;0;0] | |
|> List.mapi (fun i v -> (i, v)) | |
|> Map.ofList | |
let getOpCodeAction : int -> (int -> int -> int) option = function | |
| 1 -> Some (+) | |
| 2 -> Some (*) | |
| _ -> None |
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
module Day6Part2 where | |
import Data.List ((\\), nub) | |
import Data.Graph | |
input :: [(String, String)] | |
input = | |
[("CYJ","BQR"),("KX8","YWJ"),("45Z","R38"),("N95","Z8Z"),("KG2","1MS"),("GM6","DB2"),("TR1","HH5"),("WTY","P2L"),("K8J","SSK"),("VD6","RZ3"),("NPK","V1G"),("1T5","49D"),("TH3","MGC"),("23D","F12"),("YRS","MNC"),("QHP","MJV"),("GRR","39N"),("6BV","D8T"),("3Y9","XNY"),("J2H","FXH"),("SDC","172"),("LCB","1D1"),("G2G","KM3"),("5SS","2QY"),("QRJ","64S"),("PXZ","SHW"),("MNY","Q1X"),("6KN","XJD"),("HVK","M5Y"),("X5R","H48"),("NSB","NK4"),("DPM","927"),("S22","B1L"),("5MN","SF4"),("RPP","BPC"),("W58","1Y6"),("XSN","FT9"),("3TM","WY7"),("JQQ","LZJ"),("VNH","K9T"),("KG8","HG4"),("2TJ","DKJ"),("MHG","G38"),("1QQ","HJC"),("92Y","RZW"),("5M1","QKD"),("YKP","NSR"),("3VN","3CM"),("3FL","JS6"),("TJV","YFT"),("6DD","CWH"),("GKV","8PS"),("5VG","4KC"),("1ZM","6P8"),("RZ3","GGJ"),("NM1","1DV"),("SYQ","7XV"),("T1H","NV8"),("9Q1","B3P"),("GY8","SWJ"),("X6R","2VM"),("TGP","TDS"),("HGB","WZV"),("VFF","XB8"),("2BJ","3V6"),(" |
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
module Day6Part1 where | |
import Data.List (findIndex, nub, (\\)) | |
import Data.Graph | |
import Data.Tree (levels) | |
import Data.Maybe (fromMaybe) | |
input :: [(String, String)] | |
input = | |
[("CYJ","BQR"),("KX8","YWJ"),("45Z","R38"),("N95","Z8Z"),("KG2","1MS"),("GM6","DB2"),("TR1","HH5"),("WTY","P2L"),("K8J","SSK"),("VD6","RZ3"),("NPK","V1G"),("1T5","49D"),("TH3","MGC"),("23D","F12"),("YRS","MNC"),("QHP","MJV"),("GRR","39N"),("6BV","D8T"),("3Y9","XNY"),("J2H","FXH"),("SDC","172"),("LCB","1D1"),("G2G","KM3"),("5SS","2QY"),("QRJ","64S"),("PXZ","SHW"),("MNY","Q1X"),("6KN","XJD"),("HVK","M5Y"),("X5R","H48"),("NSB","NK4"),("DPM","927"),("S22","B1L"),("5MN","SF4"),("RPP","BPC"),("W58","1Y6"),("XSN","FT9"),("3TM","WY7"),("JQQ","LZJ"),("VNH","K9T"),("KG8","HG4"),("2TJ","DKJ"),("MHG","G38"),("1QQ","HJC"),("92Y","RZW"),("5M1","QKD"),("YKP","NSR"),("3VN","3CM"),("3FL","JS6"),("TJV","YFT"),("6DD","CWH"),("GKV","8PS"),("5VG","4KC"),("1ZM","6P8"),("RZ3","GGJ"),("NM1","1DV"),("SYQ","7XV"),("T1H","NV8"),("9Q1","B3P"),("GY8","SWJ"),("X6R |
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
from collections import deque | |
from abc import abstractmethod | |
puzzle_input = deque([3,225,1,225,6,6,1100,1,238,225,104,0,1002,114,19,224,1001,224,-646,224,4,224,102,8,223,223,1001,224,7,224,1,223,224,223,1101,40,62,225,1101,60,38,225,1101,30,29,225,2,195,148,224,1001,224,-40,224,4,224,1002,223,8,223,101,2,224,224,1,224,223,223,1001,143,40,224,101,-125,224,224,4,224,1002,223,8,223,1001,224,3,224,1,224,223,223,101,29,139,224,1001,224,-99,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1101,14,34,225,102,57,39,224,101,-3420,224,224,4,224,102,8,223,223,1001,224,7,224,1,223,224,223,1101,70,40,225,1102,85,69,225,1102,94,5,225,1,36,43,224,101,-92,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1102,94,24,224,1001,224,-2256,224,4,224,102,8,223,223,1001,224,1,224,1,223,224,223,1102,8,13,225,1101,36,65,224,1001,224,-101,224,4,224,102,8,223,223,101,3,224,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1 |
NewerOlder