Skip to content

Instantly share code, notes, and snippets.

@maruks
maruks / plumber.ex
Created December 13, 2017 00:21
Advent of Code, Day 12
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
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 =
@maruks
maruks / join.erl
Created February 28, 2017 00:32
functions over lists
-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.
nub([]) ->
[];
nub([X|Xs]) ->
[X | nub (lists:filter(fun (E) -> E =/= X end, Xs)].
@maruks
maruks / bits.erl
Created February 24, 2017 21:02
futurelearn erlang assignment #1
-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) ->
-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)),
@maruks
maruks / main.erl
Created December 7, 2016 11:45
GC benchmark ported to Erlang
-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)),
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
#lang racket
(define (mlist . elem)
(mcons (car elem)
(if (null? (cdr elem))
'()
(apply mlist (cdr elem)))))
;; has-cycle
@maruks
maruks / anaphoric.rkt
Last active May 23, 2016 17:35
anaphoric macro
(define-syntax (aif stx)
(syntax-case stx ()
[(_ expr then else)
(with-syntax ([it (datum->syntax stx 'it)] )
#'(let ((it expr))
(if it then else)))]))