Skip to content

Instantly share code, notes, and snippets.

@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) ->
nub([]) ->
[];
nub([X|Xs]) ->
[X | nub (lists:filter(fun (E) -> E =/= X end, Xs)].
@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.
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 / 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
@maruks
maruks / Plumber.ex
Created December 18, 2017 13:26
refactored
defmodule Plumber do
def input(file) do
file
|> 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
(ns prison.core
(:require [gniazdo.core :as ws]
[clojure.data.json :as json]))
(defn parse [str]
(json/read-str str :key-fn keyword))
(def msg-atom (atom nil))
(defn handle [msg]
(ns prison.core
(:require [gniazdo.core :as ws]
[clojure.data.json :as json]
[clojure.string :as str]))
(defn parse [str]
(json/read-str str :key-fn keyword))
(def score (atom {}))
(def last-round (atom nil))
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
@maruks
maruks / cloudy.clj
Created October 2, 2019 13:55
cloudy day
(defn queue []
(java.util.PriorityQueue.))
(defn peek [pqueue]
(.peek pqueue))
(defn poll [pqueue]
(.poll pqueue)
pqueue)