Skip to content

Instantly share code, notes, and snippets.

View theburningmonk's full-sized avatar

Yan Cui theburningmonk

View GitHub Profile
{
"name": "config-api",
"version": "1.10.0",
"scripts": {
"integration-dev": "env TEST_MODE=handler env SERVERLESS_STAGE=dev env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-dev": "env TEST_MODE=http env SERVERLESS_STAGE=dev env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"integration-test": "env TEST_MODE=handler env SERVERLESS_STAGE=test env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-test": "env TEST_MODE=http env SERVERLESS_STAGE=test env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"integration-staging": "env TEST_MODE=handler env SERVERLESS_STAGE=staging env SERVERLESS_REGION=eu-west-1 ./node_modules/.bin/mocha test/test_cases -t 60000 --reporter spec",
"acceptance-staging": "env TEST_MODE=http env SERVERLESS_STAGE=staging env SERVERLESS_REGION
'use strict';
const co = require('co');
const chance = new require('chance').Chance();
const expect = require('chai').expect;
const lib = require('../lib/index');
const when = require('../steps/when');
const region = process.env.SERVERLESS_REGION;
describe(`Given there are a few config items`, () => {
@theburningmonk
theburningmonk / Day25_part1.fsx
Created December 27, 2016 23:39
Advent of Code (Day 25)
let part1 =
Seq.initInfinite id
|> Seq.find (fun n ->
execute [ "a", n ] instructions
|> Seq.take 1000
|> Seq.chunkBySize 2
|> Seq.forall (fun [| a; b |] -> a = 0 && b = 1))
@theburningmonk
theburningmonk / Day25_execute.fsx
Created December 27, 2016 23:35
Advent of Code (Day 25)
let execute initValues (instructions : Instruction[]) =
let registers = new Dictionary<string, int>()
initValues |> Seq.iter (fun (key, value) -> registers.[key] <- value)
let fetch = function
| Value n -> n
| Reg reg ->
match registers.TryGetValue reg with
| true, n -> n
| _ -> 0
@theburningmonk
theburningmonk / Day25_parse.fsx
Created December 27, 2016 23:33
Advent of Code (Day 25)
open System
open System.Collections.Generic
open System.IO
let inputs = File.ReadAllLines (__SOURCE_DIRECTORY__ + "/Day25Input.txt")
type Operant =
| Value of int
| Reg of string
@theburningmonk
theburningmonk / Day24_Part2.fsx
Created December 25, 2016 03:34
Advent of Code (Day 24)
let part2 =
let rec traverse current (nodes : Set<int>) finalDest acc =
if nodes.Count = 0 then acc + pairDistances.[current, finalDest]
else
nodes
|> Seq.map (fun next ->
let left = nodes.Remove next
let dist = pairDistances.[current, next]
traverse next left finalDest (acc + dist))
@theburningmonk
theburningmonk / Day24_Part1.fsx
Created December 25, 2016 03:33
Advent of Code (Day 24)
let part1 =
let rec traverse current (nodes : Set<int>) acc =
if nodes.Count = 0 then acc
else
nodes
|> Seq.map (fun next ->
let left = nodes.Remove next
let dist = pairDistances.[current, next]
traverse next left (acc + dist))
@theburningmonk
theburningmonk / Day24_pair_distances.fsx
Created December 25, 2016 03:32
Advent of Code (Day 24)
let numbers =
[|
for y = 0 to height-1 do
for x = 0 to width-1 do
match grid.[x, y] with
| Number n -> yield n, (x, y)
| _ -> ()
|]
|> Map.ofArray
@theburningmonk
theburningmonk / Day24_bfs.fsx
Created December 25, 2016 03:30
Advent of Code (Day 24)
open System.Collections.Generic
let findShortestPath start target =
let cache = new HashSet<int*int>([start])
[| (start, 0) |]
|> Seq.unfold (fun paths ->
paths
|> Seq.collect (fun ((x, y), moves) ->
[ x-1, y; x+1, y; x, y-1; x, y+1 ]
@theburningmonk
theburningmonk / Day24_parse.fsx
Created December 25, 2016 03:27
Advent of Code (Day 24)
open System.IO
let input = File.ReadAllLines(__SOURCE_DIRECTORY__ + "/Day24Input.txt")
type Tile = Wall | Space | Number of int
let width, height = input.[0].Length, input.Length
let grid = Array2D.init width height (fun x y ->
match input.[y].[x] with
| '#' -> Wall