Skip to content

Instantly share code, notes, and snippets.

View akash-akya's full-sized avatar

Akash Hiremath akash-akya

View GitHub Profile
@akash-akya
akash-akya / aoc_2020_day_16.exs
Last active December 16, 2020 09:36
Advent of Code 2020: Day 16
defmodule Advent2020.Day16 do
def input, do: File.read!(Path.expand("day16.txt", :code.priv_dir(:advent_2020)))
defp split_lines(str), do: String.split(str, "\n", trim: true)
defp to_int(str), do: String.to_integer(str)
defp parse_fields(fields) do
Map.new(split_lines(fields), fn field ->
[_, name, a1, a2, b1, b2] = Regex.run(~r/([a-z ]+): (\d+)-(\d+) or (\d+)-(\d+)/, field)
@akash-akya
akash-akya / aoc_2020_day_14.exs
Last active December 14, 2020 17:40
Advent of Code 2020: Day 14
defmodule Advent2020.Day14 do
defp parse_addr(<<"] = ", value::binary>>, acc),
do: {:mem, String.to_integer(acc), String.to_integer(value)}
defp parse_addr(<<d::binary-size(1), rest::binary>>, acc), do: parse_addr(rest, acc <> d)
def parse("mask = " <> mask), do: {:mask, mask}
def parse(<<"mem[", d::binary-size(1), rest::binary>>), do: parse_addr(rest, d)
def input do
@akash-akya
akash-akya / aoc_2020_day_11.exs
Created December 12, 2020 14:24
Advent of Code 2020: Day 11
defmodule AOC2020.Day11 do
def parse(input) do
String.split(input, "\n", trim: true)
|> Enum.map(&String.codepoints(&1))
end
def show(room) do
Enum.map(room, &IO.puts(Enum.join(&1)))
room
end
@akash-akya
akash-akya / bench.md
Created May 21, 2020 05:40
Fork benachmark on mac
alias Exile.ProcessNif

Benchee.run(
  %{
    "exile" => fn ->
      {:ok, ctx} = ProcessNif.execute(['/bin/cat'], [], '', 0)
      ctx
    end,
    "port" => fn ->