alias Exile.ProcessNif
Benchee.run(
%{
"exile" => fn ->
{:ok, ctx} = ProcessNif.execute(['/bin/cat'], [], '', 0)
ctx
end,
"port" => fn ->
This file contains hidden or 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 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) |
This file contains hidden or 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 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 |
This file contains hidden or 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 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 |