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
defmodule Plumber do | |
def input do | |
"/Users/maris/Projects/Advent_of_code_2017/plumber/test/input" |> | |
File.stream!() |> | |
Enum.map(&(Regex.split(~r/\D+/, String.trim(&1)))) |> | |
Enum.reduce(%{}, fn([first | rest],acc) -> Map.put(acc,first,rest) end ) | |
end | |
def count([], acc, input) do | |
case Map.keys(input) do |
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
blur : Dict(Int,Int) Int -> ( Int, Int ) -> Int | |
blur cells ( x, y ) = | |
let | |
xs = | |
range (x - 1) (x + 1) | |
ys = | |
range (y - 1) (y + 1) | |
points = |
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(join). | |
-import(lists,[foldr/3,foldl/3,filter/2,split/2,flatmap/2,map/2,seq/2]). | |
-export([join/2,concat/1,member/2,qsort/1,msort/1,isort/1,perms/1]). | |
join_([X|Xs],Ys) -> | |
join_(Xs, [X | Ys]); | |
join_([], Ys) -> | |
Ys. |
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
nub([]) -> | |
[]; | |
nub([X|Xs]) -> | |
[X | nub (lists:filter(fun (E) -> E =/= X end, Xs)]. |
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(bits). | |
-export([bits/1, bits2/1, bits3/1]). | |
bits_tail_rec(<<B:1, Rest/bitstring>>, A) -> | |
bits_tail_rec(Rest,B + A); | |
bits_tail_rec(<<>>, A) -> | |
A. | |
bits(N) -> |
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). | |
-define(WINDOW_SIZE, 200000). | |
-define(MSG_COUNT, 1000000). | |
-define(MSG_SIZE, 1024). | |
-export([main/0]). | |
push_message(N, Tab) -> | |
Start = erlang:monotonic_time(), | |
Bin = list_to_binary(lists:duplicate(?MSG_SIZE, N rem 255)), |
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). | |
-define(WINDOW_SIZE, 200000). | |
-define(MSG_COUNT, 1000000). | |
-define(MSG_SIZE, 1024). | |
-export([main/0]). | |
push_message(N) -> | |
Start = erlang:monotonic_time(), | |
Bin = list_to_binary(lists:duplicate(?MSG_SIZE, N rem 255)), |
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
isSorted :: Tree -> Bool | |
isSorted t = isSortedTree t minBound maxBound | |
insert :: Tree -> Int -> Tree | |
insert Leaf e = Node e Leaf Leaf | |
insert n@(Node v l r) e | |
| v < e = Node v l (insert r e) | |
| v > e = Node v (insert l e) r | |
| otherwise = n |
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
#lang racket | |
(define (mlist . elem) | |
(mcons (car elem) | |
(if (null? (cdr elem)) | |
'() | |
(apply mlist (cdr elem))))) | |
;; has-cycle |
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
(define-syntax (aif stx) | |
(syntax-case stx () | |
[(_ expr then else) | |
(with-syntax ([it (datum->syntax stx 'it)] ) | |
#'(let ((it expr)) | |
(if it then else)))])) |