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
import Enum, only: [all?: 2, at: 2, map: 2, join: 2, reverse: 1, zip: 2] | |
import Stream, only: [filter: 2, flat_map: 2, with_index: 2] | |
import String, only: [duplicate: 2, split_at: 2, to_integer: 1] | |
defmodule NQueens do | |
def safe?(queens, p) do | |
props = fn {f, r} -> [f, f+r, f-r] end | |
props_p = props.(p) | |
all?(queens, fn q -> all?(zip(props_p, props.(q)), fn {p, q} -> p != q end) end) | |
end |
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
def props(f, r) | |
[f, f + r, f - r] | |
end | |
def safe?(queens, f, r) | |
p_props = props(f, r) | |
queens.all? { |q| p_props.zip(props(*q)).all?{ |p| p[0] != p[1] } } | |
end | |
def solve(n, queens, rank, &block) |
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 Chess.PGN do | |
use Combine | |
@dquote ?" | |
@open_square ?[ | |
@close_square ?] | |
@backslash ?\ | |
def parse(str) do | |
Combine.parse(str, parser) |
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 Chess.PGN.Stream do | |
def split(stream, f), do: { Stream.take_while(stream, f), Stream.drop_while(stream, f) } | |
def process_header(line, hash) do | |
caps = Regex.named_captures(~r/\[(?<key>.+)\s+\"(?<value>.+)\"\s*\]/, line) | |
if caps == nil do | |
hash | |
else | |
Map.put(hash, caps["key"], caps["value"]) |
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
chars = Hash.new(0) | |
File.open("2019-annual/taxa.txt") do |f| | |
f.each_char.lazy.each do |char| | |
chars[char] += 1 if char.match(/^[[:alpha:]]$/) | |
end | |
end | |
puts chars.to_a.max{ |a, b| a[1] <=> b[1] } |
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 AlphaMaxPar do | |
def count_alpha(string) do | |
string | |
|> String.codepoints | |
|> Enum.filter(fn c -> c =~ ~r/[A-Za-z0-9]/ end) | |
|> Enum.reduce(Map.new, fn c,acc -> Map.update(acc, c, 1, &(&1+1)) end) | |
end | |
end | |
File.stream!("2019-annual/taxa.txt", [encoding: :utf8], 1_000_000) |
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
def schema do | |
schema(%{ | |
accel_x: spec(is_float()), | |
accel_y: spec(is_float()), | |
accel_z: spec(is_float()), | |
ambient_air_temp: spec(is_float()), | |
barometric_pressure: spec(is_float()), | |
battery_level: spec(is_float()), | |
data_provider_id: spec(Util.is_UUID()), | |
diagnostic_codes: coll_of(spec(is_binary())), |
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
[stepper_x] | |
step_pin: PB13 | |
dir_pin: !PB12 | |
enable_pin: !PB14 | |
microsteps: 16 | |
rotation_distance: 40 | |
endstop_pin: ^PC0 | |
position_endstop: 0 | |
position_min: 0 | |
position_max: 268 |
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
function pdf_variants(baseUrl) { | |
return { | |
rawUri: baseUrl + '_raw.pdf', | |
rawX1a: baseUrl + '_raw.pdfx', | |
rawNonX1a: baseUrl + '_raw_non_x1a.pdf', | |
proofUri: baseUrl + '.pdf', | |
proofX1a: baseUrl + '.pdfx', | |
proofNonX1a: baseUrl + '_non_x1a.pdf', | |
} | |
} |
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
@spec create(ES.index_t()) :: {:ok, pit_t()} | {:error, ES.response_t()} | |
def create(index) do | |
:post | |
|> HTTP.request(url(index), HTTP.no_payload(), HTTP.json_encoding()) | |
|> HTTP.on_200(& &1["id"]) | |
end |