diff options
Diffstat (limited to 'aoc2023/build/dev/erlang')
796 files changed, 47980 insertions, 0 deletions
diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache Binary files differnew file mode 100644 index 0000000..f44ba7b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache_meta Binary files differnew file mode 100644 index 0000000..0af4a84 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.erl new file mode 100644 index 0000000..99741f8 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent.erl @@ -0,0 +1,55 @@ +-module(adglent). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([inspect/1, get_input/1, get_test_folder/1, start_arguments/0, get_part/0]). +-export_type([example/1, problem/0, charlist/0]). + +-type example(NYX) :: {example, binary(), NYX}. + +-type problem() :: first | second. + +-type charlist() :: any(). + +-spec inspect(any()) -> binary(). +inspect(Value) -> + Inspected_value = gleam@string:inspect(Value), + case begin + _pipe = Inspected_value, + gleam@string:starts_with(_pipe, <<"\""/utf8>>) + end of + true -> + _pipe@1 = Inspected_value, + _pipe@2 = gleam@string:drop_left(_pipe@1, 1), + gleam@string:drop_right(_pipe@2, 1); + + false -> + Inspected_value + end. + +-spec get_input(binary()) -> {ok, binary()} | {error, simplifile:file_error()}. +get_input(Day) -> + simplifile:read( + <<<<"src/day"/utf8, Day/binary>>/binary, "/input.txt"/utf8>> + ). + +-spec get_test_folder(binary()) -> binary(). +get_test_folder(Day) -> + <<"test/day"/utf8, Day/binary>>. + +-spec start_arguments() -> list(binary()). +start_arguments() -> + _pipe = init:get_plain_arguments(), + gleam@list:map(_pipe, fun unicode:characters_to_binary/1). + +-spec get_part() -> {ok, problem()} | {error, nil}. +get_part() -> + case start_arguments() of + [<<"1"/utf8>>] -> + {ok, first}; + + [<<"2"/utf8>>] -> + {ok, second}; + + _ -> + {error, nil} + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache Binary files differnew file mode 100644 index 0000000..be237c1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache_meta Binary files differnew file mode 100644 index 0000000..1637f81 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.erl new file mode 100644 index 0000000..68880ba --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@day.erl @@ -0,0 +1,278 @@ +-module(adglent@day). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec create_file_if_not_present(binary(), binary()) -> {ok, binary()} | + {error, binary()}. +create_file_if_not_present(Content, Path) -> + case simplifile:is_file(Path) of + true -> + {ok, <<Path/binary, " already exists - skipped"/utf8>>}; + + false -> + gleam@result:'try'( + begin + _pipe = simplifile:create_file(Path), + priv@errors:map_messages( + _pipe, + <<"Created "/utf8, Path/binary>>, + <<"Could not create "/utf8, Path/binary>> + ) + end, + fun(_) -> _pipe@1 = simplifile:write(Path, Content), + priv@errors:map_messages( + _pipe@1, + <<"Wrote "/utf8, Path/binary>>, + <<"Could not write to "/utf8, Path/binary>> + ) end + ) + end. + +-spec main() -> binary(). +main() -> + Day@1 = begin + _pipe = case adglent:start_arguments() of + [Day] -> + {ok, Day}; + + Args -> + {error, + <<"Expected day - found: "/utf8, + (gleam@string:join(Args, <<", "/utf8>>))/binary>>} + end, + _pipe@1 = priv@errors:map_error( + _pipe, + <<"Error when parsing command args"/utf8>> + ), + _pipe@2 = priv@errors:print_error(_pipe@1), + priv@errors:assert_ok(_pipe@2) + end, + Aoc_toml = begin + _pipe@3 = simplifile:read(<<"aoc.toml"/utf8>>), + _pipe@4 = priv@errors:map_error( + _pipe@3, + <<"Could not read aoc.toml"/utf8>> + ), + _pipe@5 = priv@errors:print_error(_pipe@4), + priv@errors:assert_ok(_pipe@5) + end, + Aoc_toml_version = priv@toml:get_int(Aoc_toml, [<<"version"/utf8>>]), + Year = begin + _pipe@6 = priv@toml:get_string(Aoc_toml, [<<"year"/utf8>>]), + _pipe@7 = priv@errors:map_error( + _pipe@6, + <<"Could not read \"year\" from aoc.toml"/utf8>> + ), + _pipe@8 = priv@errors:print_error(_pipe@7), + priv@errors:assert_ok(_pipe@8) + end, + Session = begin + _pipe@9 = priv@toml:get_string(Aoc_toml, [<<"session"/utf8>>]), + _pipe@10 = priv@errors:map_error( + _pipe@9, + <<"Could not read \"session\" from aoc.toml"/utf8>> + ), + _pipe@11 = priv@errors:print_error(_pipe@10), + priv@errors:assert_ok(_pipe@11) + end, + Showtime = case Aoc_toml_version of + {ok, 2} -> + _pipe@12 = priv@toml:get_bool(Aoc_toml, [<<"showtime"/utf8>>]), + _pipe@13 = priv@errors:map_error( + _pipe@12, + <<"Could not read \"showtime\" from aoc.toml"/utf8>> + ), + _pipe@14 = priv@errors:print_error(_pipe@13), + priv@errors:assert_ok(_pipe@14); + + _ -> + _pipe@15 = priv@toml:get_string(Aoc_toml, [<<"showtime"/utf8>>]), + _pipe@16 = gleam@result:map( + _pipe@15, + fun(Bool_string) -> case Bool_string of + <<"True"/utf8>> -> + true; + + _ -> + false + end end + ), + _pipe@17 = priv@errors:map_error( + _pipe@16, + <<"Could not read \"showtime\" from aoc.toml"/utf8>> + ), + _pipe@18 = priv@errors:print_error(_pipe@17), + priv@errors:assert_ok(_pipe@18) + end, + Test_folder = adglent:get_test_folder(Day@1), + Test_file = <<<<<<Test_folder/binary, "/day"/utf8>>/binary, Day@1/binary>>/binary, + "_test.gleam"/utf8>>, + _pipe@19 = simplifile:create_directory_all(Test_folder), + _pipe@20 = priv@errors:map_error( + _pipe@19, + <<<<"Could not create folder \""/utf8, Test_folder/binary>>/binary, + "\""/utf8>> + ), + _pipe@21 = priv@errors:print_error(_pipe@20), + priv@errors:assert_ok(_pipe@21), + Testfile_template = case Showtime of + true -> + <<" +import gleam/list +import showtime/tests/should +import adglent.{type Example, Example} +import day{{ day }}/solve + +type Problem1AnswerType = + String + +type Problem2AnswerType = + String + +/// Add examples for part 1 here: +/// ```gleam +///const part1_examples: List(Example(Problem1AnswerType)) = [Example(\"some input\", \"\")] +/// ``` +const part1_examples: List(Example(Problem1AnswerType)) = [] + +/// Add examples for part 2 here: +/// ```gleam +///const part2_examples: List(Example(Problem2AnswerType)) = [Example(\"some input\", \"\")] +/// ``` +const part2_examples: List(Example(Problem2AnswerType)) = [] + +pub fn part1_test() { + part1_examples + |> should.not_equal([]) + use example <- list.map(part1_examples) + solve.part1(example.input) + |> should.equal(example.answer) +} + +pub fn part2_test() { + part2_examples + |> should.not_equal([]) + use example <- list.map(part2_examples) + solve.part2(example.input) + |> should.equal(example.answer) +} + +"/utf8>>; + + false -> + <<" +import gleam/list +import gleeunit/should +import adglent.{type Example, Example} +import day{{ day }}/solve + +type Problem1AnswerType = + String + +type Problem2AnswerType = + String + +/// Add examples for part 1 here: +/// ```gleam +///const part1_examples: List(Example(Problem1AnswerType)) = [Example(\"some input\", \"\")] +/// ``` +const part1_examples: List(Example(Problem1AnswerType)) = [] + +/// Add examples for part 2 here: +/// ```gleam +///const part2_examples: List(Example(Problem2AnswerType)) = [Example(\"some input\", \"\")] +/// ``` +const part2_examples: List(Example(Problem2AnswerType)) = [] + +pub fn part1_test() { + part1_examples + |> should.not_equal([]) + use example <- list.map(part1_examples) + solve.part1(example.input) + |> should.equal(example.answer) +} + +pub fn part2_test() { + part2_examples + |> should.not_equal([]) + use example <- list.map(part2_examples) + solve.part2(example.input) + |> should.equal(example.answer) +} + +"/utf8>> + end, + _pipe@22 = priv@template:render( + Testfile_template, + [{<<"day"/utf8>>, Day@1}] + ), + _pipe@23 = create_file_if_not_present(_pipe@22, Test_file), + _pipe@24 = priv@errors:print_result(_pipe@23), + priv@errors:assert_ok(_pipe@24), + Solutions_folder = <<"src/day"/utf8, Day@1/binary>>, + Solution_file = <<Solutions_folder/binary, "/solve.gleam"/utf8>>, + _pipe@25 = simplifile:create_directory_all(Solutions_folder), + _pipe@26 = priv@errors:map_error( + _pipe@25, + <<<<"Could not create folder \""/utf8, Solutions_folder/binary>>/binary, + "\""/utf8>> + ), + _pipe@27 = priv@errors:print_error(_pipe@26), + priv@errors:assert_ok(_pipe@27), + _pipe@28 = priv@template:render( + <<" +import adglent.{First, Second} +import gleam/io + +pub fn part1(input: String) { + todo as \"Implement solution to part 1\" +} + +pub fn part2(input: String) { + todo as \"Implement solution to part 2\" +} + +pub fn main() { + let assert Ok(part) = adglent.get_part() + let assert Ok(input) = adglent.get_input(\"{{ day }}\") + case part { + First -> + part1(input) + |> adglent.inspect + |> io.println + Second -> + part2(input) + |> adglent.inspect + |> io.println + } +} +"/utf8>>, + [{<<"day"/utf8>>, Day@1}] + ), + _pipe@29 = create_file_if_not_present(_pipe@28, Solution_file), + _pipe@30 = priv@errors:print_result(_pipe@29), + priv@errors:assert_ok(_pipe@30), + _pipe@31 = create_file_if_not_present( + <<"input.txt"/utf8>>, + <<Solutions_folder/binary, "/.gitignore"/utf8>> + ), + _pipe@32 = priv@errors:print_result(_pipe@31), + priv@errors:assert_ok(_pipe@32), + Input = begin + _pipe@33 = priv@aoc_client:get_input(Year, Day@1, Session), + _pipe@34 = priv@errors:map_error( + _pipe@33, + <<"Error when fetching input"/utf8>> + ), + _pipe@35 = priv@errors:print_error(_pipe@34), + priv@errors:assert_ok(_pipe@35) + end, + _pipe@36 = Input, + _pipe@37 = gleam@string:trim(_pipe@36), + _pipe@38 = create_file_if_not_present( + _pipe@37, + <<Solutions_folder/binary, "/input.txt"/utf8>> + ), + _pipe@39 = priv@errors:print_result(_pipe@38), + priv@errors:assert_ok(_pipe@39). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache Binary files differnew file mode 100644 index 0000000..798878b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache_meta Binary files differnew file mode 100644 index 0000000..2751b68 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.erl new file mode 100644 index 0000000..50d1242 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent@init.erl @@ -0,0 +1,142 @@ +-module(adglent@init). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec main() -> {ok, binary()} | {error, binary()}. +main() -> + Year = priv@prompt:value(<<"Year"/utf8>>, <<"2023"/utf8>>, false), + Session = priv@prompt:value(<<"Session Cookie"/utf8>>, <<""/utf8>>, false), + Use_showtime = priv@prompt:confirm(<<"Use showtime"/utf8>>, false), + Aoc_toml_file = <<"aoc.toml"/utf8>>, + Overwrite = case simplifile:create_file(Aoc_toml_file) of + {ok, _} -> + true; + + {error, eexist} -> + priv@prompt:confirm(<<"aoc.toml exits - overwrite"/utf8>>, false); + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"Could not create aoc.toml"/utf8>>, + module => <<"adglent/init"/utf8>>, + function => <<"main"/utf8>>, + line => 29}) + end, + _pipe@3 = case Overwrite of + true -> + _pipe@1 = priv@template:render( + <<" +version = {{ version }} +year = \"{{ year }}\" +session = \"{{ session }}\" +showtime = {{ showtime }} +"/utf8>>, + [{<<"version"/utf8>>, <<"2"/utf8>>}, + {<<"year"/utf8>>, Year}, + {<<"session"/utf8>>, Session}, + {<<"showtime"/utf8>>, + begin + _pipe = gleam@bool:to_string(Use_showtime), + gleam@string:lowercase(_pipe) + end}] + ), + _pipe@2 = simplifile:write(Aoc_toml_file, _pipe@1), + priv@errors:map_messages( + _pipe@2, + <<"aoc.toml - written"/utf8>>, + <<"Error when writing aoc.toml"/utf8>> + ); + + false -> + {ok, <<"aoc.toml - skipped"/utf8>>} + end, + priv@errors:print_result(_pipe@3), + Gleam_toml = begin + _pipe@4 = simplifile:read(<<"gleam.toml"/utf8>>), + _pipe@5 = priv@errors:map_error( + _pipe@4, + <<"Could not read gleam.toml"/utf8>> + ), + _pipe@6 = priv@errors:print_error(_pipe@5), + priv@errors:assert_ok(_pipe@6) + end, + Name = begin + _pipe@7 = priv@toml:get_string(Gleam_toml, [<<"name"/utf8>>]), + _pipe@8 = priv@errors:map_error( + _pipe@7, + <<"Could not read \"name\" from gleam.toml"/utf8>> + ), + _pipe@9 = priv@errors:print_error(_pipe@8), + priv@errors:assert_ok(_pipe@9) + end, + Test_main_file = <<<<"test/"/utf8, Name/binary>>/binary, + "_test.gleam"/utf8>>, + _pipe@12 = case Use_showtime of + true -> + _pipe@10 = priv@template:render( + <<" +import showtime + +pub fn main() { + showtime.main() +} +"/utf8>>, + [] + ), + _pipe@11 = simplifile:write(Test_main_file, _pipe@10), + priv@errors:map_messages( + _pipe@11, + <<"Wrote "/utf8, Test_main_file/binary>>, + <<"Could not write to "/utf8, Test_main_file/binary>> + ); + + false -> + {ok, <<"Using existing (gleeunit) "/utf8, Test_main_file/binary>>} + end, + _pipe@13 = priv@errors:print_result(_pipe@12), + priv@errors:assert_ok(_pipe@13), + _pipe@17 = case simplifile:is_file(<<".gitignore"/utf8>>) of + true -> + gleam@result:'try'( + begin + _pipe@14 = simplifile:read(<<".gitignore"/utf8>>), + gleam@result:map_error( + _pipe@14, + fun(Err) -> + <<"Could not read .gitignore: "/utf8, + (gleam@string:inspect(Err))/binary>> + end + ) + end, + fun(Gitignore) -> + Aoc_toml_ignored = begin + _pipe@15 = gleam@string:split(Gitignore, <<"\n"/utf8>>), + gleam@list:find( + _pipe@15, + fun(Line) -> Line =:= <<"aoc.toml"/utf8>> end + ) + end, + case Aoc_toml_ignored of + {error, _} -> + _pipe@16 = simplifile:append( + <<".gitignore"/utf8>>, + <<"\naoc.toml"/utf8>> + ), + priv@errors:map_messages( + _pipe@16, + <<".gitignore written"/utf8>>, + <<"Error when writing .gitignore"/utf8>> + ); + + {ok, _} -> + {ok, + <<".gitignore - skipped (already configured)"/utf8>>} + end + end + ); + + false -> + {error, <<"Could not find .gitignore"/utf8>>} + end, + priv@errors:print_result(_pipe@17). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent_ffi.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent_ffi.erl new file mode 100644 index 0000000..a6a92e6 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/adglent_ffi.erl @@ -0,0 +1,12 @@ +-module(adglent_ffi). + +-export([get_line/1]). + +-spec get_line(io:prompt()) -> {ok, unicode:unicode_binary()} | {error, eof | no_data}. +get_line(Prompt) -> + case io:get_line(Prompt) of + eof -> {error, eof}; + {error, _} -> {error, no_data}; + Data when is_binary(Data) -> {ok, Data}; + Data when is_list(Data) -> {ok, unicode:characters_to_binary(Data)} + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache Binary files differnew file mode 100644 index 0000000..e87188f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache_meta Binary files differnew file mode 100644 index 0000000..b6c1617 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.erl new file mode 100644 index 0000000..b30266b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@aoc_client.erl @@ -0,0 +1,61 @@ +-module(priv@aoc_client). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([get_input/3]). + +-spec get_input(binary(), binary(), binary()) -> {ok, binary()} | + {error, binary()}. +get_input(Year, Day, Session) -> + Url = <<<<<<<<"https://adventofcode.com/"/utf8, Year/binary>>/binary, + "/day/"/utf8>>/binary, + Day/binary>>/binary, + "/input"/utf8>>, + gleam@result:'try'( + begin + _pipe = gleam@http@request:to(Url), + gleam@result:map_error( + _pipe, + fun(Error) -> + <<<<<<"Could not create request for \""/utf8, Url/binary>>/binary, + "\": "/utf8>>/binary, + (gleam@string:inspect(Error))/binary>> + end + ) + end, + fun(Request) -> + gleam@result:'try'( + begin + _pipe@1 = Request, + _pipe@2 = gleam@http@request:prepend_header( + _pipe@1, + <<"Accept"/utf8>>, + <<"application/json"/utf8>> + ), + _pipe@3 = gleam@http@request:prepend_header( + _pipe@2, + <<"Cookie"/utf8>>, + <<<<"session="/utf8, Session/binary>>/binary, ";"/utf8>> + ), + _pipe@4 = gleam@httpc:send(_pipe@3), + gleam@result:map_error( + _pipe@4, + fun(Error@1) -> + <<<<<<"Error when requesting \""/utf8, Url/binary>>/binary, + "\": "/utf8>>/binary, + (gleam@string:inspect(Error@1))/binary>> + end + ) + end, + fun(Response) -> case erlang:element(2, Response) of + Status when (Status >= 200) andalso (Status < 300) -> + {ok, erlang:element(4, Response)}; + + Status@1 -> + {error, + <<<<(gleam@int:to_string(Status@1))/binary, + " - "/utf8>>/binary, + (erlang:element(4, Response))/binary>>} + end end + ) + end + ). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache Binary files differnew file mode 100644 index 0000000..3ea27a4 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache_meta Binary files differnew file mode 100644 index 0000000..498e302 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.erl new file mode 100644 index 0000000..bd45efa --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@errors.erl @@ -0,0 +1,74 @@ +-module(priv@errors). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([map_messages/3, map_error/2, print_result/1, print_error/1, assert_ok/1]). + +-spec map_messages({ok, any()} | {error, any()}, binary(), binary()) -> {ok, + binary()} | + {error, binary()}. +map_messages(Result, Success_message, Error_message) -> + _pipe = Result, + _pipe@1 = gleam@result:map_error( + _pipe, + fun(Error) -> + <<<<<<"Error - "/utf8, Error_message/binary>>/binary, ": "/utf8>>/binary, + (gleam@string:inspect(Error))/binary>> + end + ), + gleam@result:replace(_pipe@1, Success_message). + +-spec map_error({ok, PBO} | {error, any()}, binary()) -> {ok, PBO} | + {error, binary()}. +map_error(Result, Error_message) -> + _pipe = Result, + gleam@result:map_error( + _pipe, + fun(Error) -> + <<<<Error_message/binary, ": "/utf8>>/binary, + (gleam@string:inspect(Error))/binary>> + end + ). + +-spec print_result({ok, binary()} | {error, binary()}) -> {ok, binary()} | + {error, binary()}. +print_result(Result) -> + _pipe = Result, + _pipe@1 = gleam@result:unwrap_both(_pipe), + gleam@io:println(_pipe@1), + Result. + +-spec print_error({ok, PBX} | {error, binary()}) -> {ok, PBX} | + {error, binary()}. +print_error(Result) -> + _pipe = Result, + gleam@result:map_error( + _pipe, + fun(Err) -> + gleam@io:println(Err), + Err + end + ). + +-spec assert_ok({ok, PCB} | {error, binary()}) -> PCB. +assert_ok(Result) -> + _assert_subject = begin + _pipe = Result, + gleam@result:map_error( + _pipe, + fun(Err) -> + erlang:halt(1), + Err + end + ) + end, + {ok, Value} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"priv/errors"/utf8>>, + function => <<"assert_ok"/utf8>>, + line => 43}) + end, + Value. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache Binary files differnew file mode 100644 index 0000000..6d858d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache_meta Binary files differnew file mode 100644 index 0000000..b010daf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.erl new file mode 100644 index 0000000..9be1713 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@prompt.erl @@ -0,0 +1,53 @@ +-module(priv@prompt). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([get_line/1, confirm/2, value/3]). +-export_type([get_line_error/0]). + +-type get_line_error() :: eof | no_data. + +-spec get_line(binary()) -> {ok, binary()} | {error, get_line_error()}. +get_line(Prompt) -> + adglent_ffi:get_line(Prompt). + +-spec confirm(binary(), boolean()) -> boolean(). +confirm(Message, Auto_accept) -> + Auto_accept orelse case begin + _pipe = adglent_ffi:get_line(<<Message/binary, "? (Y/N): "/utf8>>), + _pipe@1 = gleam@result:unwrap(_pipe, <<"n"/utf8>>), + gleam@string:trim(_pipe@1) + end of + <<"Y"/utf8>> -> + true; + + <<"y"/utf8>> -> + true; + + _ -> + false + end. + +-spec get_value_of_default(binary(), binary(), boolean()) -> binary(). +get_value_of_default(Message, Default, Auto_accept) -> + case Auto_accept of + true -> + Default; + + false -> + _pipe = adglent_ffi:get_line( + <<<<<<Message/binary, "? ("/utf8>>/binary, Default/binary>>/binary, + "): "/utf8>> + ), + _pipe@1 = gleam@result:unwrap(_pipe, <<""/utf8>>), + gleam@string:trim(_pipe@1) + end. + +-spec value(binary(), binary(), boolean()) -> binary(). +value(Message, Default, Auto_accept) -> + case get_value_of_default(Message, Default, Auto_accept) of + <<""/utf8>> -> + Default; + + Value -> + Value + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache Binary files differnew file mode 100644 index 0000000..1df1c9d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache_meta Binary files differnew file mode 100644 index 0000000..5e1f919 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.erl new file mode 100644 index 0000000..dee331b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@template.erl @@ -0,0 +1,25 @@ +-module(priv@template). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([render/2]). + +-spec render(binary(), list({binary(), binary()})) -> binary(). +render(Template, Substitutions) -> + <<(begin + _pipe = Substitutions, + _pipe@2 = gleam@list:fold( + _pipe, + Template, + fun(Template@1, Substitution) -> + {Name, Value} = Substitution, + _pipe@1 = Template@1, + gleam@string:replace( + _pipe@1, + <<<<"{{ "/utf8, Name/binary>>/binary, " }}"/utf8>>, + Value + ) + end + ), + gleam@string:trim(_pipe@2) + end)/binary, + "\n"/utf8>>. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache Binary files differnew file mode 100644 index 0000000..3f12af2 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache_meta Binary files differnew file mode 100644 index 0000000..3397840 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.erl new file mode 100644 index 0000000..7e36387 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@solution.erl @@ -0,0 +1 @@ +-module(priv@templates@solution). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache Binary files differnew file mode 100644 index 0000000..3ca29d0 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache_meta Binary files differnew file mode 100644 index 0000000..17c867f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.erl new file mode 100644 index 0000000..ca6b127 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@test_main.erl @@ -0,0 +1 @@ +-module(priv@templates@test_main). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache Binary files differnew file mode 100644 index 0000000..22f49a5 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache_meta Binary files differnew file mode 100644 index 0000000..c996833 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.erl new file mode 100644 index 0000000..2f5a41e --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_gleeunit.erl @@ -0,0 +1 @@ +-module(priv@templates@testfile_gleeunit). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache Binary files differnew file mode 100644 index 0000000..5dc9daa --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache_meta Binary files differnew file mode 100644 index 0000000..120c91f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.erl new file mode 100644 index 0000000..bbbc8b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@templates@testfile_showtime.erl @@ -0,0 +1 @@ +-module(priv@templates@testfile_showtime). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache Binary files differnew file mode 100644 index 0000000..0e5b549 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache_meta Binary files differnew file mode 100644 index 0000000..a423083 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.erl new file mode 100644 index 0000000..c53ca23 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/priv@toml.erl @@ -0,0 +1,83 @@ +-module(priv@toml). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([get_string/2, get_bool/2, get_int/2]). +-export_type([tom_error/0]). + +-type tom_error() :: {tom_parse_error, tom:parse_error()} | + {tom_get_error, tom:get_error()}. + +-spec get_string(binary(), list(binary())) -> {ok, binary()} | + {error, tom_error()}. +get_string(Toml_content, Key_path) -> + gleam@result:'try'( + begin + _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>), + gleam@result:map_error( + _pipe, + fun(Field@0) -> {tom_parse_error, Field@0} end + ) + end, + fun(Toml) -> + gleam@result:'try'( + begin + _pipe@1 = tom:get_string(Toml, Key_path), + gleam@result:map_error( + _pipe@1, + fun(Field@0) -> {tom_get_error, Field@0} end + ) + end, + fun(Value) -> {ok, Value} end + ) + end + ). + +-spec get_bool(binary(), list(binary())) -> {ok, boolean()} | + {error, tom_error()}. +get_bool(Toml_content, Key_path) -> + gleam@result:'try'( + begin + _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>), + gleam@result:map_error( + _pipe, + fun(Field@0) -> {tom_parse_error, Field@0} end + ) + end, + fun(Toml) -> + gleam@result:'try'( + begin + _pipe@1 = tom:get_bool(Toml, Key_path), + gleam@result:map_error( + _pipe@1, + fun(Field@0) -> {tom_get_error, Field@0} end + ) + end, + fun(Value) -> {ok, Value} end + ) + end + ). + +-spec get_int(binary(), list(binary())) -> {ok, integer()} | + {error, tom_error()}. +get_int(Toml_content, Key_path) -> + gleam@result:'try'( + begin + _pipe = tom:parse(<<Toml_content/binary, "\n"/utf8>>), + gleam@result:map_error( + _pipe, + fun(Field@0) -> {tom_parse_error, Field@0} end + ) + end, + fun(Toml) -> + gleam@result:'try'( + begin + _pipe@1 = tom:get_int(Toml, Key_path), + gleam@result:map_error( + _pipe@1, + fun(Field@0) -> {tom_get_error, Field@0} end + ) + end, + fun(Value) -> {ok, Value} end + ) + end + ). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache Binary files differnew file mode 100644 index 0000000..a93f0d6 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache_meta Binary files differnew file mode 100644 index 0000000..96a5705 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.erl new file mode 100644 index 0000000..1107421 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime.erl @@ -0,0 +1,155 @@ +-module(showtime). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec mk_runner( + fun((gleam@option:option(list(binary())), list(binary()), showtime@internal@common@cli:capture()) -> PLX), + glint:command_input() +) -> PLX. +mk_runner(Func, Command) -> + _assert_subject = begin + _pipe = erlang:element(3, Command), + _pipe@1 = glint@flag:get_strings(_pipe, <<"modules"/utf8>>), + gleam@result:map(_pipe@1, fun(Modules) -> case Modules of + [] -> + none; + + Modules@1 -> + {some, Modules@1} + end end) + end, + {ok, Module_list} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime"/utf8>>, + function => <<"mk_runner"/utf8>>, + line => 91}) + end, + _assert_subject@1 = begin + _pipe@2 = erlang:element(3, Command), + glint@flag:get_strings(_pipe@2, <<"ignore"/utf8>>) + end, + {ok, Ignore_tags} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"showtime"/utf8>>, + function => <<"mk_runner"/utf8>>, + line => 100}) + end, + _assert_subject@2 = begin + _pipe@3 = erlang:element(3, Command), + _pipe@4 = glint@flag:get_string(_pipe@3, <<"capture"/utf8>>), + _pipe@5 = gleam@result:map( + _pipe@4, + fun(Arg) -> gleam@string:lowercase(Arg) end + ), + gleam@result:map(_pipe@5, fun(Arg@1) -> case Arg@1 of + <<"no"/utf8>> -> + no; + + <<"yes"/utf8>> -> + yes; + + <<"mixed"/utf8>> -> + mixed + end end) + end, + {ok, Capture_output} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"showtime"/utf8>>, + function => <<"mk_runner"/utf8>>, + line => 104}) + end, + Func(Module_list, Ignore_tags, Capture_output). + +-spec start_with_args( + list(binary()), + fun((gleam@option:option(list(binary())), list(binary()), showtime@internal@common@cli:capture()) -> any()) +) -> nil. +start_with_args(Args, Func) -> + Modules_flag = begin + _pipe = glint@flag:string_list(), + _pipe@1 = glint@flag:default(_pipe, []), + glint@flag:description( + _pipe@1, + <<"Run only tests in the modules in this list"/utf8>> + ) + end, + Ignore_flag = begin + _pipe@2 = glint@flag:string_list(), + _pipe@3 = glint@flag:default(_pipe@2, []), + glint@flag:description( + _pipe@3, + <<"Ignore tests that are have tags matching a tag in this list"/utf8>> + ) + end, + Capture_flag = begin + _pipe@4 = glint@flag:string(), + _pipe@5 = glint@flag:default(_pipe@4, <<"no"/utf8>>), + _pipe@6 = glint@flag:constraint( + _pipe@5, + glint@flag@constraint:one_of( + [<<"yes"/utf8>>, <<"no"/utf8>>, <<"mixed"/utf8>>] + ) + ), + glint@flag:description( + _pipe@6, + <<"Capture output: no (default) - output when tests are run, yes - output is captured and shown in report, mixed - output when run and in report"/utf8>> + ) + end, + _pipe@7 = glint:new(), + _pipe@12 = glint:add( + _pipe@7, + [], + begin + _pipe@8 = glint:command( + fun(_capture) -> mk_runner(Func, _capture) end + ), + _pipe@9 = glint:flag(_pipe@8, <<"modules"/utf8>>, Modules_flag), + _pipe@10 = glint:flag(_pipe@9, <<"ignore"/utf8>>, Ignore_flag), + _pipe@11 = glint:flag(_pipe@10, <<"capture"/utf8>>, Capture_flag), + glint:description(_pipe@11, <<"Runs test"/utf8>>) + end + ), + _pipe@13 = glint:with_pretty_help(_pipe@12, glint:default_pretty_help()), + glint:run(_pipe@13, Args). + +-spec main() -> nil. +main() -> + start_with_args( + gleam@erlang:start_arguments(), + fun(Module_list, Ignore_tags, Capture) -> + Test_event_handler = showtime@internal@erlang@event_handler:start(), + Test_module_handler = showtime@internal@erlang@module_handler:start( + Test_event_handler, + fun showtime@internal@erlang@discover:collect_test_functions/1, + fun showtime@internal@erlang@runner:run_test_suite/4, + Ignore_tags, + Capture + ), + Test_event_handler(start_test_run), + Modules = showtime@internal@erlang@discover:collect_modules( + Test_module_handler, + Module_list + ), + Test_event_handler( + {end_test_run, + begin + _pipe = Modules, + gleam@list:length(_pipe) + end} + ), + nil + end + ). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache Binary files differnew file mode 100644 index 0000000..2fd016f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache_meta Binary files differnew file mode 100644 index 0000000..4c3ebd3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.erl new file mode 100644 index 0000000..401b409 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@cli.erl @@ -0,0 +1,8 @@ +-module(showtime@internal@common@cli). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([capture/0]). + +-type capture() :: yes | no | mixed. + + diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache Binary files differnew file mode 100644 index 0000000..af5456d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache_meta Binary files differnew file mode 100644 index 0000000..cea0c4b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.erl new file mode 100644 index 0000000..9b9134c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@common_event_handler.erl @@ -0,0 +1,131 @@ +-module(showtime@internal@common@common_event_handler). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([handle_event/3]). +-export_type([test_state/0, handler_state/0]). + +-type test_state() :: not_started | running | {finished, integer()}. + +-type handler_state() :: {handler_state, + test_state(), + integer(), + gleam@dict:dict(binary(), gleam@dict:dict(binary(), showtime@internal@common@test_suite:test_run()))}. + +-spec handle_event( + showtime@internal@common@test_suite:test_event(), + fun(() -> integer()), + handler_state() +) -> handler_state(). +handle_event(Msg, System_time, State) -> + Test_state = erlang:element(2, State), + Num_done = erlang:element(3, State), + Events = erlang:element(4, State), + {Updated_test_state, Updated_num_done, Updated_events} = case Msg of + start_test_run -> + {running, Num_done, Events}; + + {start_test_suite, Module} -> + Maybe_module_events = gleam@map:get( + Events, + erlang:element(2, Module) + ), + New_events = case Maybe_module_events of + {ok, _} -> + Events; + + {error, _} -> + _pipe = Events, + gleam@map:insert( + _pipe, + erlang:element(2, Module), + gleam@map:new() + ) + end, + {Test_state, Num_done, New_events}; + + {start_test, Module@1, Test} -> + Current_time = System_time(), + Maybe_module_events@1 = gleam@map:get( + Events, + erlang:element(2, Module@1) + ), + New_events@1 = case Maybe_module_events@1 of + {ok, Module_events} -> + Maybe_test_event = gleam@map:get( + Module_events, + erlang:element(2, Test) + ), + case Maybe_test_event of + {error, _} -> + _pipe@1 = Events, + gleam@map:insert( + _pipe@1, + erlang:element(2, Module@1), + begin + _pipe@2 = Module_events, + gleam@map:insert( + _pipe@2, + erlang:element(2, Test), + {ongoing_test_run, Test, Current_time} + ) + end + ); + + {ok, _} -> + Events + end; + + {error, _} -> + Events + end, + {Test_state, Num_done, New_events@1}; + + {end_test, Module@2, Test@1, Result} -> + Current_time@1 = System_time(), + Maybe_module_events@2 = gleam@map:get( + Events, + erlang:element(2, Module@2) + ), + New_events@2 = case Maybe_module_events@2 of + {ok, Module_events@1} -> + Maybe_test_run = begin + _pipe@3 = Module_events@1, + gleam@map:get(_pipe@3, erlang:element(2, Test@1)) + end, + Updated_module_events = case Maybe_test_run of + {ok, {ongoing_test_run, Test_function, Started_at}} -> + _pipe@4 = Module_events@1, + gleam@map:insert( + _pipe@4, + erlang:element(2, Test@1), + {completed_test_run, + Test_function, + Current_time@1 - Started_at, + Result} + ); + + {error, _} -> + Module_events@1 + end, + _pipe@5 = Events, + gleam@map:insert( + _pipe@5, + erlang:element(2, Module@2), + Updated_module_events + ); + + {error, _} -> + Events + end, + {Test_state, Num_done, New_events@2}; + + {end_test_suite, _} -> + {Test_state, Num_done + 1, Events}; + + {end_test_run, Num_modules} -> + {{finished, Num_modules}, Num_done, Events}; + + _ -> + {running, Num_done, Events} + end, + {handler_state, Updated_test_state, Updated_num_done, Updated_events}. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache Binary files differnew file mode 100644 index 0000000..d460b8c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache_meta Binary files differnew file mode 100644 index 0000000..ae0cd95 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.erl new file mode 100644 index 0000000..52b69ef --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_result.erl @@ -0,0 +1,54 @@ +-module(showtime@internal@common@test_result). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([ignore_reason/0, test_return/0, exception/0, reason/0, reason_detail/0, gleam_error_detail/0, class/0, trace_list/0, trace/0, extra_info/0, arity_/0]). + +-type ignore_reason() :: ignore. + +-type test_return() :: {test_function_return, + gleam@dynamic:dynamic_(), + list(binary())} | + {ignored, ignore_reason()}. + +-type exception() :: {erlang_exception, + class(), + reason(), + trace_list(), + list(binary())}. + +-type reason() :: {assert_equal, list(reason_detail())} | + {assert_not_equal, list(reason_detail())} | + {assert_match, list(reason_detail())} | + {gleam_error, gleam_error_detail()} | + {gleam_assert, gleam@dynamic:dynamic_(), integer()} | + {generic_exception, gleam@dynamic:dynamic_()}. + +-type reason_detail() :: {module, binary()} | + {reason_line, integer()} | + {expression, binary()} | + {expected, gleam@dynamic:dynamic_()} | + {value, gleam@dynamic:dynamic_()} | + {pattern, binary()}. + +-type gleam_error_detail() :: {let_assert, + binary(), + binary(), + integer(), + binary(), + gleam@dynamic:dynamic_()}. + +-type class() :: erlang_error | exit | throw. + +-type trace_list() :: {trace_list, list(trace())}. + +-type trace() :: {trace, binary(), arity_(), list(extra_info())} | + {trace_module, binary(), binary(), arity_(), list(extra_info())}. + +-type extra_info() :: {error_info, + gleam@dict:dict(gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_())} | + {file, binary()} | + {line, integer()}. + +-type arity_() :: {num, integer()} | {arg_list, list(gleam@dynamic:dynamic_())}. + + diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache Binary files differnew file mode 100644 index 0000000..054b4d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache_meta Binary files differnew file mode 100644 index 0000000..b2139f9 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.erl new file mode 100644 index 0000000..ed41d72 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@common@test_suite.erl @@ -0,0 +1,30 @@ +-module(showtime@internal@common@test_suite). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([test_run/0, test_module/0, test_function/0, test_suite/0, test_event/0]). + +-type test_run() :: {ongoing_test_run, test_function(), integer()} | + {completed_test_run, + test_function(), + integer(), + {ok, showtime@internal@common@test_result:test_return()} | + {error, showtime@internal@common@test_result:exception()}}. + +-type test_module() :: {test_module, binary(), gleam@option:option(binary())}. + +-type test_function() :: {test_function, binary()}. + +-type test_suite() :: {test_suite, test_module(), list(test_function())}. + +-type test_event() :: start_test_run | + {start_test_suite, test_module()} | + {start_test, test_module(), test_function()} | + {end_test, + test_module(), + test_function(), + {ok, showtime@internal@common@test_result:test_return()} | + {error, showtime@internal@common@test_result:exception()}} | + {end_test_suite, test_module()} | + {end_test_run, integer()}. + + diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache Binary files differnew file mode 100644 index 0000000..5a8fdad --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache_meta Binary files differnew file mode 100644 index 0000000..236dd39 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.erl new file mode 100644 index 0000000..025c467 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@discover.erl @@ -0,0 +1,230 @@ +-module(showtime@internal@erlang@discover). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([collect_modules/2, collect_test_functions/1]). + +-spec get_module_prefix(binary()) -> binary(). +get_module_prefix(Path) -> + Path_without_test = begin + _pipe = Path, + gleam@string:replace(_pipe, <<"./test"/utf8>>, <<""/utf8>>) + end, + Path_without_leading_slash = case gleam@string:starts_with( + Path_without_test, + <<"/"/utf8>> + ) of + true -> + gleam@string:drop_left(Path_without_test, 1); + + false -> + Path_without_test + end, + Module_prefix = begin + _pipe@1 = Path_without_leading_slash, + gleam@string:replace(_pipe@1, <<"/"/utf8>>, <<"@"/utf8>>) + end, + case gleam@string:length(Module_prefix) of + 0 -> + Module_prefix; + + _ -> + <<Module_prefix/binary, "@"/utf8>> + end. + +-spec collect_modules_in_folder( + binary(), + fun((showtime@internal@common@test_suite:test_module()) -> nil), + gleam@option:option(list(binary())) +) -> list(showtime@internal@common@test_suite:test_module()). +collect_modules_in_folder(Path, Test_module_handler, Only_modules) -> + Module_prefix = get_module_prefix(Path), + _assert_subject = simplifile:read_directory(Path), + {ok, Files} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/internal/erlang/discover"/utf8>>, + function => <<"collect_modules_in_folder"/utf8>>, + line => 40}) + end, + Test_modules_in_folder = begin + _pipe = Files, + _pipe@1 = gleam@list:filter( + _pipe, + fun(_capture) -> + gleam@string:ends_with(_capture, <<"_test.gleam"/utf8>>) + end + ), + gleam@list:filter_map( + _pipe@1, + fun(Test_module_file) -> + Module_name = <<Module_prefix/binary, + (begin + _pipe@2 = Test_module_file, + gleam@string:replace( + _pipe@2, + <<".gleam"/utf8>>, + <<""/utf8>> + ) + end)/binary>>, + case Only_modules of + {some, Only_modules_list} -> + Module_in_list = begin + _pipe@3 = Only_modules_list, + gleam@list:any( + _pipe@3, + fun(Only_module_name) -> + Only_module_name =:= begin + _pipe@4 = Module_name, + gleam@string:replace( + _pipe@4, + <<"@"/utf8>>, + <<"/"/utf8>> + ) + end + end + ) + end, + case Module_in_list of + true -> + Test_module = {test_module, + Module_name, + {some, Test_module_file}}, + Test_module_handler(Test_module), + {ok, Test_module}; + + false -> + {error, nil} + end; + + none -> + Test_module@1 = {test_module, + Module_name, + {some, Test_module_file}}, + Test_module_handler(Test_module@1), + {ok, Test_module@1} + end + end + ) + end, + Test_modules_in_subfolders = begin + _pipe@5 = Files, + _pipe@6 = gleam@list:map( + _pipe@5, + fun(Filename) -> + <<<<Path/binary, "/"/utf8>>/binary, Filename/binary>> + end + ), + _pipe@7 = gleam@list:filter( + _pipe@6, + fun(File) -> simplifile:is_directory(File) end + ), + gleam@list:fold( + _pipe@7, + [], + fun(Modules, Subfolder) -> _pipe@8 = Modules, + gleam@list:append( + _pipe@8, + collect_modules_in_folder( + Subfolder, + Test_module_handler, + Only_modules + ) + ) end + ) + end, + _pipe@9 = Test_modules_in_folder, + gleam@list:append(_pipe@9, Test_modules_in_subfolders). + +-spec collect_modules( + fun((showtime@internal@common@test_suite:test_module()) -> nil), + gleam@option:option(list(binary())) +) -> list(showtime@internal@common@test_suite:test_module()). +collect_modules(Test_module_handler, Only_modules) -> + collect_modules_in_folder( + <<"./test"/utf8>>, + Test_module_handler, + Only_modules + ). + +-spec collect_test_functions(showtime@internal@common@test_suite:test_module()) -> showtime@internal@common@test_suite:test_suite(). +collect_test_functions(Module) -> + Test_functions = begin + _pipe = erlang:apply( + erlang:binary_to_atom(erlang:element(2, Module)), + erlang:binary_to_atom(<<"module_info"/utf8>>), + [gleam@dynamic:from(erlang:binary_to_atom(<<"exports"/utf8>>))] + ), + gleam@dynamic:unsafe_coerce(_pipe) + end, + Test_functions_filtered = begin + _pipe@1 = Test_functions, + _pipe@3 = gleam@list:map( + _pipe@1, + fun(Entry) -> + {Name, Arity} = case Entry of + {_, _} -> Entry; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/internal/erlang/discover"/utf8>>, + function => <<"collect_test_functions"/utf8>>, + line => 131}) + end, + {begin + _pipe@2 = Name, + erlang:atom_to_binary(_pipe@2) + end, + Arity} + end + ), + _pipe@4 = gleam@list:filter_map( + _pipe@3, + fun(Entry@1) -> + {Name@1, Arity@1} = case Entry@1 of + {_, _} -> Entry@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"showtime/internal/erlang/discover"/utf8>>, + function => <<"collect_test_functions"/utf8>>, + line => 139}) + end, + case gleam@string:ends_with(Name@1, <<"_test"/utf8>>) of + true -> + case Arity@1 of + 0 -> + {ok, Name@1}; + + _ -> + gleam@io:println( + <<<<<<<<"WARNING: function \""/utf8, + Name@1/binary>>/binary, + "\" has arity: "/utf8>>/binary, + (gleam@int:to_string(Arity@1))/binary>>/binary, + " - cannot be used as test (needs to be 0)"/utf8>> + ), + {error, <<"Wrong arity"/utf8>>} + end; + + false -> + {error, <<"Non matching name"/utf8>>} + end + end + ), + _pipe@5 = gleam@list:filter( + _pipe@4, + fun(_capture) -> + gleam@string:ends_with(_capture, <<"_test"/utf8>>) + end + ), + gleam@list:map( + _pipe@5, + fun(Function_name) -> {test_function, Function_name} end + ) + end, + {test_suite, Module, Test_functions_filtered}. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache Binary files differnew file mode 100644 index 0000000..e21ee6b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache_meta Binary files differnew file mode 100644 index 0000000..1223c48 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.erl new file mode 100644 index 0000000..d3bdf0f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@event_handler.erl @@ -0,0 +1,76 @@ +-module(showtime@internal@erlang@event_handler). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([start/0]). +-export_type([event_handler_message/0]). + +-type event_handler_message() :: {event_handler_message, + showtime@internal@common@test_suite:test_event(), + gleam@erlang@process:subject(integer())}. + +-spec system_time() -> integer(). +system_time() -> + os:system_time(millisecond). + +-spec start() -> fun((showtime@internal@common@test_suite:test_event()) -> nil). +start() -> + _assert_subject = gleam@otp@actor:start( + {not_started, 0, gleam@map:new()}, + fun(Msg, State) -> + {event_handler_message, Test_event, Reply_to} = Msg, + {Test_state, Num_done, Events} = State, + Updated_state = showtime@internal@common@common_event_handler:handle_event( + Test_event, + fun system_time/0, + {handler_state, Test_state, Num_done, Events} + ), + case Updated_state of + {handler_state, {finished, Num_modules}, Num_done@1, Events@1} when Num_done@1 =:= Num_modules -> + {Test_report, Num_failed} = showtime@internal@reports@formatter:create_test_report( + Events@1 + ), + gleam@io:println(Test_report), + gleam@erlang@process:send(Reply_to, Num_failed), + {stop, normal}; + + {handler_state, Test_state@1, Num_done@2, Events@2} -> + {continue, {Test_state@1, Num_done@2, Events@2}, none} + end + end + ), + {ok, Subject} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/internal/erlang/event_handler"/utf8>>, + function => <<"start"/utf8>>, + line => 32}) + end, + Parent_subject = gleam@erlang@process:new_subject(), + Selector = begin + _pipe = gleam_erlang_ffi:new_selector(), + gleam@erlang@process:selecting(_pipe, Parent_subject, fun(X) -> X end) + end, + fun(Test_event@1) -> case Test_event@1 of + {end_test_run, _} -> + gleam@erlang@process:send( + Subject, + {event_handler_message, Test_event@1, Parent_subject} + ), + Num_failed@1 = gleam_erlang_ffi:select(Selector), + case Num_failed@1 > 0 of + true -> + erlang:halt(1); + + false -> + erlang:halt(0) + end; + + _ -> + gleam@erlang@process:send( + Subject, + {event_handler_message, Test_event@1, Parent_subject} + ) + end end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache Binary files differnew file mode 100644 index 0000000..39bc91c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache_meta Binary files differnew file mode 100644 index 0000000..7cd0c75 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.erl new file mode 100644 index 0000000..9eaadcf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@module_handler.erl @@ -0,0 +1,53 @@ +-module(showtime@internal@erlang@module_handler). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([start/5]). + +-spec start( + fun((showtime@internal@common@test_suite:test_event()) -> nil), + fun((showtime@internal@common@test_suite:test_module()) -> showtime@internal@common@test_suite:test_suite()), + fun((showtime@internal@common@test_suite:test_suite(), fun((showtime@internal@common@test_suite:test_event()) -> nil), list(binary()), showtime@internal@common@cli:capture()) -> nil), + list(binary()), + showtime@internal@common@cli:capture() +) -> fun((showtime@internal@common@test_suite:test_module()) -> nil). +start( + Test_event_handler, + Test_function_collector, + Run_test_suite, + Ignore_tags, + Capture +) -> + _assert_subject = gleam@otp@actor:start( + nil, + fun(Module, State) -> + gleam@erlang@process:start( + fun() -> + Test_suite = Test_function_collector(Module), + Test_event_handler({start_test_suite, Module}), + Run_test_suite( + Test_suite, + Test_event_handler, + Ignore_tags, + Capture + ), + Test_event_handler({end_test_suite, Module}) + end, + false + ), + {continue, State, none} + end + ), + {ok, Subject} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/internal/erlang/module_handler"/utf8>>, + function => <<"start"/utf8>>, + line => 23}) + end, + fun(Test_module) -> + gleam@erlang@process:send(Subject, Test_module), + nil + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache Binary files differnew file mode 100644 index 0000000..8251097 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache_meta Binary files differnew file mode 100644 index 0000000..069c9cf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.erl new file mode 100644 index 0000000..93fc592 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@erlang@runner.erl @@ -0,0 +1,46 @@ +-module(showtime@internal@erlang@runner). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([run_test/4, run_test_suite/4]). + +-spec run_test( + binary(), + binary(), + list(binary()), + showtime@internal@common@cli:capture() +) -> {ok, showtime@internal@common@test_result:test_return()} | + {error, showtime@internal@common@test_result:exception()}. +run_test(Module_name, Test_name, Ignore_tags, Capture) -> + Result = showtime_ffi:run_test( + erlang:binary_to_atom(Module_name), + erlang:binary_to_atom(Test_name), + Ignore_tags, + Capture + ), + Result. + +-spec run_test_suite( + showtime@internal@common@test_suite:test_suite(), + fun((showtime@internal@common@test_suite:test_event()) -> nil), + list(binary()), + showtime@internal@common@cli:capture() +) -> nil. +run_test_suite(Test_suite, Test_event_handler, Ignore_tags, Capture) -> + _pipe = erlang:element(3, Test_suite), + gleam@list:each( + _pipe, + fun(Test) -> + Test_event_handler( + {start_test, erlang:element(2, Test_suite), Test} + ), + Result = run_test( + erlang:element(2, erlang:element(2, Test_suite)), + erlang:element(2, Test), + Ignore_tags, + Capture + ), + Test_event_handler( + {end_test, erlang:element(2, Test_suite), Test, Result} + ) + end + ). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache Binary files differnew file mode 100644 index 0000000..8fd4424 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache_meta Binary files differnew file mode 100644 index 0000000..be99189 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.erl new file mode 100644 index 0000000..64f94fa --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@compare.erl @@ -0,0 +1,61 @@ +-module(showtime@internal@reports@compare). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([compare/2]). + +-spec compare(gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> {binary(), + binary()}. +compare(Expected, Got) -> + Expected_as_list = begin + _pipe = Expected, + (gleam@dynamic:list(fun gleam@dynamic:dynamic/1))(_pipe) + end, + Got_as_list = begin + _pipe@1 = Got, + (gleam@dynamic:list(fun gleam@dynamic:dynamic/1))(_pipe@1) + end, + Expected_as_string = begin + _pipe@2 = Expected, + gleam@dynamic:string(_pipe@2) + end, + Got_as_string = begin + _pipe@3 = Got, + gleam@dynamic:string(_pipe@3) + end, + case {Expected_as_list, Got_as_list, Expected_as_string, Got_as_string} of + {{ok, Expected_list}, {ok, Got_list}, _, _} -> + Comparison = begin + _pipe@4 = gap:compare_lists(Expected_list, Got_list), + _pipe@5 = gap@styling:from_comparison(_pipe@4), + _pipe@6 = gap@styling:highlight( + _pipe@5, + fun showtime@internal@reports@styles:expected_highlight/1, + fun showtime@internal@reports@styles:got_highlight/1, + fun(Item) -> Item end + ), + gap@styling:to_styled_comparison(_pipe@6) + end, + {erlang:element(2, Comparison), erlang:element(3, Comparison)}; + + {_, _, {ok, Expected_string}, {ok, Got_string}} -> + Comparison@1 = begin + _pipe@7 = gap:compare_strings(Expected_string, Got_string), + _pipe@8 = gap@styling:from_comparison(_pipe@7), + _pipe@9 = gap@styling:highlight( + _pipe@8, + fun showtime@internal@reports@styles:expected_highlight/1, + fun showtime@internal@reports@styles:got_highlight/1, + fun(Item@1) -> Item@1 end + ), + gap@styling:to_styled_comparison(_pipe@9) + end, + {erlang:element(2, Comparison@1), erlang:element(3, Comparison@1)}; + + {_, _, _, _} -> + {showtime@internal@reports@styles:expected_highlight( + gleam@string:inspect(Expected) + ), + showtime@internal@reports@styles:got_highlight( + gleam@string:inspect(Got) + )} + end. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache Binary files differnew file mode 100644 index 0000000..69a4738 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache_meta Binary files differnew file mode 100644 index 0000000..86e3c59 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.erl new file mode 100644 index 0000000..cef0b49 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@formatter.erl @@ -0,0 +1,749 @@ +-module(showtime@internal@reports@formatter). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([create_test_report/1]). +-export_type([glee_unit_assertion_type/0, module_and_test/0, unified_error/0]). + +-type glee_unit_assertion_type() :: {glee_unit_assert_equal, binary()} | + {glee_unit_assert_not_equal, binary()} | + {glee_unit_assert_match, binary()}. + +-type module_and_test() :: {module_and_test_run, + binary(), + showtime@internal@common@test_suite:test_run()}. + +-type unified_error() :: {unified_error, + gleam@option:option(showtime@tests@meta:meta()), + binary(), + binary(), + binary(), + binary(), + gleam@option:option(integer()), + list(showtime@internal@common@test_result:trace())}. + +-spec erlang_error_to_unified( + list(showtime@internal@common@test_result:reason_detail()), + glee_unit_assertion_type(), + list(showtime@internal@common@test_result:trace()) +) -> unified_error(). +erlang_error_to_unified(Error_details, Assertion_type, Stacktrace) -> + _pipe = Error_details, + gleam@list:fold( + _pipe, + {unified_error, + none, + <<"not_set"/utf8>>, + erlang:element(2, Assertion_type), + <<""/utf8>>, + <<""/utf8>>, + none, + Stacktrace}, + fun(Unified, Reason) -> case Reason of + {expression, Expression} -> + erlang:setelement(3, Unified, Expression); + + {expected, Value} -> + case Assertion_type of + {glee_unit_assert_equal, _} -> + erlang:setelement( + 5, + Unified, + showtime@internal@reports@styles:expected_highlight( + gleam@string:inspect(Value) + ) + ); + + _ -> + Unified + end; + + {value, Value@1} -> + case Assertion_type of + {glee_unit_assert_not_equal, _} -> + erlang:setelement( + 6, + erlang:setelement( + 5, + Unified, + <<(showtime@internal@reports@styles:not_style( + <<"not "/utf8>> + ))/binary, + (gleam@string:inspect(Value@1))/binary>> + ), + showtime@internal@reports@styles:got_highlight( + gleam@string:inspect(Value@1) + ) + ); + + _ -> + erlang:setelement( + 6, + Unified, + showtime@internal@reports@styles:got_highlight( + gleam@string:inspect(Value@1) + ) + ) + end; + + {pattern, Pattern} -> + case Pattern of + <<"{ ok , _ }"/utf8>> -> + erlang:setelement( + 5, + Unified, + showtime@internal@reports@styles:expected_highlight( + <<"Ok(_)"/utf8>> + ) + ); + + <<"{ error , _ }"/utf8>> -> + erlang:setelement( + 5, + Unified, + showtime@internal@reports@styles:expected_highlight( + <<"Error(_)"/utf8>> + ) + ); + + _ -> + Unified + end; + + _ -> + Unified + end end + ). + +-spec gleam_error_to_unified( + showtime@internal@common@test_result:gleam_error_detail(), + list(showtime@internal@common@test_result:trace()) +) -> unified_error(). +gleam_error_to_unified(Gleam_error, Stacktrace) -> + case Gleam_error of + {let_assert, _, _, _, _, Value} -> + Result = gleam@dynamic:unsafe_coerce(Value), + {error, Assertion} = case Result of + {error, _} -> Result; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/internal/reports/formatter"/utf8>>, + function => <<"gleam_error_to_unified"/utf8>>, + line => 293}) + end, + case Assertion of + {eq, Got, Expected, Meta} -> + {Expected@1, Got@1} = showtime@internal@reports@compare:compare( + Expected, + Got + ), + {unified_error, + Meta, + <<"assert"/utf8>>, + <<"Assert equal"/utf8>>, + Expected@1, + Got@1, + none, + Stacktrace}; + + {not_eq, Got@2, Expected@2, Meta@1} -> + {unified_error, + Meta@1, + <<"assert"/utf8>>, + <<"Assert not equal"/utf8>>, + <<(showtime@internal@reports@styles:not_style( + <<"not "/utf8>> + ))/binary, + (gleam@string:inspect(Expected@2))/binary>>, + gleam@string:inspect(Got@2), + none, + Stacktrace}; + + {is_ok, Got@3, Meta@2} -> + {unified_error, + Meta@2, + <<"assert"/utf8>>, + <<"Assert is Ok"/utf8>>, + showtime@internal@reports@styles:expected_highlight( + <<"Ok(_)"/utf8>> + ), + showtime@internal@reports@styles:got_highlight( + gleam@string:inspect(Got@3) + ), + none, + Stacktrace}; + + {is_error, Got@4, Meta@3} -> + {unified_error, + Meta@3, + <<"assert"/utf8>>, + <<"Assert is Ok"/utf8>>, + showtime@internal@reports@styles:expected_highlight( + <<"Error(_)"/utf8>> + ), + showtime@internal@reports@styles:got_highlight( + gleam@string:inspect(Got@4) + ), + none, + Stacktrace}; + + {fail, Meta@4} -> + {unified_error, + Meta@4, + <<"assert"/utf8>>, + <<"Assert is Ok"/utf8>>, + showtime@internal@reports@styles:got_highlight( + <<"should.fail()"/utf8>> + ), + showtime@internal@reports@styles:got_highlight( + <<"N/A - test always expected to fail"/utf8>> + ), + none, + Stacktrace} + end + end. + +-spec format_reason(unified_error(), binary(), binary(), list(binary())) -> list(list(showtime@internal@reports@table:col())). +format_reason(Error, Module, Function, Output_buffer) -> + Meta@1 = case erlang:element(2, Error) of + {some, Meta} -> + {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Description"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left, {content, erlang:element(2, Meta)}, 0}]}; + + none -> + none + end, + Stacktrace = begin + _pipe = erlang:element(8, Error), + gleam@list:map(_pipe, fun(Trace) -> case Trace of + {trace, Function@1, _, _} when Function@1 =:= <<""/utf8>> -> + <<"(anonymous)"/utf8>>; + + {trace_module, Module@1, Function@2, _, _} when Function@2 =:= <<""/utf8>> -> + <<<<Module@1/binary, "."/utf8>>/binary, + "(anonymous)"/utf8>>; + + {trace, Function@3, _, _} -> + Function@3; + + {trace_module, Module@2, Function@4, _, _} -> + <<<<Module@2/binary, "."/utf8>>/binary, + Function@4/binary>> + end end) + end, + Stacktrace_rows = case Stacktrace of + [] -> + []; + + [First | Rest] -> + First_row = {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Stacktrace"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left, + {styled_content, + showtime@internal@reports@styles:stacktrace_style( + First + )}, + 0}]}, + Rest_rows = begin + _pipe@1 = Rest, + gleam@list:map( + _pipe@1, + fun(Row) -> + {some, + [{align_right, {content, <<""/utf8>>}, 2}, + {separator, <<" "/utf8>>}, + {align_left, + {styled_content, + showtime@internal@reports@styles:stacktrace_style( + Row + )}, + 0}]} + end + ) + end, + [First_row | Rest_rows] + end, + Output_rows = case begin + _pipe@2 = Output_buffer, + _pipe@3 = gleam@list:reverse(_pipe@2), + gleam@list:map( + _pipe@3, + fun(Row@1) -> gleam@string:trim_right(Row@1) end + ) + end of + [] -> + []; + + [First@1 | Rest@1] -> + First_row@1 = {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Output"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left_overflow, + {styled_content, + showtime@internal@reports@styles:stacktrace_style( + First@1 + )}, + 0}]}, + Rest_rows@1 = begin + _pipe@4 = Rest@1, + gleam@list:map( + _pipe@4, + fun(Row@2) -> + {some, + [{align_right, {content, <<""/utf8>>}, 2}, + {separator, <<" "/utf8>>}, + {align_left_overflow, + {styled_content, + showtime@internal@reports@styles:stacktrace_style( + Row@2 + )}, + 0}]} + end + ) + end, + [First_row@1 | Rest_rows@1] + end, + Line@1 = begin + _pipe@5 = erlang:element(7, Error), + _pipe@6 = gleam@option:map( + _pipe@5, + fun(Line) -> <<":"/utf8, (gleam@int:to_string(Line))/binary>> end + ), + gleam@option:unwrap(_pipe@6, <<""/utf8>>) + end, + Arrow = <<(gleam@string:join( + gleam@list:repeat( + <<"-"/utf8>>, + (gleam@string:length(Module) + 1) + ((gleam@string:length( + Function + ) + + gleam@string:length(Line@1)) + div 2) + ), + <<""/utf8>> + ))/binary, + "⌄"/utf8>>, + Standard_table_rows = [{some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:error_style( + <<"Failed"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left, {content, Arrow}, 0}]}, + {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Test"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left, + {styled_content, + <<<<Module/binary, "."/utf8>>/binary, + (showtime@internal@reports@styles:function_style( + <<Function/binary, Line@1/binary>> + ))/binary>>}, + 0}]}, + Meta@1, + {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Expected"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left_overflow, + {styled_content, erlang:element(5, Error)}, + 0}]}, + {some, + [{align_right, + {styled_content, + showtime@internal@reports@styles:heading_style( + <<"Got"/utf8>> + )}, + 2}, + {separator, <<": "/utf8>>}, + {align_left_overflow, + {styled_content, erlang:element(6, Error)}, + 0}]}], + _pipe@7 = Standard_table_rows, + _pipe@8 = gleam@list:append(_pipe@7, Stacktrace_rows), + _pipe@9 = gleam@list:append(_pipe@8, Output_rows), + _pipe@10 = gleam@list:append( + _pipe@9, + [{some, + [{align_right, {content, <<""/utf8>>}, 0}, + {align_right, {content, <<""/utf8>>}, 0}, + {align_right, {content, <<""/utf8>>}, 0}]}] + ), + gleam@list:filter_map( + _pipe@10, + fun(Row@3) -> gleam@option:to_result(Row@3, nil) end + ). + +-spec create_test_report( + gleam@dict:dict(binary(), gleam@dict:dict(binary(), showtime@internal@common@test_suite:test_run())) +) -> {binary(), integer()}. +create_test_report(Test_results) -> + All_test_runs = begin + _pipe = Test_results, + _pipe@1 = gleam@map:values(_pipe), + gleam@list:flat_map(_pipe@1, fun gleam@map:values/1) + end, + Failed_test_runs = begin + _pipe@2 = Test_results, + _pipe@3 = gleam@map:to_list(_pipe@2), + gleam@list:flat_map( + _pipe@3, + fun(Entry) -> + {Module_name, Test_module_results} = Entry, + _pipe@4 = Test_module_results, + _pipe@5 = gleam@map:values(_pipe@4), + gleam@list:filter_map(_pipe@5, fun(Test_run) -> case Test_run of + {completed_test_run, _, _, Result} -> + case Result of + {error, _} -> + {ok, + {module_and_test_run, + Module_name, + Test_run}}; + + {ok, {ignored, _}} -> + {error, nil}; + + {ok, _} -> + {error, nil} + end; + + _ -> + _pipe@6 = Test_run, + gleam@io:debug(_pipe@6), + {error, nil} + end end) + end + ) + end, + Ignored_test_runs = begin + _pipe@7 = Test_results, + _pipe@8 = gleam@map:to_list(_pipe@7), + gleam@list:flat_map( + _pipe@8, + fun(Entry@1) -> + {Module_name@1, Test_module_results@1} = Entry@1, + _pipe@9 = Test_module_results@1, + _pipe@10 = gleam@map:values(_pipe@9), + gleam@list:filter_map( + _pipe@10, + fun(Test_run@1) -> case Test_run@1 of + {completed_test_run, Test_function, _, Result@1} -> + case Result@1 of + {ok, {ignored, Reason}} -> + {ok, + {<<<<Module_name@1/binary, + "."/utf8>>/binary, + (erlang:element( + 2, + Test_function + ))/binary>>, + Reason}}; + + _ -> + {error, nil} + end; + + _ -> + {error, nil} + end end + ) + end + ) + end, + Failed_tests_report = begin + _pipe@11 = Failed_test_runs, + _pipe@12 = gleam@list:filter_map( + _pipe@11, + fun(Module_and_test_run) -> + case erlang:element(3, Module_and_test_run) of + {completed_test_run, Test_function@1, _, Result@2} -> + case Result@2 of + {error, Exception} -> + case erlang:element(3, Exception) of + {assert_equal, Reason_details} -> + {ok, + format_reason( + erlang_error_to_unified( + Reason_details, + {glee_unit_assert_equal, + <<"Assert equal"/utf8>>}, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + ) + ), + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + {assert_not_equal, Reason_details@1} -> + {ok, + format_reason( + erlang_error_to_unified( + Reason_details@1, + {glee_unit_assert_not_equal, + <<"Assert not equal"/utf8>>}, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + ) + ), + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + {assert_match, Reason_details@2} -> + {ok, + format_reason( + erlang_error_to_unified( + Reason_details@2, + {glee_unit_assert_match, + <<"Assert match"/utf8>>}, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + ) + ), + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + {gleam_error, Reason@1} -> + {ok, + format_reason( + gleam_error_to_unified( + Reason@1, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + ) + ), + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + {gleam_assert, Value, Line_no} -> + {ok, + format_reason( + {unified_error, + none, + <<"gleam assert"/utf8>>, + <<"Assert failed"/utf8>>, + <<"Patterns should match"/utf8>>, + showtime@internal@reports@styles:error_style( + gleam@string:inspect( + Value + ) + ), + {some, Line_no}, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + )}, + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + {generic_exception, Value@1} -> + {ok, + format_reason( + {unified_error, + none, + <<"generic exception"/utf8>>, + <<"Test function threw an exception"/utf8>>, + <<"Exception in test function"/utf8>>, + showtime@internal@reports@styles:error_style( + gleam@string:inspect( + Value@1 + ) + ), + none, + erlang:element( + 2, + erlang:element( + 4, + Exception + ) + )}, + erlang:element( + 2, + Module_and_test_run + ), + erlang:element( + 2, + Test_function@1 + ), + erlang:element(5, Exception) + )}; + + Other -> + gleam@io:println( + <<"Other: "/utf8, + (gleam@string:inspect(Other))/binary>> + ), + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"showtime/internal/reports/formatter"/utf8>>, + function => <<"create_test_report"/utf8>>, + line => 178}), + {error, nil} + end; + + _ -> + {error, nil} + end; + + _ -> + {error, nil} + end + end + ), + gleam@list:fold( + _pipe@12, + [], + fun(Rows, Test_rows) -> gleam@list:append(Rows, Test_rows) end + ) + end, + All_test_execution_time_reports = begin + _pipe@13 = All_test_runs, + gleam@list:filter_map(_pipe@13, fun(Test_run@2) -> case Test_run@2 of + {completed_test_run, Test_function@2, Total_time, _} -> + {ok, + <<<<<<(erlang:element(2, Test_function@2))/binary, + ": "/utf8>>/binary, + (gleam@int:to_string(Total_time))/binary>>/binary, + " ms"/utf8>>}; + + _ -> + {error, nil} + end end) + end, + _ = begin + _pipe@14 = All_test_execution_time_reports, + gleam@string:join(_pipe@14, <<"\n"/utf8>>) + end, + All_tests_count = begin + _pipe@15 = All_test_runs, + gleam@list:length(_pipe@15) + end, + Ignored_tests_count = begin + _pipe@16 = Ignored_test_runs, + gleam@list:length(_pipe@16) + end, + Failed_tests_count = begin + _pipe@17 = Failed_test_runs, + gleam@list:length(_pipe@17) + end, + Passed = showtime@internal@reports@styles:passed_style( + <<(gleam@int:to_string( + (All_tests_count - Failed_tests_count) - Ignored_tests_count + ))/binary, + " passed"/utf8>> + ), + Failed = showtime@internal@reports@styles:failed_style( + <<(gleam@int:to_string(Failed_tests_count))/binary, " failed"/utf8>> + ), + Ignored = case Ignored_tests_count of + 0 -> + <<""/utf8>>; + + _ -> + <<", "/utf8, + (showtime@internal@reports@styles:ignored_style( + <<(gleam@int:to_string(Ignored_tests_count))/binary, + " ignored"/utf8>> + ))/binary>> + end, + Failed_tests_table = begin + _pipe@18 = {table, none, Failed_tests_report}, + _pipe@19 = showtime@internal@reports@table:align_table(_pipe@18), + showtime@internal@reports@table:to_string(_pipe@19) + end, + Test_report = <<<<<<<<<<<<"\n"/utf8, Failed_tests_table/binary>>/binary, + "\n"/utf8>>/binary, + Passed/binary>>/binary, + ", "/utf8>>/binary, + Failed/binary>>/binary, + Ignored/binary>>, + {Test_report, Failed_tests_count}. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache Binary files differnew file mode 100644 index 0000000..f974100 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache_meta Binary files differnew file mode 100644 index 0000000..c0078b3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.erl new file mode 100644 index 0000000..5243ae7 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@styles.erl @@ -0,0 +1,93 @@ +-module(showtime@internal@reports@styles). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([not_style/1, module_style/1, heading_style/1, stacktrace_style/1, failed_style/1, error_style/1, got_highlight/1, passed_style/1, expected_highlight/1, ignored_style/1, function_style/1, strip_style/1]). + +-spec not_style(binary()) -> binary(). +not_style(Text) -> + gleam_community@ansi:bold(Text). + +-spec module_style(binary()) -> binary(). +module_style(Text) -> + gleam_community@ansi:cyan(Text). + +-spec heading_style(binary()) -> binary(). +heading_style(Text) -> + gleam_community@ansi:cyan(Text). + +-spec stacktrace_style(binary()) -> binary(). +stacktrace_style(Text) -> + Text. + +-spec bold_red(binary()) -> binary(). +bold_red(Text) -> + gleam_community@ansi:bold(gleam_community@ansi:red(Text)). + +-spec failed_style(binary()) -> binary(). +failed_style(Text) -> + bold_red(Text). + +-spec error_style(binary()) -> binary(). +error_style(Text) -> + bold_red(Text). + +-spec got_highlight(binary()) -> binary(). +got_highlight(Text) -> + bold_red(Text). + +-spec bold_green(binary()) -> binary(). +bold_green(Text) -> + gleam_community@ansi:bold(gleam_community@ansi:green(Text)). + +-spec passed_style(binary()) -> binary(). +passed_style(Text) -> + bold_green(Text). + +-spec expected_highlight(binary()) -> binary(). +expected_highlight(Text) -> + bold_green(Text). + +-spec bold_yellow(binary()) -> binary(). +bold_yellow(Text) -> + gleam_community@ansi:bold(gleam_community@ansi:yellow(Text)). + +-spec ignored_style(binary()) -> binary(). +ignored_style(Text) -> + bold_yellow(Text). + +-spec bold_cyan(binary()) -> binary(). +bold_cyan(Text) -> + gleam_community@ansi:bold(gleam_community@ansi:cyan(Text)). + +-spec function_style(binary()) -> binary(). +function_style(Text) -> + bold_cyan(Text). + +-spec strip_style(binary()) -> binary(). +strip_style(Text) -> + {New_text, _} = begin + _pipe = Text, + _pipe@1 = gleam@string:to_graphemes(_pipe), + gleam@list:fold( + _pipe@1, + {<<""/utf8>>, false}, + fun(Acc, Char) -> + {Str, Removing} = Acc, + Bit_char = gleam_stdlib:identity(Char), + case {Bit_char, Removing} of + {<<16#1b>>, _} -> + {Str, true}; + + {<<16#6d>>, true} -> + {Str, false}; + + {_, true} -> + {Str, true}; + + {_, false} -> + {<<Str/binary, Char/binary>>, false} + end + end + ) + end, + New_text. diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache Binary files differnew file mode 100644 index 0000000..86c39cb --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache_meta Binary files differnew file mode 100644 index 0000000..080524c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.erl new file mode 100644 index 0000000..e0a5b40 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@internal@reports@table.erl @@ -0,0 +1,229 @@ +-module(showtime@internal@reports@table). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([to_string/1, align_table/1]). +-export_type([content/0, col/0, table/0]). + +-type content() :: {content, binary()} | {styled_content, binary()}. + +-type col() :: {align_right, content(), integer()} | + {align_left, content(), integer()} | + {align_right_overflow, content(), integer()} | + {align_left_overflow, content(), integer()} | + {separator, binary()} | + {aligned, binary()}. + +-type table() :: {table, gleam@option:option(binary()), list(list(col()))}. + +-spec to_string(table()) -> binary(). +to_string(Table) -> + Rows = begin + _pipe = erlang:element(3, Table), + _pipe@3 = gleam@list:map(_pipe, fun(Row) -> _pipe@1 = Row, + _pipe@2 = gleam@list:filter_map(_pipe@1, fun(Col) -> case Col of + {separator, Char} -> + {ok, Char}; + + {aligned, Content} -> + {ok, Content}; + + _ -> + {error, nil} + end end), + gleam@string:join(_pipe@2, <<""/utf8>>) end), + gleam@string:join(_pipe@3, <<"\n"/utf8>>) + end, + Header@1 = begin + _pipe@4 = erlang:element(2, Table), + _pipe@5 = gleam@option:map( + _pipe@4, + fun(Header) -> <<Header/binary, "\n"/utf8>> end + ), + gleam@option:unwrap(_pipe@5, <<""/utf8>>) + end, + <<Header@1/binary, Rows/binary>>. + +-spec pad_left(binary(), integer(), binary()) -> binary(). +pad_left(Str, Num, Char) -> + Padding = begin + _pipe = gleam@list:repeat(Char, Num), + gleam@string:join(_pipe, <<""/utf8>>) + end, + <<Padding/binary, Str/binary>>. + +-spec pad_right(binary(), integer(), binary()) -> binary(). +pad_right(Str, Num, Char) -> + Padding = begin + _pipe = gleam@list:repeat(Char, Num), + gleam@string:join(_pipe, <<""/utf8>>) + end, + <<Str/binary, Padding/binary>>. + +-spec align_table(table()) -> table(). +align_table(Table) -> + Cols = begin + _pipe = erlang:element(3, Table), + gleam@list:transpose(_pipe) + end, + Col_width = begin + _pipe@1 = Cols, + gleam@list:map(_pipe@1, fun(Col) -> _pipe@2 = Col, + _pipe@3 = gleam@list:map( + _pipe@2, + fun(Content) -> case Content of + {align_right, {content, Unstyled}, _} -> + Unstyled; + + {align_right, {styled_content, Styled}, _} -> + showtime@internal@reports@styles:strip_style( + Styled + ); + + {align_left, {content, Unstyled@1}, _} -> + Unstyled@1; + + {align_left, {styled_content, Styled@1}, _} -> + showtime@internal@reports@styles:strip_style( + Styled@1 + ); + + {align_left_overflow, _, _} -> + <<""/utf8>>; + + {align_right_overflow, _, _} -> + <<""/utf8>>; + + {separator, Char} -> + Char; + + {aligned, Content@1} -> + Content@1 + end end + ), + gleam@list:fold( + _pipe@3, + 0, + fun(Max, Str) -> + gleam@int:max(Max, gleam@string:length(Str)) + end + ) end) + end, + Aligned_col = begin + _pipe@4 = Cols, + _pipe@5 = gleam@list:zip(_pipe@4, Col_width), + gleam@list:map( + _pipe@5, + fun(Col_and_width) -> + {Col@1, Width} = Col_and_width, + _pipe@6 = Col@1, + gleam@list:map(_pipe@6, fun(Content@2) -> case Content@2 of + {align_right, {content, Unstyled@2}, Margin} -> + {aligned, + pad_left( + Unstyled@2, + (Width + Margin) - gleam@string:length( + Unstyled@2 + ), + <<" "/utf8>> + )}; + + {align_right, {styled_content, Styled@2}, Margin@1} -> + {aligned, + pad_left( + Styled@2, + (Width + Margin@1) - gleam@string:length( + showtime@internal@reports@styles:strip_style( + Styled@2 + ) + ), + <<" "/utf8>> + )}; + + {align_right_overflow, + {content, Unstyled@3}, + Margin@2} -> + {aligned, + pad_left( + Unstyled@3, + (Width + Margin@2) - gleam@string:length( + Unstyled@3 + ), + <<" "/utf8>> + )}; + + {align_right_overflow, + {styled_content, Styled@3}, + Margin@3} -> + {aligned, + pad_left( + Styled@3, + (Width + Margin@3) - gleam@string:length( + showtime@internal@reports@styles:strip_style( + Styled@3 + ) + ), + <<" "/utf8>> + )}; + + {align_left, {content, Unstyled@4}, Margin@4} -> + {aligned, + pad_right( + Unstyled@4, + (Width + Margin@4) - gleam@string:length( + Unstyled@4 + ), + <<" "/utf8>> + )}; + + {align_left, {styled_content, Styled@4}, Margin@5} -> + {aligned, + pad_right( + Styled@4, + (Width + Margin@5) - gleam@string:length( + showtime@internal@reports@styles:strip_style( + Styled@4 + ) + ), + <<" "/utf8>> + )}; + + {align_left_overflow, + {content, Unstyled@5}, + Margin@6} -> + {aligned, + pad_right( + Unstyled@5, + (Width + Margin@6) - gleam@string:length( + Unstyled@5 + ), + <<" "/utf8>> + )}; + + {align_left_overflow, + {styled_content, Styled@5}, + Margin@7} -> + {aligned, + pad_right( + Styled@5, + (Width + Margin@7) - gleam@string:length( + showtime@internal@reports@styles:strip_style( + Styled@5 + ) + ), + <<" "/utf8>> + )}; + + {separator, Char@1} -> + {separator, Char@1}; + + {aligned, Content@3} -> + {aligned, Content@3} + end end) + end + ) + end, + Aligned_rows = begin + _pipe@7 = Aligned_col, + gleam@list:transpose(_pipe@7) + end, + erlang:setelement(3, Table, Aligned_rows). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache Binary files differnew file mode 100644 index 0000000..d9b2000 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache_meta Binary files differnew file mode 100644 index 0000000..7f1bdda --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.erl new file mode 100644 index 0000000..904345a --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@meta.erl @@ -0,0 +1,8 @@ +-module(showtime@tests@meta). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([meta/0]). + +-type meta() :: {meta, binary(), list(binary())}. + + diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache Binary files differnew file mode 100644 index 0000000..1adcc9d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache_meta Binary files differnew file mode 100644 index 0000000..fcc4e8a --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.erl new file mode 100644 index 0000000..88dafdd --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@should.erl @@ -0,0 +1,143 @@ +-module(showtime@tests@should). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([evaluate/1, equal/2, equal_meta/3, not_equal/2, not_equal_meta/3, be_ok/1, be_ok_meta/2, be_error/1, be_error_meta/2, fail/0, fail_meta/1, be_true/1, be_true_meta/2, be_false/1, be_false_meta/2]). +-export_type([assertion/2]). + +-type assertion(OEX, OEY) :: {eq, + OEX, + OEX, + gleam@option:option(showtime@tests@meta:meta())} | + {not_eq, OEX, OEX, gleam@option:option(showtime@tests@meta:meta())} | + {is_ok, + {ok, OEX} | {error, OEY}, + gleam@option:option(showtime@tests@meta:meta())} | + {is_error, + {ok, OEX} | {error, OEY}, + gleam@option:option(showtime@tests@meta:meta())} | + {fail, gleam@option:option(showtime@tests@meta:meta())}. + +-spec evaluate(assertion(any(), any())) -> nil. +evaluate(Assertion) -> + case Assertion of + {eq, A, B, _} -> + case A =:= B of + true -> + nil; + + false -> + showtime_ffi:gleam_error({error, Assertion}) + end; + + {not_eq, A@1, B@1, _} -> + case A@1 /= B@1 of + true -> + nil; + + false -> + showtime_ffi:gleam_error({error, Assertion}) + end; + + {is_ok, A@2, _} -> + case A@2 of + {ok, _} -> + nil; + + {error, _} -> + showtime_ffi:gleam_error({error, Assertion}) + end; + + {is_error, A@3, _} -> + case A@3 of + {error, _} -> + nil; + + {ok, _} -> + showtime_ffi:gleam_error({error, Assertion}) + end; + + {fail, _} -> + showtime_ffi:gleam_error({error, Assertion}) + end. + +-spec equal(OEZ, OEZ) -> nil. +equal(A, B) -> + evaluate({eq, A, B, none}). + +-spec equal_meta(OFB, OFB, showtime@tests@meta:meta()) -> nil. +equal_meta(A, B, Meta) -> + evaluate({eq, A, B, {some, Meta}}). + +-spec not_equal(OFD, OFD) -> nil. +not_equal(A, B) -> + evaluate({not_eq, A, B, none}). + +-spec not_equal_meta(OFF, OFF, showtime@tests@meta:meta()) -> nil. +not_equal_meta(A, B, Meta) -> + evaluate({not_eq, A, B, {some, Meta}}). + +-spec be_ok({ok, OFH} | {error, any()}) -> OFH. +be_ok(A) -> + evaluate({is_ok, A, none}), + {ok, Value} = case A of + {ok, _} -> A; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/tests/should"/utf8>>, + function => <<"be_ok"/utf8>>, + line => 30}) + end, + Value. + +-spec be_ok_meta({ok, any()} | {error, any()}, showtime@tests@meta:meta()) -> nil. +be_ok_meta(A, Meta) -> + evaluate({is_ok, A, {some, Meta}}). + +-spec be_error({ok, any()} | {error, OFS}) -> OFS. +be_error(A) -> + evaluate({is_error, A, none}), + {error, Value} = case A of + {error, _} -> A; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"showtime/tests/should"/utf8>>, + function => <<"be_error"/utf8>>, + line => 40}) + end, + Value. + +-spec be_error_meta({ok, any()} | {error, any()}, showtime@tests@meta:meta()) -> nil. +be_error_meta(A, Meta) -> + evaluate({is_error, A, {some, Meta}}). + +-spec fail() -> nil. +fail() -> + evaluate({fail, none}). + +-spec fail_meta(showtime@tests@meta:meta()) -> nil. +fail_meta(Meta) -> + evaluate({fail, {some, Meta}}). + +-spec be_true(boolean()) -> nil. +be_true(A) -> + _pipe = A, + equal(_pipe, true). + +-spec be_true_meta(boolean(), showtime@tests@meta:meta()) -> nil. +be_true_meta(A, Meta) -> + _pipe = A, + equal_meta(_pipe, true, Meta). + +-spec be_false(boolean()) -> nil. +be_false(A) -> + _pipe = A, + equal(_pipe, false). + +-spec be_false_meta(boolean(), showtime@tests@meta:meta()) -> nil. +be_false_meta(A, Meta) -> + _pipe = A, + equal_meta(_pipe, false, Meta). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache Binary files differnew file mode 100644 index 0000000..06be22a --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache_meta b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache_meta Binary files differnew file mode 100644 index 0000000..8354c6f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.cache_meta diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.erl new file mode 100644 index 0000000..115dbb1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime@tests@test.erl @@ -0,0 +1,57 @@ +-module(showtime@tests@test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([test/2, equal/3, not_equal/3, with_meta/2, be_ok/2, be_error/2, fail/1, be_true/2, be_false/2]). +-export_type([test/0, meta_should/1]). + +-type test() :: {test, showtime@tests@meta:meta(), fun(() -> nil)}. + +-type meta_should(PQU) :: {meta_should, + fun((PQU, PQU) -> nil), + fun((PQU, PQU) -> nil)}. + +-spec test(showtime@tests@meta:meta(), fun((showtime@tests@meta:meta()) -> nil)) -> test(). +test(Meta, Test_function) -> + {test, Meta, fun() -> Test_function(Meta) end}. + +-spec equal(PQZ, PQZ, showtime@tests@meta:meta()) -> nil. +equal(A, B, Meta) -> + gleam@io:debug(A), + gleam@io:debug(B), + showtime@tests@should:equal_meta(A, B, Meta). + +-spec not_equal(PRB, PRB, showtime@tests@meta:meta()) -> nil. +not_equal(A, B, Meta) -> + showtime@tests@should:equal_meta(A, B, Meta). + +-spec with_meta(showtime@tests@meta:meta(), fun((meta_should(any())) -> nil)) -> test(). +with_meta(Meta, Test_function) -> + {test, + Meta, + fun() -> + Test_function( + {meta_should, + fun(A, B) -> equal(A, B, Meta) end, + fun(A@1, B@1) -> not_equal(A@1, B@1, Meta) end} + ) + end}. + +-spec be_ok({ok, any()} | {error, any()}, showtime@tests@meta:meta()) -> nil. +be_ok(A, Meta) -> + showtime@tests@should:be_ok_meta(A, Meta). + +-spec be_error({ok, any()} | {error, any()}, showtime@tests@meta:meta()) -> nil. +be_error(A, Meta) -> + showtime@tests@should:be_error_meta(A, Meta). + +-spec fail(showtime@tests@meta:meta()) -> nil. +fail(Meta) -> + showtime@tests@should:fail_meta(Meta). + +-spec be_true(boolean(), showtime@tests@meta:meta()) -> nil. +be_true(A, Meta) -> + showtime@tests@should:be_true_meta(A, Meta). + +-spec be_false(boolean(), showtime@tests@meta:meta()) -> nil. +be_false(A, Meta) -> + showtime@tests@should:be_false_meta(A, Meta). diff --git a/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime_ffi.erl b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime_ffi.erl new file mode 100644 index 0000000..3259623 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/_gleam_artefacts/showtime_ffi.erl @@ -0,0 +1,187 @@ +-module(showtime_ffi). + +-export([run_test/4, functions/0, capture_output/1, gleam_error/1]). + +gleam_error(Value) -> + erlang:error(#{ + gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => Value, + module => <<"this/is/not/used"/utf8>>, + function => <<"gleam_error"/utf8>>, + % Not used + line => 0 + }). + +start_output_capture(Capture) -> + OldGroupLeader = group_leader(), + CapturePid = spawn(showtime_ffi, capture_output, [{[], {OldGroupLeader, Capture}}]), + group_leader(CapturePid, self()), + {CapturePid, OldGroupLeader}. + +stop_output_capture({CapturePid, OldGroupLeader}) -> + group_leader(OldGroupLeader, self()), + CapturePid ! {capture_done, self()}, + receive + Buffer -> + Buffer + end. + +capture_output({Buffer, {OldGroupLeader, Capture}}) -> + receive + {io_request, From, ReplyAs, {put_chars, unicode, BitString}} -> + case Capture of + yes -> + From ! {io_reply, ReplyAs, ok}, + capture_output({[BitString | Buffer], {OldGroupLeader, Capture}}); + mixed -> + OldGroupLeader ! {io_request, From, ReplyAs, {put_chars, unicode, BitString}}, + capture_output({[BitString | Buffer], {OldGroupLeader, Capture}}); + no -> + OldGroupLeader ! {io_request, From, ReplyAs, {put_chars, unicode, BitString}}, + capture_output({Buffer, {OldGroupLeader, Capture}}) + end; + {capture_done, SenderPid} -> + SenderPid ! Buffer; + OtherMessage -> + OldGroupLeader ! OtherMessage, + capture_output({Buffer, {OldGroupLeader, Capture}}) + end. + +run_test(Module, Function, IgnoreTags, Capture) -> + OutputCapture = start_output_capture(Capture), + try + Result = apply(Module, Function, []), + {ResultType, FinalResult} = + case Result of + {test, {meta, _Description, Tags}, TestFun} -> + case + lists:any( + fun(Tag) -> + lists:any(fun(IgnoreTag) -> IgnoreTag == Tag end, IgnoreTags) + end, + Tags + ) + of + true -> + {ignored, ignore}; + false -> + {test_function_return, TestFun()} + end; + DirectResult -> + {test_function_return, DirectResult} + end, + OutputCaptureBuffer = stop_output_capture(OutputCapture), + case ResultType of + ignored -> {ok, {ResultType, FinalResult}}; + _ -> {ok, {ResultType, FinalResult, OutputCaptureBuffer}} + end + catch + Class:Reason:Stacktrace -> + GleamReason = + case Reason of + {Assertion, ReasonList} -> + ErlangReasonList = + lists:map( + fun(ReasonDetail) -> + case ReasonDetail of + {line, LineNo} -> + {reason_line, LineNo}; + {expression, List} -> + {expression, list_to_binary(List)}; + {module, ModuleAtom} -> + {module, atom_to_binary(ModuleAtom)}; + {pattern, Pattern} -> + {pattern, list_to_binary(Pattern)}; + Other -> + Other + end + end, + ReasonList + ), + GleamAssertionType = + case Assertion of + assertEqual -> + assert_equal; + assertNotEqual -> + assert_not_equal; + assertMatch -> + assert_match; + OtherAssertionType -> + OtherAssertionType + end, + {GleamAssertionType, ErlangReasonList}; + #{ + function := GleamFunction, + gleam_error := GleamError, + line := Line, + message := Message, + module := GleamModule, + value := Value + } -> + case Value of + {error, {OkValue, _, _, _}} when OkValue == not_eq; OkValue == eq -> + {gleam_error, + {GleamError, GleamModule, GleamFunction, Line, Message, Value}}; + {error, {OkValue, _, _}} when OkValue == is_ok; OkValue == is_error -> + {gleam_error, + {GleamError, GleamModule, GleamFunction, Line, Message, Value}}; + {error, {OkValue, _}} when OkValue == fail -> + {gleam_error, + {GleamError, GleamModule, GleamFunction, Line, Message, Value}}; + _ -> + {gleam_assert, Value, Line} + end; + OtherReason -> + {generic_exception, OtherReason} + end, + GleamClass = + case Class of + error -> + erlang_error; + Other -> + Other + end, + GleamTraceList = + lists:map( + fun(Trace) -> + case Trace of + {ModuleName, FunctionName, Arity, ExtraInfoList} -> + {trace_module, atom_to_binary(ModuleName), + atom_to_binary(FunctionName), map_arity(Arity), + map_extra_info_list(ExtraInfoList)}; + {FunctionName, Arity, ExtraInfoList} -> + {trace, atom_to_binary(FunctionName), map_arity(Arity), + map_extra_info_list(ExtraInfoList)} + end + end, + Stacktrace + ), + OutputCaptureBufferCatch = stop_output_capture(OutputCapture), + {error, + {erlang_exception, GleamClass, GleamReason, {trace_list, GleamTraceList}, + OutputCaptureBufferCatch}} + end. + +map_extra_info_list(ExtraInfoList) -> + lists:map( + fun(ExtraInfo) -> + case ExtraInfo of + {file, FileNameList} -> {file, list_to_binary(FileNameList)}; + Other -> Other + end + end, + ExtraInfoList + ). + +map_arity(Arity) -> + if + is_list(Arity) -> + {arg_list, Arity}; + is_integer(Arity) -> + {num, Arity} + end. + +functions() -> + Funs = module_info(exports), + Funs. diff --git a/aoc2023/build/dev/erlang/adglent/ebin/adglent.app b/aoc2023/build/dev/erlang/adglent/ebin/adglent.app new file mode 100644 index 0000000..f8e1aa6 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/adglent.app @@ -0,0 +1,17 @@ +{application, adglent, [ + {vsn, "1.2.0"}, + {applications, [gap, + gleam_community_ansi, + gleam_erlang, + gleam_http, + gleam_httpc, + gleam_otp, + gleam_stdlib, + glint, + simplifile, + snag, + tom]}, + {description, "Advent of code helper - automating setup of tests, solution template and problem input"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/adglent/ebin/adglent.beam b/aoc2023/build/dev/erlang/adglent/ebin/adglent.beam Binary files differnew file mode 100644 index 0000000..aad1d26 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/adglent.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/adglent@day.beam b/aoc2023/build/dev/erlang/adglent/ebin/adglent@day.beam Binary files differnew file mode 100644 index 0000000..b7c03ed --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/adglent@day.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/adglent@init.beam b/aoc2023/build/dev/erlang/adglent/ebin/adglent@init.beam Binary files differnew file mode 100644 index 0000000..be1eae9 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/adglent@init.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/adglent_ffi.beam b/aoc2023/build/dev/erlang/adglent/ebin/adglent_ffi.beam Binary files differnew file mode 100644 index 0000000..1c75150 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/adglent_ffi.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@aoc_client.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@aoc_client.beam Binary files differnew file mode 100644 index 0000000..85aa9ae --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@aoc_client.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@errors.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@errors.beam Binary files differnew file mode 100644 index 0000000..c8778d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@errors.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@prompt.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@prompt.beam Binary files differnew file mode 100644 index 0000000..0228df2 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@prompt.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@template.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@template.beam Binary files differnew file mode 100644 index 0000000..4a3c938 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@template.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@solution.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@solution.beam Binary files differnew file mode 100644 index 0000000..aaf50f6 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@solution.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@test_main.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@test_main.beam Binary files differnew file mode 100644 index 0000000..d214095 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@test_main.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_gleeunit.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_gleeunit.beam Binary files differnew file mode 100644 index 0000000..7dc47b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_gleeunit.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_showtime.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_showtime.beam Binary files differnew file mode 100644 index 0000000..3667f53 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@templates@testfile_showtime.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/priv@toml.beam b/aoc2023/build/dev/erlang/adglent/ebin/priv@toml.beam Binary files differnew file mode 100644 index 0000000..ce828c9 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/priv@toml.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime.beam Binary files differnew file mode 100644 index 0000000..c1d19b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@cli.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@cli.beam Binary files differnew file mode 100644 index 0000000..dec1bcc --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@cli.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@common_event_handler.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@common_event_handler.beam Binary files differnew file mode 100644 index 0000000..50fe885 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@common_event_handler.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_result.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_result.beam Binary files differnew file mode 100644 index 0000000..277fdd1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_result.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_suite.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_suite.beam Binary files differnew file mode 100644 index 0000000..42dbbb9 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@common@test_suite.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@discover.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@discover.beam Binary files differnew file mode 100644 index 0000000..9f5d14e --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@discover.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@event_handler.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@event_handler.beam Binary files differnew file mode 100644 index 0000000..c9a64e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@event_handler.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@module_handler.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@module_handler.beam Binary files differnew file mode 100644 index 0000000..6b95d6c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@module_handler.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@runner.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@runner.beam Binary files differnew file mode 100644 index 0000000..0681641 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@erlang@runner.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@compare.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@compare.beam Binary files differnew file mode 100644 index 0000000..cfe37b1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@compare.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@formatter.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@formatter.beam Binary files differnew file mode 100644 index 0000000..46b885b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@formatter.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@styles.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@styles.beam Binary files differnew file mode 100644 index 0000000..4fb83b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@styles.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@table.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@table.beam Binary files differnew file mode 100644 index 0000000..aaeb33c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@internal@reports@table.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@meta.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@meta.beam Binary files differnew file mode 100644 index 0000000..ffaff22 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@meta.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@should.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@should.beam Binary files differnew file mode 100644 index 0000000..a87184d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@should.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@test.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@test.beam Binary files differnew file mode 100644 index 0000000..65f2a87 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime@tests@test.beam diff --git a/aoc2023/build/dev/erlang/adglent/ebin/showtime_ffi.beam b/aoc2023/build/dev/erlang/adglent/ebin/showtime_ffi.beam Binary files differnew file mode 100644 index 0000000..982e813 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/ebin/showtime_ffi.beam diff --git a/aoc2023/build/dev/erlang/adglent/include/adglent_Example.hrl b/aoc2023/build/dev/erlang/adglent/include/adglent_Example.hrl new file mode 100644 index 0000000..615e473 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/adglent_Example.hrl @@ -0,0 +1 @@ +-record(example, {input :: binary(), answer :: any()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomGetError.hrl b/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomGetError.hrl new file mode 100644 index 0000000..4cd5ddd --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomGetError.hrl @@ -0,0 +1 @@ +-record(tom_get_error, {error :: tom:get_error()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomParseError.hrl b/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomParseError.hrl new file mode 100644 index 0000000..7306934 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/priv@toml_TomParseError.hrl @@ -0,0 +1 @@ +-record(tom_parse_error, {error :: tom:parse_error()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_Finished.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_Finished.hrl new file mode 100644 index 0000000..7d24e52 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_Finished.hrl @@ -0,0 +1 @@ +-record(finished, {num_modules :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_HandlerState.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_HandlerState.hrl new file mode 100644 index 0000000..3efcd39 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@common_event_handler_HandlerState.hrl @@ -0,0 +1,5 @@ +-record(handler_state, { + test_state :: showtime@internal@common@common_event_handler:test_state(), + num_done :: integer(), + events :: gleam@dict:dict(binary(), gleam@dict:dict(binary(), showtime@internal@common@test_suite:test_run())) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ArgList.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ArgList.hrl new file mode 100644 index 0000000..79f34f8 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ArgList.hrl @@ -0,0 +1 @@ +-record(arg_list, {arg_list :: list(gleam@dynamic:dynamic_())}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertEqual.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertEqual.hrl new file mode 100644 index 0000000..c6458ba --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertEqual.hrl @@ -0,0 +1,3 @@ +-record(assert_equal, { + details :: list(showtime@internal@common@test_result:reason_detail()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertMatch.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertMatch.hrl new file mode 100644 index 0000000..4920304 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertMatch.hrl @@ -0,0 +1,3 @@ +-record(assert_match, { + details :: list(showtime@internal@common@test_result:reason_detail()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertNotEqual.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertNotEqual.hrl new file mode 100644 index 0000000..221c15f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_AssertNotEqual.hrl @@ -0,0 +1,3 @@ +-record(assert_not_equal, { + details :: list(showtime@internal@common@test_result:reason_detail()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErlangException.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErlangException.hrl new file mode 100644 index 0000000..9a31ba8 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErlangException.hrl @@ -0,0 +1,6 @@ +-record(erlang_exception, { + class :: showtime@internal@common@test_result:class(), + reason :: showtime@internal@common@test_result:reason(), + stacktrace :: showtime@internal@common@test_result:trace_list(), + output_buffer :: list(binary()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErrorInfo.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErrorInfo.hrl new file mode 100644 index 0000000..4e0244d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ErrorInfo.hrl @@ -0,0 +1,3 @@ +-record(error_info, { + error_info :: gleam@dict:dict(gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expected.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expected.hrl new file mode 100644 index 0000000..5e40ad3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expected.hrl @@ -0,0 +1 @@ +-record(expected, {value :: gleam@dynamic:dynamic_()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expression.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expression.hrl new file mode 100644 index 0000000..7aa0c35 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Expression.hrl @@ -0,0 +1 @@ +-record(expression, {expression :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_File.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_File.hrl new file mode 100644 index 0000000..1274b74 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_File.hrl @@ -0,0 +1 @@ +-record(file, {filename :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GenericException.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GenericException.hrl new file mode 100644 index 0000000..7c33d0d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GenericException.hrl @@ -0,0 +1 @@ +-record(generic_exception, {value :: gleam@dynamic:dynamic_()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamAssert.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamAssert.hrl new file mode 100644 index 0000000..095748c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamAssert.hrl @@ -0,0 +1 @@ +-record(gleam_assert, {value :: gleam@dynamic:dynamic_(), line_no :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamError.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamError.hrl new file mode 100644 index 0000000..68e6645 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_GleamError.hrl @@ -0,0 +1,3 @@ +-record(gleam_error, { + details :: showtime@internal@common@test_result:gleam_error_detail() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Ignored.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Ignored.hrl new file mode 100644 index 0000000..87b7e2f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Ignored.hrl @@ -0,0 +1 @@ +-record(ignored, {reason :: showtime@internal@common@test_result:ignore_reason()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_LetAssert.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_LetAssert.hrl new file mode 100644 index 0000000..5f3f60d --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_LetAssert.hrl @@ -0,0 +1,7 @@ +-record(let_assert, { + module :: binary(), + function :: binary(), + line_no :: integer(), + message :: binary(), + value :: gleam@dynamic:dynamic_() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Line.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Line.hrl new file mode 100644 index 0000000..9807df6 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Line.hrl @@ -0,0 +1 @@ +-record(line, {line_no :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Module.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Module.hrl new file mode 100644 index 0000000..8002c0c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Module.hrl @@ -0,0 +1 @@ +-record(module, {name :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Num.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Num.hrl new file mode 100644 index 0000000..c36efa3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Num.hrl @@ -0,0 +1 @@ +-record(num, {arity :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Pattern.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Pattern.hrl new file mode 100644 index 0000000..6aa9c84 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Pattern.hrl @@ -0,0 +1 @@ +-record(pattern, {pattern :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ReasonLine.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ReasonLine.hrl new file mode 100644 index 0000000..b7ad1ab --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_ReasonLine.hrl @@ -0,0 +1 @@ +-record(reason_line, {line_no :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TestFunctionReturn.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TestFunctionReturn.hrl new file mode 100644 index 0000000..b0bc294 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TestFunctionReturn.hrl @@ -0,0 +1,4 @@ +-record(test_function_return, { + value :: gleam@dynamic:dynamic_(), + output_buffer :: list(binary()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Trace.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Trace.hrl new file mode 100644 index 0000000..4cb007c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Trace.hrl @@ -0,0 +1,5 @@ +-record(trace, { + function :: binary(), + arity :: showtime@internal@common@test_result:arity_(), + extra_info :: list(showtime@internal@common@test_result:extra_info()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceList.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceList.hrl new file mode 100644 index 0000000..c1aa9c5 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceList.hrl @@ -0,0 +1,3 @@ +-record(trace_list, { + traces :: list(showtime@internal@common@test_result:trace()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceModule.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceModule.hrl new file mode 100644 index 0000000..595362f --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_TraceModule.hrl @@ -0,0 +1,6 @@ +-record(trace_module, { + module :: binary(), + function :: binary(), + arity :: showtime@internal@common@test_result:arity_(), + extra_info :: list(showtime@internal@common@test_result:extra_info()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Value.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Value.hrl new file mode 100644 index 0000000..3a4b0dd --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_result_Value.hrl @@ -0,0 +1 @@ +-record(value, {value :: gleam@dynamic:dynamic_()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_CompletedTestRun.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_CompletedTestRun.hrl new file mode 100644 index 0000000..927a0cf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_CompletedTestRun.hrl @@ -0,0 +1,6 @@ +-record(completed_test_run, { + test_function :: showtime@internal@common@test_suite:test_function(), + total_time :: integer(), + result :: {ok, showtime@internal@common@test_result:test_return()} | + {error, showtime@internal@common@test_result:exception()} +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTest.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTest.hrl new file mode 100644 index 0000000..13df1bf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTest.hrl @@ -0,0 +1,6 @@ +-record(end_test, { + test_module :: showtime@internal@common@test_suite:test_module(), + test_function :: showtime@internal@common@test_suite:test_function(), + result :: {ok, showtime@internal@common@test_result:test_return()} | + {error, showtime@internal@common@test_result:exception()} +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestRun.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestRun.hrl new file mode 100644 index 0000000..3f78991 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestRun.hrl @@ -0,0 +1 @@ +-record(end_test_run, {num_modules :: integer()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestSuite.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestSuite.hrl new file mode 100644 index 0000000..a7f37b3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_EndTestSuite.hrl @@ -0,0 +1,3 @@ +-record(end_test_suite, { + test_module :: showtime@internal@common@test_suite:test_module() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_OngoingTestRun.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_OngoingTestRun.hrl new file mode 100644 index 0000000..f52e5cc --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_OngoingTestRun.hrl @@ -0,0 +1,4 @@ +-record(ongoing_test_run, { + test_function :: showtime@internal@common@test_suite:test_function(), + started_at :: integer() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTest.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTest.hrl new file mode 100644 index 0000000..d532609 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTest.hrl @@ -0,0 +1,4 @@ +-record(start_test, { + test_module :: showtime@internal@common@test_suite:test_module(), + test_function :: showtime@internal@common@test_suite:test_function() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTestSuite.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTestSuite.hrl new file mode 100644 index 0000000..d5a03d3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_StartTestSuite.hrl @@ -0,0 +1,3 @@ +-record(start_test_suite, { + test_module :: showtime@internal@common@test_suite:test_module() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestFunction.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestFunction.hrl new file mode 100644 index 0000000..a783ba4 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestFunction.hrl @@ -0,0 +1 @@ +-record(test_function, {name :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestModule.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestModule.hrl new file mode 100644 index 0000000..ee9baaf --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestModule.hrl @@ -0,0 +1 @@ +-record(test_module, {name :: binary(), path :: gleam@option:option(binary())}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestSuite.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestSuite.hrl new file mode 100644 index 0000000..253a946 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@common@test_suite_TestSuite.hrl @@ -0,0 +1,4 @@ +-record(test_suite, { + module :: showtime@internal@common@test_suite:test_module(), + tests :: list(showtime@internal@common@test_suite:test_function()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeft.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeft.hrl new file mode 100644 index 0000000..ca52968 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeft.hrl @@ -0,0 +1,4 @@ +-record(align_left, { + content :: showtime@internal@reports@table:content(), + margin :: integer() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeftOverflow.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeftOverflow.hrl new file mode 100644 index 0000000..8d5a673 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignLeftOverflow.hrl @@ -0,0 +1,4 @@ +-record(align_left_overflow, { + content :: showtime@internal@reports@table:content(), + margin :: integer() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRight.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRight.hrl new file mode 100644 index 0000000..7f7a3f0 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRight.hrl @@ -0,0 +1,4 @@ +-record(align_right, { + content :: showtime@internal@reports@table:content(), + margin :: integer() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRightOverflow.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRightOverflow.hrl new file mode 100644 index 0000000..4fc4536 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_AlignRightOverflow.hrl @@ -0,0 +1,4 @@ +-record(align_right_overflow, { + content :: showtime@internal@reports@table:content(), + margin :: integer() +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Aligned.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Aligned.hrl new file mode 100644 index 0000000..2343dfd --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Aligned.hrl @@ -0,0 +1 @@ +-record(aligned, {content :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Content.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Content.hrl new file mode 100644 index 0000000..044891b --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Content.hrl @@ -0,0 +1 @@ +-record(content, {unstyled_text :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Separator.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Separator.hrl new file mode 100644 index 0000000..db3f822 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Separator.hrl @@ -0,0 +1 @@ +-record(separator, {char :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_StyledContent.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_StyledContent.hrl new file mode 100644 index 0000000..ed500df --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_StyledContent.hrl @@ -0,0 +1 @@ +-record(styled_content, {styled_text :: binary()}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Table.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Table.hrl new file mode 100644 index 0000000..5b41bb1 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@internal@reports@table_Table.hrl @@ -0,0 +1,4 @@ +-record(table, { + header :: gleam@option:option(binary()), + rows :: list(list(showtime@internal@reports@table:col())) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@meta_Meta.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@meta_Meta.hrl new file mode 100644 index 0000000..14184fb --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@meta_Meta.hrl @@ -0,0 +1 @@ +-record(meta, {description :: binary(), tags :: list(binary())}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Eq.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Eq.hrl new file mode 100644 index 0000000..6ebea34 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Eq.hrl @@ -0,0 +1,5 @@ +-record(eq, { + a :: any(), + b :: any(), + meta :: gleam@option:option(showtime@tests@meta:meta()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Fail.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Fail.hrl new file mode 100644 index 0000000..cf06a3c --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_Fail.hrl @@ -0,0 +1 @@ +-record(fail, {meta :: gleam@option:option(showtime@tests@meta:meta())}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsError.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsError.hrl new file mode 100644 index 0000000..e9cabf3 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsError.hrl @@ -0,0 +1,4 @@ +-record(is_error, { + a :: {ok, any()} | {error, any()}, + meta :: gleam@option:option(showtime@tests@meta:meta()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsOk.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsOk.hrl new file mode 100644 index 0000000..37c24ca --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_IsOk.hrl @@ -0,0 +1,4 @@ +-record(is_ok, { + a :: {ok, any()} | {error, any()}, + meta :: gleam@option:option(showtime@tests@meta:meta()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_NotEq.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_NotEq.hrl new file mode 100644 index 0000000..2a6bf48 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@should_NotEq.hrl @@ -0,0 +1,5 @@ +-record(not_eq, { + a :: any(), + b :: any(), + meta :: gleam@option:option(showtime@tests@meta:meta()) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_MetaShould.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_MetaShould.hrl new file mode 100644 index 0000000..a814a93 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_MetaShould.hrl @@ -0,0 +1,4 @@ +-record(meta_should, { + equal :: fun((any(), any()) -> nil), + not_equal :: fun((any(), any()) -> nil) +}). diff --git a/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_Test.hrl b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_Test.hrl new file mode 100644 index 0000000..e75a0b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/adglent/include/showtime@tests@test_Test.hrl @@ -0,0 +1,4 @@ +-record(test, { + meta :: showtime@tests@meta:meta(), + test_function :: fun(() -> nil) +}). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache Binary files differnew file mode 100644 index 0000000..de3d10c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache_meta Binary files differnew file mode 100644 index 0000000..29c7ca9 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.erl new file mode 100644 index 0000000..6ab21a2 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023.erl @@ -0,0 +1,21 @@ +-module(aoc2023). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec main() -> bitstring(). +main() -> + Trim = 8, + _assert_subject = gleam_stdlib:identity(<<"abcdefgh +abcdefgh"/utf8>>), + <<_:Trim/binary, "\n"/utf8, Rest/binary>> = case _assert_subject of + <<_:Trim/binary, "\n"/utf8, _/binary>> -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"aoc2023"/utf8>>, + function => <<"main"/utf8>>, + line => 9}) + end, + gleam@io:debug(Rest). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023@@main.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023@@main.erl new file mode 100644 index 0000000..ad291f1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023@@main.erl @@ -0,0 +1,35 @@ +-module('aoc2023@@main'). + +-export([run/1]). + +run(Module) -> + io:setopts(standard_io, [binary, {encoding, utf8}]), + io:setopts(standard_error, [{encoding, utf8}]), + try + {ok, _} = application:ensure_all_started('aoc2023'), + erlang:process_flag(trap_exit, false), + Module:main(), + erlang:halt(0) + catch + Class:Reason:StackTrace -> + print_error(Class, Reason, StackTrace), + erlang:halt(127, [{flush, true}]) + end. + +print_error(Class, Reason, StackTrace) -> + E = erl_error:format_exception( + 1, Class, Reason, StackTrace, fun stack_filter/3, + fun print_stack_frame/2, unicode + ), + io:put_chars(E). + +stack_filter(Module, _F, _A) -> + case Module of + ?MODULE -> true; + erl_eval -> true; + init -> true; + _ -> false + end. + +print_stack_frame(Term, I) -> + io_lib:format("~." ++ integer_to_list(I) ++ "tP", [Term, 50]).
\ No newline at end of file diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache Binary files differnew file mode 100644 index 0000000..105c4ea --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache_meta Binary files differnew file mode 100644 index 0000000..6612dba --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.erl new file mode 100644 index 0000000..3a2a263 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/aoc2023_test.erl @@ -0,0 +1,8 @@ +-module(aoc2023_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec main() -> nil. +main() -> + showtime:main(). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache Binary files differnew file mode 100644 index 0000000..72b188e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache_meta Binary files differnew file mode 100644 index 0000000..eba5ba6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.erl new file mode 100644 index 0000000..ece7e8d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@day10_test.erl @@ -0,0 +1,52 @@ +-module(day10@day10_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, <<"7-F7- +.FJ|7 +SJLL7 +|F--J +LJ.LJ"/utf8>>, <<"8"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, <<"7-F7- +.FJ|7 +SJLL7 +|F--J +LJ.LJ"/utf8>>, <<"8"/utf8>>}], + fun(Example) -> _pipe@1 = day10@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"........... +.S-------7. +.|F-----7|. +.||OOOOO||. +.||OOOOO||. +.|L-7OF-J|. +.|II|O|II|. +.L--JOL--J. +.....O....."/utf8>>, + <<"4"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"........... +.S-------7. +.|F-----7|. +.||OOOOO||. +.||OOOOO||. +.|L-7OF-J|. +.|II|O|II|. +.L--JOL--J. +.....O....."/utf8>>, + <<"4"/utf8>>}], + fun(Example) -> _pipe@1 = day10@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache Binary files differnew file mode 100644 index 0000000..633f740 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache_meta Binary files differnew file mode 100644 index 0000000..5c3181a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.erl new file mode 100644 index 0000000..f6178a2 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day10@solve.erl @@ -0,0 +1,340 @@ +-module(day10@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([posn/0]). + +-type posn() :: {posn, integer(), integer()}. + +-spec add_posns(posn(), posn()) -> posn(). +add_posns(P1, P2) -> + {posn, + erlang:element(2, P1) + erlang:element(2, P2), + erlang:element(3, P1) + erlang:element(3, P2)}. + +-spec make_grid(binary()) -> gleam@dict:dict(posn(), binary()). +make_grid(Input) -> + _pipe = (gleam@list:index_map( + gleam@string:split(Input, <<"\n"/utf8>>), + fun(R, Row) -> + gleam@list:index_map( + gleam@string:to_graphemes(Row), + fun(C, Col) -> {{posn, R, C}, Col} end + ) + end + )), + _pipe@1 = gleam@list:flatten(_pipe), + gleam@dict:from_list(_pipe@1). + +-spec count_crossings( + posn(), + gleam@set:set(posn()), + gleam@dict:dict(posn(), binary()), + integer(), + binary() +) -> integer(). +count_crossings(P, Loop, Grid, Acc, Corner) -> + Maybe_cell = gleam@dict:get(Grid, P), + gleam@bool:guard( + Maybe_cell =:= {error, nil}, + Acc, + fun() -> + {ok, Cell} = case Maybe_cell of + {ok, _} -> Maybe_cell; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"count_crossings"/utf8>>, + line => 125}) + end, + Next = add_posns(P, {posn, 0, 1}), + case gleam@set:contains(Loop, P) of + false -> + count_crossings(Next, Loop, Grid, Acc, Corner); + + true -> + case {Corner, Cell} of + {_, <<"|"/utf8>>} -> + count_crossings(Next, Loop, Grid, Acc + 1, Corner); + + {_, <<"F"/utf8>>} -> + count_crossings(Next, Loop, Grid, Acc, Cell); + + {_, <<"L"/utf8>>} -> + count_crossings(Next, Loop, Grid, Acc, Cell); + + {<<"F"/utf8>>, <<"J"/utf8>>} -> + count_crossings( + Next, + Loop, + Grid, + Acc + 1, + <<""/utf8>> + ); + + {<<"L"/utf8>>, <<"7"/utf8>>} -> + count_crossings( + Next, + Loop, + Grid, + Acc + 1, + <<""/utf8>> + ); + + {<<"F"/utf8>>, <<"7"/utf8>>} -> + count_crossings(Next, Loop, Grid, Acc, <<""/utf8>>); + + {<<"L"/utf8>>, <<"J"/utf8>>} -> + count_crossings(Next, Loop, Grid, Acc, <<""/utf8>>); + + {_, _} -> + count_crossings(Next, Loop, Grid, Acc, Corner) + end + end + end + ). + +-spec trace_ray( + posn(), + gleam@set:set(posn()), + gleam@dict:dict(posn(), binary()) +) -> boolean(). +trace_ray(P, Loop, Grid) -> + gleam@bool:guard( + gleam@set:contains(Loop, P), + false, + fun() -> + gleam@int:is_odd(count_crossings(P, Loop, Grid, 0, <<""/utf8>>)) + end + ). + +-spec pipe_neighbors(binary()) -> list(posn()). +pipe_neighbors(Pipe) -> + case Pipe of + <<"|"/utf8>> -> + [{posn, -1, 0}, {posn, 1, 0}]; + + <<"-"/utf8>> -> + [{posn, 0, 1}, {posn, 0, -1}]; + + <<"L"/utf8>> -> + [{posn, -1, 0}, {posn, 0, 1}]; + + <<"F"/utf8>> -> + [{posn, 1, 0}, {posn, 0, 1}]; + + <<"7"/utf8>> -> + [{posn, 1, 0}, {posn, 0, -1}]; + + <<"J"/utf8>> -> + [{posn, -1, 0}, {posn, 0, -1}]; + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"bad pipe"/utf8>>, + module => <<"day10/solve"/utf8>>, + function => <<"pipe_neighbors"/utf8>>, + line => 44}) + end. + +-spec to_next_pipe(posn(), gleam@dict:dict(posn(), binary()), list(posn())) -> list(posn()). +to_next_pipe(Current, Grid, Acc) -> + [Prev | _] = case Acc of + [_ | _] -> Acc; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"to_next_pipe"/utf8>>, + line => 76}) + end, + _assert_subject = gleam@dict:get(Grid, Current), + {ok, Pipe} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day10/solve"/utf8>>, + function => <<"to_next_pipe"/utf8>>, + line => 77}) + end, + gleam@bool:guard( + Pipe =:= <<"S"/utf8>>, + [Current | Acc], + fun() -> + _assert_subject@1 = begin + _pipe = Pipe, + _pipe@1 = pipe_neighbors(_pipe), + gleam@list:filter_map( + _pipe@1, + fun(P) -> case add_posns(P, Current) of + Neighbor when Neighbor =:= Prev -> + {error, nil}; + + Neighbor@1 -> + {ok, Neighbor@1} + end end + ) + end, + [Next] = case _assert_subject@1 of + [_] -> _assert_subject@1; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day10/solve"/utf8>>, + function => <<"to_next_pipe"/utf8>>, + line => 79}) + end, + to_next_pipe(Next, Grid, [Current | Acc]) + end + ). + +-spec valid_start_direction(gleam@dict:dict(posn(), binary()), posn()) -> posn(). +valid_start_direction(Grid, S) -> + _assert_subject = (gleam@list:filter_map( + [{{posn, -1, 0}, [<<"|"/utf8>>, <<"7"/utf8>>, <<"F"/utf8>>]}, + {{posn, 1, 0}, [<<"|"/utf8>>, <<"J"/utf8>>, <<"L"/utf8>>]}, + {{posn, 0, 1}, [<<"-"/utf8>>, <<"J"/utf8>>, <<"7"/utf8>>]}, + {{posn, 0, -1}, [<<"-"/utf8>>, <<"F"/utf8>>, <<"L"/utf8>>]}], + fun(D) -> + {Delta, Valids} = D, + Neighbor = add_posns(S, Delta), + case gleam@dict:get(Grid, Neighbor) of + {ok, Pipe} -> + case gleam@list:contains(Valids, Pipe) of + true -> + {ok, Neighbor}; + + false -> + {error, nil} + end; + + {error, _} -> + {error, nil} + end + end + )), + [Dir | _] = case _assert_subject of + [_ | _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"valid_start_direction"/utf8>>, + line => 59}) + end, + Dir. + +-spec part1(binary()) -> binary(). +part1(Input) -> + Grid = begin + _pipe = Input, + make_grid(_pipe) + end, + _assert_subject = begin + _pipe@1 = Grid, + _pipe@2 = gleam@dict:filter( + _pipe@1, + fun(_, V) -> V =:= <<"S"/utf8>> end + ), + _pipe@3 = gleam@dict:keys(_pipe@2), + gleam@list:first(_pipe@3) + end, + {ok, S} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 97}) + end, + _pipe@4 = Grid, + _pipe@5 = valid_start_direction(_pipe@4, S), + _pipe@6 = to_next_pipe(_pipe@5, Grid, [S]), + _pipe@7 = gleam@list:length(_pipe@6), + _pipe@8 = (fun(I) -> ((I - 1) div 2) end)(_pipe@7), + gleam@string:inspect(_pipe@8). + +-spec part2(binary()) -> binary(). +part2(Input) -> + Grid = begin + _pipe = Input, + make_grid(_pipe) + end, + _assert_subject = begin + _pipe@1 = Grid, + _pipe@2 = gleam@dict:filter( + _pipe@1, + fun(_, V) -> V =:= <<"S"/utf8>> end + ), + _pipe@3 = gleam@dict:keys(_pipe@2), + gleam@list:first(_pipe@3) + end, + {ok, S} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 145}) + end, + Loop_pipes = begin + _pipe@4 = Grid, + _pipe@5 = valid_start_direction(_pipe@4, S), + _pipe@6 = to_next_pipe(_pipe@5, Grid, [S]), + gleam@set:from_list(_pipe@6) + end, + _pipe@7 = Grid, + _pipe@8 = gleam@dict:keys(_pipe@7), + _pipe@9 = gleam@list:filter( + _pipe@8, + fun(_capture) -> trace_ray(_capture, Loop_pipes, Grid) end + ), + _pipe@10 = gleam@list:length(_pipe@9), + gleam@string:inspect(_pipe@10). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day10/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 165}) + end, + _assert_subject@1 = adglent:get_input(<<"10"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day10/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 166}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache Binary files differnew file mode 100644 index 0000000..508a46b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache_meta Binary files differnew file mode 100644 index 0000000..e03372f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.erl new file mode 100644 index 0000000..01b02bc --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@day11_test.erl @@ -0,0 +1,68 @@ +-module(day11@day11_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#....."/utf8>>, + <<"374"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#....."/utf8>>, + <<"374"/utf8>>}], + fun(Example) -> _pipe@1 = day11@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#....."/utf8>>, + <<"8410"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#....."/utf8>>, + <<"8410"/utf8>>}], + fun(Example) -> _pipe@1 = day11@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache Binary files differnew file mode 100644 index 0000000..64f1e54 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache_meta Binary files differnew file mode 100644 index 0000000..0ff3073 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.erl new file mode 100644 index 0000000..344613f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day11@solve.erl @@ -0,0 +1,130 @@ +-module(day11@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([posn/0]). + +-type posn() :: {posn, integer(), integer()}. + +-spec find_empty(list(list(binary()))) -> list(integer()). +find_empty(Grid) -> + gleam@list:index_fold( + Grid, + [], + fun(Acc, Row, R) -> case gleam@list:unique(Row) of + [<<"."/utf8>>] -> + [R | Acc]; + + _ -> + Acc + end end + ). + +-spec count_prior_empty_ranks(integer(), list(integer())) -> integer(). +count_prior_empty_ranks(Rank, Empty_ranks) -> + _pipe = Empty_ranks, + _pipe@1 = gleam@list:drop_while(_pipe, fun(R_empty) -> R_empty > Rank end), + gleam@list:length(_pipe@1). + +-spec parse_with_expansion(binary(), integer()) -> list(posn()). +parse_with_expansion(Input, Expansion) -> + Add = Expansion - 1, + Grid = begin + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + gleam@list:map(_pipe@1, fun gleam@string:to_graphemes/1) + end, + Empty_row_list = find_empty(Grid), + Empty_col_list = find_empty(gleam@list:transpose(Grid)), + _pipe@2 = (gleam@list:index_map( + Grid, + fun(R, Row) -> + gleam@list:index_fold( + Row, + [], + fun(Acc, Cell, C) -> + P = {posn, R, C}, + Empty_r = count_prior_empty_ranks(R, Empty_row_list), + Empty_c = count_prior_empty_ranks(C, Empty_col_list), + case Cell of + <<"#"/utf8>> -> + [{posn, + erlang:element(2, P) + (Empty_r * Add), + erlang:element(3, P) + (Empty_c * Add)} | + Acc]; + + _ -> + Acc + end + end + ) + end + )), + gleam@list:flatten(_pipe@2). + +-spec all_distances(list(posn())) -> integer(). +all_distances(Stars) -> + gleam@list:fold( + gleam@list:combination_pairs(Stars), + 0, + fun(Acc, Pair) -> + {S1, S2} = Pair, + (Acc + gleam@int:absolute_value( + erlang:element(2, S1) - erlang:element(2, S2) + )) + + gleam@int:absolute_value( + erlang:element(3, S1) - erlang:element(3, S2) + ) + end + ). + +-spec find_distances(binary(), integer()) -> binary(). +find_distances(Input, Expand_by) -> + _pipe = Input, + _pipe@1 = parse_with_expansion(_pipe, Expand_by), + _pipe@2 = all_distances(_pipe@1), + gleam@string:inspect(_pipe@2). + +-spec part1(binary()) -> binary(). +part1(Input) -> + find_distances(Input, 2). + +-spec part2(binary()) -> binary(). +part2(Input) -> + find_distances(Input, 1000000). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day11/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 72}) + end, + _assert_subject@1 = adglent:get_input(<<"11"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day11/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 73}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache Binary files differnew file mode 100644 index 0000000..849fca3 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache_meta Binary files differnew file mode 100644 index 0000000..51c4010 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.erl new file mode 100644 index 0000000..d4daa75 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@day12_test.erl @@ -0,0 +1,38 @@ +-module(day12@day12_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"???.### 1,1,3 +.??..??...?##. 1,1,3 +?#?#?#?#?#?#?#? 1,3,1,6 +????.#...#... 4,1,1 +????.######..#####. 1,6,5 +?###???????? 3,2,1"/utf8>>, + <<"21"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"???.### 1,1,3 +.??..??...?##. 1,1,3 +?#?#?#?#?#?#?#? 1,3,1,6 +????.#...#... 4,1,1 +????.######..#####. 1,6,5 +?###???????? 3,2,1"/utf8>>, + <<"21"/utf8>>}], + fun(Example) -> _pipe@1 = day12@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [], + fun(Example) -> _pipe@1 = day12@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache Binary files differnew file mode 100644 index 0000000..f0476d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache_meta Binary files differnew file mode 100644 index 0000000..d8f9228 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.erl new file mode 100644 index 0000000..1331abe --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day12@solve.erl @@ -0,0 +1,145 @@ +-module(day12@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). + +-spec parse_folds(binary(), integer()) -> list({binary(), list(integer())}). +parse_folds(Input, Folds) -> + Records = gleam@string:split(Input, <<"\n"/utf8>>), + gleam@list:map( + Records, + fun(Record) -> + _assert_subject = gleam@string:split_once(Record, <<" "/utf8>>), + {ok, {Template, Sets_str}} = case _assert_subject of + {ok, {_, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day12/solve"/utf8>>, + function => <<"parse_folds"/utf8>>, + line => 15}) + end, + Template@1 = begin + _pipe = Template, + _pipe@1 = gleam@list:repeat(_pipe, Folds), + _pipe@2 = gleam@list:intersperse(_pipe@1, <<"?"/utf8>>), + gleam@string:concat(_pipe@2) + end, + Sets = begin + _pipe@3 = Sets_str, + _pipe@4 = gleam@string:split(_pipe@3, <<","/utf8>>), + _pipe@5 = gleam@list:map(_pipe@4, fun gleam@int:parse/1), + _pipe@6 = gleam@result:values(_pipe@5), + _pipe@7 = gleam@list:repeat(_pipe@6, Folds), + gleam@list:flatten(_pipe@7) + end, + {Template@1, Sets} + end + ). + +-spec do_count( + binary(), + list(integer()), + integer(), + boolean(), + utilities@memo:cache({binary(), list(integer()), integer(), boolean()}, integer()) +) -> integer(). +do_count(Template, Groups, Left, Gap, Cache) -> + utilities@memo:memoize( + Cache, + {Template, Groups, Left, Gap}, + fun() -> case {Template, Groups, Left, Gap} of + {<<""/utf8>>, [], 0, _} -> + 1; + + {<<"?"/utf8, T_rest/binary>>, [G | G_rest], 0, false} -> + do_count(T_rest, G_rest, G - 1, G =:= 1, Cache) + do_count( + T_rest, + Groups, + 0, + false, + Cache + ); + + {<<"?"/utf8, T_rest@1/binary>>, [], 0, false} -> + do_count(T_rest@1, Groups, 0, false, Cache); + + {<<"?"/utf8, T_rest@1/binary>>, _, 0, true} -> + do_count(T_rest@1, Groups, 0, false, Cache); + + {<<"."/utf8, T_rest@1/binary>>, _, 0, _} -> + do_count(T_rest@1, Groups, 0, false, Cache); + + {<<"#"/utf8, T_rest@2/binary>>, [G@1 | G_rest@1], 0, false} -> + do_count(T_rest@2, G_rest@1, G@1 - 1, G@1 =:= 1, Cache); + + {<<"?"/utf8, T_rest@3/binary>>, Gs, L, false} -> + do_count(T_rest@3, Gs, L - 1, L =:= 1, Cache); + + {<<"#"/utf8, T_rest@3/binary>>, Gs, L, false} -> + do_count(T_rest@3, Gs, L - 1, L =:= 1, Cache); + + {_, _, _, _} -> + 0 + end end + ). + +-spec count_solutions(integer(), {binary(), list(integer())}) -> integer(). +count_solutions(Acc, Condition) -> + utilities@memo:create( + fun(Cache) -> + {Template, Groups} = Condition, + Acc + do_count(Template, Groups, 0, false, Cache) + end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _pipe = Input, + _pipe@1 = parse_folds(_pipe, 1), + _pipe@2 = gleam@list:fold(_pipe@1, 0, fun count_solutions/2), + gleam@string:inspect(_pipe@2). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _pipe = Input, + _pipe@1 = parse_folds(_pipe, 5), + _pipe@2 = gleam@list:fold(_pipe@1, 0, fun count_solutions/2), + gleam@string:inspect(_pipe@2). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day12/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 78}) + end, + _assert_subject@1 = adglent:get_input(<<"12"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day12/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 79}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache Binary files differnew file mode 100644 index 0000000..5ea210b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache_meta Binary files differnew file mode 100644 index 0000000..034e2de --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.erl new file mode 100644 index 0000000..08f1bec --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@day13_test.erl @@ -0,0 +1,88 @@ +-module(day13@day13_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"/utf8>>, + <<"405"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"/utf8>>, + <<"405"/utf8>>}], + fun(Example) -> _pipe@1 = day13@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"/utf8>>, + <<"400"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"/utf8>>, + <<"400"/utf8>>}], + fun(Example) -> _pipe@1 = day13@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache Binary files differnew file mode 100644 index 0000000..0d31dbe --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache_meta Binary files differnew file mode 100644 index 0000000..ee31fa5 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.erl new file mode 100644 index 0000000..ffe8959 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day13@solve.erl @@ -0,0 +1,149 @@ +-module(day13@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([symmetry_type/0]). + +-type symmetry_type() :: {horizontal, integer()} | {vertical, integer()}. + +-spec do_is_symmetric(list(list(BVU)), list(list(BVU)), integer()) -> {ok, + integer()} | + {error, nil}. +do_is_symmetric(Left, Right, Errors) -> + gleam@bool:guard( + gleam@list:is_empty(Right), + {error, nil}, + fun() -> + [H | T] = case Right of + [_ | _] -> Right; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day13/solve"/utf8>>, + function => <<"do_is_symmetric"/utf8>>, + line => 23}) + end, + Found_errors = begin + _pipe = gleam@list:zip( + gleam@list:flatten(Left), + gleam@list:flatten(Right) + ), + _pipe@1 = gleam@list:filter( + _pipe, + fun(Tup) -> + erlang:element(2, Tup) /= erlang:element(1, Tup) + end + ), + gleam@list:length(_pipe@1) + end, + case Found_errors =:= Errors of + true -> + {ok, gleam@list:length(Left)}; + + false -> + do_is_symmetric([H | Left], T, Errors) + end + end + ). + +-spec is_symmetric(list(list(any())), integer()) -> {ok, integer()} | + {error, nil}. +is_symmetric(Xss, Errs) -> + [Left | Right] = case Xss of + [_ | _] -> Xss; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day13/solve"/utf8>>, + function => <<"is_symmetric"/utf8>>, + line => 13}) + end, + do_is_symmetric([Left], Right, Errs). + +-spec get_symmetry_type(list(list(binary())), integer()) -> symmetry_type(). +get_symmetry_type(Xss, Errors) -> + case is_symmetric(Xss, Errors) of + {ok, N} -> + {horizontal, N}; + + _ -> + _assert_subject = is_symmetric(gleam@list:transpose(Xss), Errors), + {ok, N@1} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day13/solve"/utf8>>, + function => <<"get_symmetry_type"/utf8>>, + line => 38}) + end, + {vertical, N@1} + end. + +-spec summarize_notes(list(symmetry_type())) -> integer(). +summarize_notes(Symmetries) -> + gleam@list:fold(Symmetries, 0, fun(Acc, Note) -> Acc + case Note of + {horizontal, N} -> + 100 * N; + + {vertical, N@1} -> + N@1 + end end). + +-spec solve(binary(), integer()) -> binary(). +solve(Input, Errors) -> + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n\n"/utf8>>), + _pipe@5 = gleam@list:map(_pipe@1, fun(Strs) -> _pipe@2 = Strs, + _pipe@3 = gleam@string:split(_pipe@2, <<"\n"/utf8>>), + _pipe@4 = gleam@list:map(_pipe@3, fun gleam@string:to_graphemes/1), + get_symmetry_type(_pipe@4, Errors) end), + _pipe@6 = summarize_notes(_pipe@5), + gleam@string:inspect(_pipe@6). + +-spec part1(binary()) -> binary(). +part1(Input) -> + solve(Input, 0). + +-spec part2(binary()) -> binary(). +part2(Input) -> + solve(Input, 1). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day13/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 75}) + end, + _assert_subject@1 = adglent:get_input(<<"13"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day13/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 76}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache Binary files differnew file mode 100644 index 0000000..cb5c2df --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache_meta Binary files differnew file mode 100644 index 0000000..af65466 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.erl new file mode 100644 index 0000000..fd81f21 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@day14_test.erl @@ -0,0 +1,68 @@ +-module(day14@day14_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#...."/utf8>>, + <<"136"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#...."/utf8>>, + <<"136"/utf8>>}], + fun(Example) -> _pipe@1 = day14@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#...."/utf8>>, + <<"64"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#...."/utf8>>, + <<"64"/utf8>>}], + fun(Example) -> _pipe@1 = day14@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache Binary files differnew file mode 100644 index 0000000..2bceb68 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache_meta Binary files differnew file mode 100644 index 0000000..f6a8981 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.erl new file mode 100644 index 0000000..11e3202 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day14@solve.erl @@ -0,0 +1,149 @@ +-module(day14@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). + +-spec parse(binary()) -> list(list(binary())). +parse(Input) -> + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun gleam@string:to_graphemes/1), + gleam@list:transpose(_pipe@2). + +-spec roll_boulders(list(binary())) -> list(binary()). +roll_boulders(Strs) -> + _pipe = (gleam@list:map( + gleam@list:chunk( + Strs, + fun(C) -> (C =:= <<"O"/utf8>>) orelse (C =:= <<"."/utf8>>) end + ), + fun(Chunks) -> + gleam@list:sort( + Chunks, + gleam@order:reverse(fun gleam@string:compare/2) + ) + end + )), + gleam@list:flatten(_pipe). + +-spec score(list(list(binary()))) -> integer(). +score(Matrix) -> + gleam@list:fold( + Matrix, + 0, + fun(Acc, Col) -> + Acc + (gleam@list:index_fold( + gleam@list:reverse(Col), + 0, + fun(Col_acc, Char, N) -> case Char of + <<"O"/utf8>> -> + (Col_acc + N) + 1; + + _ -> + Col_acc + end end + )) + end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _pipe = Input, + _pipe@1 = parse(_pipe), + _pipe@2 = gleam@list:map(_pipe@1, fun roll_boulders/1), + _pipe@3 = score(_pipe@2), + gleam@string:inspect(_pipe@3). + +-spec rotate(list(list(BEG))) -> list(list(BEG)). +rotate(Matrix) -> + _pipe = Matrix, + _pipe@1 = gleam@list:map(_pipe, fun gleam@list:reverse/1), + gleam@list:transpose(_pipe@1). + +-spec spin(list(list(binary()))) -> list(list(binary())). +spin(Matrix) -> + gleam@list:fold(gleam@list:range(1, 4), Matrix, fun(Acc, _) -> _pipe = Acc, + _pipe@1 = gleam@list:map(_pipe, fun roll_boulders/1), + rotate(_pipe@1) end). + +-spec check_if_seen( + list(list(binary())), + gleam@dict:dict(list(list(binary())), integer()), + integer() +) -> integer(). +check_if_seen(Matrix, Cache, Count) -> + case gleam@dict:get(Cache, Matrix) of + {error, nil} -> + check_if_seen( + spin(Matrix), + gleam@dict:insert(Cache, Matrix, Count), + Count - 1 + ); + + {ok, N} -> + _assert_subject = gleam@int:modulo(Count, N - Count), + {ok, Extra} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day14/solve"/utf8>>, + function => <<"check_if_seen"/utf8>>, + line => 67}) + end, + _pipe = gleam@list:fold( + gleam@list:range(1, Extra), + Matrix, + fun(Acc, _) -> spin(Acc) end + ), + score(_pipe) + end. + +-spec spin_cycle(list(list(binary()))) -> integer(). +spin_cycle(Matrix) -> + Cache = gleam@dict:new(), + check_if_seen(Matrix, Cache, 1000000000). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _pipe = Input, + _pipe@1 = parse(_pipe), + _pipe@2 = spin_cycle(_pipe@1), + gleam@string:inspect(_pipe@2). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day14/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 82}) + end, + _assert_subject@1 = adglent:get_input(<<"14"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day14/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 83}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache Binary files differnew file mode 100644 index 0000000..ebef31b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache_meta Binary files differnew file mode 100644 index 0000000..2b2eed1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.erl new file mode 100644 index 0000000..ad6d957 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@day15_test.erl @@ -0,0 +1,32 @@ +-module(day15@day15_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7"/utf8>>, + <<"1320"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7"/utf8>>, + <<"1320"/utf8>>}], + fun(Example) -> _pipe@1 = day15@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7"/utf8>>, + <<"145"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7"/utf8>>, + <<"145"/utf8>>}], + fun(Example) -> _pipe@1 = day15@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache Binary files differnew file mode 100644 index 0000000..5f19cbb --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache_meta Binary files differnew file mode 100644 index 0000000..9fc44a6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.erl new file mode 100644 index 0000000..c817452 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day15@solve.erl @@ -0,0 +1,177 @@ +-module(day15@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([instruction/0]). + +-type instruction() :: {remove, binary()} | {insert, binary(), integer()}. + +-spec split(binary()) -> list(binary()). +split(Input) -> + _pipe = Input, + gleam@string:split(_pipe, <<","/utf8>>). + +-spec hash_algorithm(binary()) -> integer(). +hash_algorithm(Str) -> + Codepoints = begin + _pipe = Str, + _pipe@1 = gleam@string:to_utf_codepoints(_pipe), + gleam@list:map(_pipe@1, fun gleam@string:utf_codepoint_to_int/1) + end, + gleam@list:fold( + Codepoints, + 0, + fun(Acc, C) -> + _assert_subject = gleam@int:modulo((Acc + C) * 17, 256), + {ok, Acc@1} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day15/solve"/utf8>>, + function => <<"hash_algorithm"/utf8>>, + line => 20}) + end, + Acc@1 + end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _pipe = Input, + _pipe@1 = split(_pipe), + _pipe@2 = gleam@list:fold( + _pipe@1, + 0, + fun(Acc, Str) -> Acc + hash_algorithm(Str) end + ), + gleam@string:inspect(_pipe@2). + +-spec read_instruction(binary()) -> instruction(). +read_instruction(Str) -> + case gleam@string:split(Str, <<"="/utf8>>) of + [Label, Focal_str] -> + _assert_subject = gleam@int:parse(Focal_str), + {ok, Focal} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day15/solve"/utf8>>, + function => <<"read_instruction"/utf8>>, + line => 39}) + end, + {insert, Label, Focal}; + + _ -> + {remove, gleam@string:drop_right(Str, 1)} + end. + +-spec remove_lens(gleam@dict:dict(integer(), list({binary(), RCB})), binary()) -> gleam@dict:dict(integer(), list({binary(), + RCB})). +remove_lens(Boxes, Label) -> + gleam@dict:update(Boxes, hash_algorithm(Label), fun(V) -> case V of + {some, Lenses} -> + case gleam@list:key_pop(Lenses, Label) of + {ok, {_, Updated}} -> + Updated; + + {error, nil} -> + Lenses + end; + + none -> + [] + end end). + +-spec insert_lens( + gleam@dict:dict(integer(), list({binary(), RAT})), + binary(), + RAT +) -> gleam@dict:dict(integer(), list({binary(), RAT})). +insert_lens(Boxes, Label, Focal) -> + gleam@dict:update(Boxes, hash_algorithm(Label), fun(V) -> case V of + {some, Lenses} -> + gleam@list:key_set(Lenses, Label, Focal); + + none -> + [{Label, Focal}] + end end). + +-spec parse_instructions(list(binary())) -> gleam@dict:dict(integer(), list({binary(), + integer()})). +parse_instructions(Insts) -> + gleam@list:fold( + Insts, + gleam@dict:new(), + fun(Acc, Inst) -> case read_instruction(Inst) of + {remove, Label} -> + remove_lens(Acc, Label); + + {insert, Label@1, Focal} -> + insert_lens(Acc, Label@1, Focal) + end end + ). + +-spec focusing_power(gleam@dict:dict(integer(), list({binary(), integer()}))) -> integer(). +focusing_power(Boxes) -> + gleam@dict:fold( + Boxes, + 0, + fun(Acc, K, V) -> + Box_acc = (gleam@list:index_fold( + V, + 0, + fun(Acc@1, Lens, I) -> + Acc@1 + (erlang:element(2, Lens) * (I + 1)) + end + )), + Acc + ((K + 1) * Box_acc) + end + ). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _pipe = Input, + _pipe@1 = split(_pipe), + _pipe@2 = parse_instructions(_pipe@1), + _pipe@3 = focusing_power(_pipe@2), + gleam@string:inspect(_pipe@3). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day15/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 92}) + end, + _assert_subject@1 = adglent:get_input(<<"15"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day15/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 93}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache Binary files differnew file mode 100644 index 0000000..a8d21d6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache_meta Binary files differnew file mode 100644 index 0000000..7defae5 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.erl new file mode 100644 index 0000000..71bb64d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@day16_test.erl @@ -0,0 +1,68 @@ +-module(day16@day16_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<".|...\\.... +|.-.\\..... +.....|-... +........|. +.......... +.........\\ +..../.\\\\.. +.-.-/..|.. +.|....-|.\\ +..//.|...."/utf8>>, + 46}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<".|...\\.... +|.-.\\..... +.....|-... +........|. +.......... +.........\\ +..../.\\\\.. +.-.-/..|.. +.|....-|.\\ +..//.|...."/utf8>>, + 46}], + fun(Example) -> _pipe@1 = day16@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<".|...\\.... +|.-.\\..... +.....|-... +........|. +.......... +.........\\ +..../.\\\\.. +.-.-/..|.. +.|....-|.\\ +..//.|...."/utf8>>, + 51}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<".|...\\.... +|.-.\\..... +.....|-... +........|. +.......... +.........\\ +..../.\\\\.. +.-.-/..|.. +.|....-|.\\ +..//.|...."/utf8>>, + 51}], + fun(Example) -> _pipe@1 = day16@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache Binary files differnew file mode 100644 index 0000000..35182e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache_meta Binary files differnew file mode 100644 index 0000000..70fdb71 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.erl new file mode 100644 index 0000000..9e8b9b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day16@solve.erl @@ -0,0 +1,253 @@ +-module(day16@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([direction/0, light/0]). + +-type direction() :: up | right | down | left. + +-type light() :: {light, utilities@array2d:posn(), direction()}. + +-spec move(light()) -> light(). +move(L) -> + {light, P, Dir} = L, + case Dir of + up -> + erlang:setelement( + 2, + L, + erlang:setelement(2, P, erlang:element(2, P) - 1) + ); + + down -> + erlang:setelement( + 2, + L, + erlang:setelement(2, P, erlang:element(2, P) + 1) + ); + + left -> + erlang:setelement( + 2, + L, + erlang:setelement(3, P, erlang:element(3, P) - 1) + ); + + right -> + erlang:setelement( + 2, + L, + erlang:setelement(3, P, erlang:element(3, P) + 1) + ) + end. + +-spec transform(light(), {ok, binary()} | {error, nil}) -> list(light()). +transform(L, Cell) -> + gleam@bool:guard( + gleam@result:is_error(Cell), + [], + fun() -> + {ok, C} = case Cell of + {ok, _} -> Cell; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day16/solve"/utf8>>, + function => <<"transform"/utf8>>, + line => 33}) + end, + {light, P, Dir} = L, + case {Dir, C} of + {_, <<"."/utf8>>} -> + [L]; + + {up, <<"|"/utf8>>} -> + [L]; + + {down, <<"|"/utf8>>} -> + [L]; + + {left, <<"-"/utf8>>} -> + [L]; + + {right, <<"-"/utf8>>} -> + [L]; + + {left, <<"/"/utf8>>} -> + [{light, P, down}]; + + {down, <<"/"/utf8>>} -> + [{light, P, left}]; + + {right, <<"/"/utf8>>} -> + [{light, P, up}]; + + {up, <<"/"/utf8>>} -> + [{light, P, right}]; + + {left, <<"\\"/utf8>>} -> + [{light, P, up}]; + + {up, <<"\\"/utf8>>} -> + [{light, P, left}]; + + {right, <<"\\"/utf8>>} -> + [{light, P, down}]; + + {down, <<"\\"/utf8>>} -> + [{light, P, right}]; + + {left, <<"|"/utf8>>} -> + [{light, P, up}, {light, P, down}]; + + {right, <<"|"/utf8>>} -> + [{light, P, up}, {light, P, down}]; + + {up, <<"-"/utf8>>} -> + [{light, P, left}, {light, P, right}]; + + {down, <<"-"/utf8>>} -> + [{light, P, left}, {light, P, right}]; + + {_, _} -> + erlang:error(#{gleam_error => panic, + message => <<"unrecognized cell type"/utf8>>, + module => <<"day16/solve"/utf8>>, + function => <<"transform"/utf8>>, + line => 50}) + end + end + ). + +-spec energize( + list(light()), + gleam@set:set(light()), + gleam@dict:dict(utilities@array2d:posn(), binary()) +) -> integer(). +energize(Lights, Visited, Grid) -> + Next_positions = begin + _pipe = Lights, + _pipe@1 = gleam@list:flat_map( + _pipe, + fun(L) -> + Next = move(L), + transform(Next, gleam@dict:get(Grid, erlang:element(2, Next))) + end + ), + gleam@list:filter( + _pipe@1, + fun(L@1) -> not gleam@set:contains(Visited, L@1) end + ) + end, + All_visited = gleam@set:union(gleam@set:from_list(Next_positions), Visited), + case Visited =:= All_visited of + true -> + _pipe@2 = gleam@set:fold( + Visited, + gleam@set:new(), + fun(Acc, L@2) -> + gleam@set:insert(Acc, erlang:element(2, L@2)) + end + ), + _pipe@3 = gleam@set:to_list(_pipe@2), + gleam@list:length(_pipe@3); + + false -> + energize(Next_positions, All_visited, Grid) + end. + +-spec part1(binary()) -> integer(). +part1(Input) -> + Grid = utilities@array2d:parse_grid(Input), + _pipe = [{light, {posn, 0, -1}, right}], + energize(_pipe, gleam@set:new(), Grid). + +-spec part2(binary()) -> integer(). +part2(Input) -> + Grid = utilities@array2d:parse_grid(Input), + {posn, Rows, Cols} = (gleam@list:fold( + gleam@dict:keys(Grid), + {posn, 0, 0}, + fun(Acc, P) -> + case (erlang:element(2, Acc) + erlang:element(3, Acc)) > (erlang:element( + 2, + P + ) + + erlang:element(3, P)) of + true -> + Acc; + + false -> + P + end + end + )), + All_starts = gleam@list:concat( + [gleam@list:map( + gleam@list:range(0, Rows), + fun(R) -> {light, {posn, R, -1}, right} end + ), + gleam@list:map( + gleam@list:range(0, Rows), + fun(R@1) -> {light, {posn, R@1, Cols + 1}, left} end + ), + gleam@list:map( + gleam@list:range(0, Cols), + fun(C) -> {light, {posn, -1, C}, down} end + ), + gleam@list:map( + gleam@list:range(0, Cols), + fun(C@1) -> {light, {posn, Rows + 1, C@1}, up} end + )] + ), + gleam@list:fold( + All_starts, + 0, + fun(Acc@1, P@1) -> + Energized = energize([P@1], gleam@set:new(), Grid), + case Acc@1 > Energized of + true -> + Acc@1; + + false -> + Energized + end + end + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day16/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 107}) + end, + _assert_subject@1 = adglent:get_input(<<"16"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day16/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 108}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache Binary files differnew file mode 100644 index 0000000..923d0a6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache_meta Binary files differnew file mode 100644 index 0000000..1c9c12b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.erl new file mode 100644 index 0000000..052b6cc --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@day17_test.erl @@ -0,0 +1,42 @@ +-module(day17@day17_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"2413432311323 +3215453535623 +3255245654254 +3446585845452 +4546657867536 +1438598798454 +4457876987766 +3637877979653 +4654967986887 +4564679986453 +1224686865563 +2546548887735 +4322674655533"/utf8>>, + <<"102"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"2413432311323 +3215453535623 +3255245654254 +3446585845452 +4546657867536 +1438598798454 +4457876987766 +3637877979653 +4654967986887 +4564679986453 +1224686865563 +2546548887735 +4322674655533"/utf8>>, + <<"102"/utf8>>}], + fun(Example) -> _pipe@1 = day17@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache Binary files differnew file mode 100644 index 0000000..b06fb02 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache_meta Binary files differnew file mode 100644 index 0000000..aad0cb3 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.erl new file mode 100644 index 0000000..206ab5f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day17@solve.erl @@ -0,0 +1,231 @@ +-module(day17@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part2/1, part1/1, main/0]). +-export_type([state/0]). + +-type state() :: {state, + utilities@array2d:posn(), + integer(), + utilities@array2d:posn(), + list(utilities@array2d:posn())}. + +-spec same_dir(state()) -> list(utilities@array2d:posn()). +same_dir(S) -> + case erlang:element(5, S) of + [] -> + []; + + [First | _] = Deltas -> + _pipe = gleam@list:take_while(Deltas, fun(D) -> D =:= First end), + gleam@list:take(_pipe, 10) + end. + +-spec make_key(state()) -> {utilities@array2d:posn(), + list(utilities@array2d:posn())}. +make_key(S) -> + {erlang:element(2, S), same_dir(S)}. + +-spec is_goal(state(), integer(), utilities@array2d:posn()) -> boolean(). +is_goal(S, Min_run, Goal) -> + (Goal =:= erlang:element(2, S)) andalso (gleam@list:length(same_dir(S)) >= Min_run). + +-spec eliminate_bad_neighbors( + utilities@array2d:posn(), + state(), + integer(), + integer(), + gleam@dict:dict(utilities@array2d:posn(), any()) +) -> boolean(). +eliminate_bad_neighbors(D, S, Max, Min, Grid) -> + Neighbor = utilities@array2d:add_posns(D, erlang:element(2, S)), + gleam@bool:guard( + (Neighbor =:= erlang:element(4, S)) orelse not gleam@dict:has_key( + Grid, + Neighbor + ), + false, + fun() -> case {same_dir(S), gleam@list:length(same_dir(S))} of + {[Prev | _], L} when L =:= Max -> + D /= Prev; + + {_, 0} -> + true; + + {[Prev@1 | _], L@1} when L@1 < Min -> + D =:= Prev@1; + + {_, _} -> + true + end end + ). + +-spec make_state( + utilities@array2d:posn(), + state(), + gleam@dict:dict(utilities@array2d:posn(), integer()) +) -> state(). +make_state(D, S, Grid) -> + Neighbor = utilities@array2d:add_posns(D, erlang:element(2, S)), + _assert_subject = gleam@dict:get(Grid, Neighbor), + {ok, Heat_lost} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day17/solve"/utf8>>, + function => <<"make_state"/utf8>>, + line => 58}) + end, + {state, + Neighbor, + erlang:element(3, S) + Heat_lost, + erlang:element(2, S), + [D | erlang:element(5, S)]}. + +-spec find_path( + gleam@dict:dict(utilities@array2d:posn(), integer()), + utilities@prioqueue:priority_queue(state()), + gleam@set:set({utilities@array2d:posn(), list(utilities@array2d:posn())}), + fun((state()) -> list(state())), + fun((state()) -> boolean()) +) -> integer(). +find_path(Grid, Queue, Seen, Get_neighbors, Is_goal) -> + _assert_subject = utilities@prioqueue:pop(Queue), + {ok, {State, Rest}} = case _assert_subject of + {ok, {_, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day17/solve"/utf8>>, + function => <<"find_path"/utf8>>, + line => 74}) + end, + Key = make_key( + begin + _pipe = State, + gleam@io:debug(_pipe) + end + ), + case gleam@set:contains(Seen, Key) of + true -> + find_path(Grid, Rest, Seen, Get_neighbors, Is_goal); + + false -> + Now_seen = gleam@set:insert(Seen, Key), + Neighbors = Get_neighbors(State), + case gleam@list:find(Neighbors, Is_goal) of + {ok, Final} -> + erlang:element(3, Final); + + _ -> + Now_queue = gleam@list:fold( + Neighbors, + Rest, + fun(Acc, N) -> + utilities@prioqueue:insert( + Acc, + N, + erlang:element(3, N) + ) + end + ), + find_path(Grid, Now_queue, Now_seen, Get_neighbors, Is_goal) + end + end. + +-spec part2(binary()) -> binary(). +part2(Input) -> + _pipe = Input, + gleam@string:inspect(_pipe). + +-spec find_good_neighbors( + integer(), + integer(), + state(), + gleam@dict:dict(utilities@array2d:posn(), integer()) +) -> list(state()). +find_good_neighbors(Max, Min, S, Grid) -> + _pipe = [{posn, -1, 0}, {posn, 1, 0}, {posn, 0, -1}, {posn, 0, 1}], + _pipe@1 = gleam@list:filter( + _pipe, + fun(_capture) -> + eliminate_bad_neighbors(_capture, S, Max, Min, Grid) + end + ), + gleam@list:map( + _pipe@1, + fun(_capture@1) -> make_state(_capture@1, S, Grid) end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + Raw_grid = begin + _pipe = Input, + utilities@array2d:to_list_of_lists(_pipe) + end, + Grid = utilities@array2d:to_2d_intarray(Raw_grid), + Rmax = gleam@list:length(Raw_grid), + _assert_subject = begin + _pipe@1 = Raw_grid, + _pipe@2 = gleam@list:first(_pipe@1), + gleam@result:map(_pipe@2, fun gleam@list:length/1) + end, + {ok, Cmax} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day17/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 107}) + end, + Start = {state, {posn, 0, 0}, 0, {posn, 0, 0}, []}, + Goal = {posn, Rmax, Cmax}, + _pipe@3 = find_path( + Grid, + utilities@prioqueue:insert(utilities@prioqueue:new(), Start, 0), + gleam@set:new(), + fun(_capture) -> find_good_neighbors(0, 3, _capture, Grid) end, + fun(_capture@1) -> is_goal(_capture@1, 1, Goal) end + ), + gleam@string:inspect(_pipe@3). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day17/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 131}) + end, + _assert_subject@1 = adglent:get_input(<<"17"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day17/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 132}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache Binary files differnew file mode 100644 index 0000000..33f80d2 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache_meta Binary files differnew file mode 100644 index 0000000..22ffeb7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.erl new file mode 100644 index 0000000..76bea52 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@day18_test.erl @@ -0,0 +1,84 @@ +-module(day18@day18_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"R 6 (#70c710) +D 5 (#0dc571) +L 2 (#5713f0) +D 2 (#d2c081) +R 2 (#59c680) +D 2 (#411b91) +L 5 (#8ceee2) +U 2 (#caa173) +L 1 (#1b58a2) +U 2 (#caa171) +R 2 (#7807d2) +U 3 (#a77fa3) +L 2 (#015232) +U 2 (#7a21e3)"/utf8>>, + <<"62"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"R 6 (#70c710) +D 5 (#0dc571) +L 2 (#5713f0) +D 2 (#d2c081) +R 2 (#59c680) +D 2 (#411b91) +L 5 (#8ceee2) +U 2 (#caa173) +L 1 (#1b58a2) +U 2 (#caa171) +R 2 (#7807d2) +U 3 (#a77fa3) +L 2 (#015232) +U 2 (#7a21e3)"/utf8>>, + <<"62"/utf8>>}], + fun(Example) -> _pipe@1 = day18@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"R 6 (#70c710) +D 5 (#0dc571) +L 2 (#5713f0) +D 2 (#d2c081) +R 2 (#59c680) +D 2 (#411b91) +L 5 (#8ceee2) +U 2 (#caa173) +L 1 (#1b58a2) +U 2 (#caa171) +R 2 (#7807d2) +U 3 (#a77fa3) +L 2 (#015232) +U 2 (#7a21e3)"/utf8>>, + <<"952408144115"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"R 6 (#70c710) +D 5 (#0dc571) +L 2 (#5713f0) +D 2 (#d2c081) +R 2 (#59c680) +D 2 (#411b91) +L 5 (#8ceee2) +U 2 (#caa173) +L 1 (#1b58a2) +U 2 (#caa171) +R 2 (#7807d2) +U 3 (#a77fa3) +L 2 (#015232) +U 2 (#7a21e3)"/utf8>>, + <<"952408144115"/utf8>>}], + fun(Example) -> _pipe@1 = day18@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache Binary files differnew file mode 100644 index 0000000..c557ff7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache_meta Binary files differnew file mode 100644 index 0000000..a536e04 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.erl new file mode 100644 index 0000000..4e54297 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day18@solve.erl @@ -0,0 +1,218 @@ +-module(day18@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([coord/0, direction/0, dig/0]). + +-type coord() :: {coord, integer(), integer()}. + +-type direction() :: up | right | down | left. + +-type dig() :: {dig, direction(), integer()}. + +-spec to_direction(binary()) -> direction(). +to_direction(C) -> + case C of + <<"R"/utf8>> -> + right; + + <<"0"/utf8>> -> + right; + + <<"D"/utf8>> -> + down; + + <<"1"/utf8>> -> + down; + + <<"L"/utf8>> -> + left; + + <<"2"/utf8>> -> + left; + + <<"U"/utf8>> -> + up; + + <<"3"/utf8>> -> + up; + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"day18/solve"/utf8>>, + function => <<"to_direction"/utf8>>, + line => 30}) + end. + +-spec parse_front(binary()) -> dig(). +parse_front(Line) -> + _assert_subject = gleam@regex:from_string(<<"(.) (.*) \\(.*\\)"/utf8>>), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day18/solve"/utf8>>, + function => <<"parse_front"/utf8>>, + line => 35}) + end, + _assert_subject@1 = gleam@regex:scan(Re, Line), + [{match, _, [{some, Dir}, {some, Dist}]}] = case _assert_subject@1 of + [{match, _, [{some, _}, {some, _}]}] -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day18/solve"/utf8>>, + function => <<"parse_front"/utf8>>, + line => 36}) + end, + _assert_subject@2 = gleam@int:parse(Dist), + {ok, N} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day18/solve"/utf8>>, + function => <<"parse_front"/utf8>>, + line => 38}) + end, + {dig, to_direction(Dir), N}. + +-spec parse_hex(binary()) -> dig(). +parse_hex(Line) -> + _assert_subject = gleam@regex:from_string(<<"\\(#(.....)(.)\\)"/utf8>>), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day18/solve"/utf8>>, + function => <<"parse_hex"/utf8>>, + line => 43}) + end, + _assert_subject@1 = gleam@regex:scan(Re, Line), + [{match, _, [{some, Dist}, {some, Dir}]}] = case _assert_subject@1 of + [{match, _, [{some, _}, {some, _}]}] -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day18/solve"/utf8>>, + function => <<"parse_hex"/utf8>>, + line => 44}) + end, + _assert_subject@2 = gleam@int:base_parse(Dist, 16), + {ok, N} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day18/solve"/utf8>>, + function => <<"parse_hex"/utf8>>, + line => 46}) + end, + {dig, to_direction(Dir), N}. + +-spec go(coord(), dig()) -> coord(). +go(Current, Dig) -> + case Dig of + {dig, up, N} -> + {coord, erlang:element(2, Current), erlang:element(3, Current) + N}; + + {dig, right, N@1} -> + {coord, + erlang:element(2, Current) + N@1, + erlang:element(3, Current)}; + + {dig, down, N@2} -> + {coord, + erlang:element(2, Current), + erlang:element(3, Current) - N@2}; + + {dig, left, N@3} -> + {coord, + erlang:element(2, Current) - N@3, + erlang:element(3, Current)} + end. + +-spec double_triangle(coord(), coord()) -> integer(). +double_triangle(C1, C2) -> + (erlang:element(2, C1) * erlang:element(3, C2)) - (erlang:element(2, C2) * erlang:element( + 3, + C1 + )). + +-spec do_next_dig(list(dig()), coord(), integer(), integer()) -> integer(). +do_next_dig(Digs, Current, Area, Perimeter) -> + case Digs of + [] -> + ((gleam@int:absolute_value(Area) div 2) + (Perimeter div 2)) + 1; + + [Dig | Rest] -> + Next = go(Current, Dig), + Area@1 = Area + double_triangle(Current, Next), + Perimeter@1 = Perimeter + erlang:element(3, Dig), + do_next_dig(Rest, Next, Area@1, Perimeter@1) + end. + +-spec start_dig(list(dig())) -> integer(). +start_dig(Digs) -> + do_next_dig(Digs, {coord, 0, 0}, 0, 0). + +-spec solve_with(binary(), fun((binary()) -> dig())) -> binary(). +solve_with(Input, F) -> + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, F), + _pipe@3 = start_dig(_pipe@2), + gleam@string:inspect(_pipe@3). + +-spec part1(binary()) -> binary(). +part1(Input) -> + solve_with(Input, fun parse_front/1). + +-spec part2(binary()) -> binary(). +part2(Input) -> + solve_with(Input, fun parse_hex/1). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day18/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 101}) + end, + _assert_subject@1 = adglent:get_input(<<"18"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day18/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 102}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache Binary files differnew file mode 100644 index 0000000..32c0bad --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache_meta Binary files differnew file mode 100644 index 0000000..56332b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.erl new file mode 100644 index 0000000..d9fea80 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@day19_test.erl @@ -0,0 +1,96 @@ +-module(day19@day19_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"px{a<2006:qkq,m>2090:A,rfg} +pv{a>1716:R,A} +lnx{m>1548:A,A} +rfg{s<537:gd,x>2440:R,A} +qs{s>3448:A,lnx} +qkq{x<1416:A,crn} +crn{x>2662:A,R} +in{s<1351:px,qqz} +qqz{s>2770:qs,m<1801:hdj,R} +gd{a>3333:R,R} +hdj{m>838:A,pv} + +{x=787,m=2655,a=1222,s=2876} +{x=1679,m=44,a=2067,s=496} +{x=2036,m=264,a=79,s=2244} +{x=2461,m=1339,a=466,s=291} +{x=2127,m=1623,a=2188,s=1013}"/utf8>>, + <<"19114"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"px{a<2006:qkq,m>2090:A,rfg} +pv{a>1716:R,A} +lnx{m>1548:A,A} +rfg{s<537:gd,x>2440:R,A} +qs{s>3448:A,lnx} +qkq{x<1416:A,crn} +crn{x>2662:A,R} +in{s<1351:px,qqz} +qqz{s>2770:qs,m<1801:hdj,R} +gd{a>3333:R,R} +hdj{m>838:A,pv} + +{x=787,m=2655,a=1222,s=2876} +{x=1679,m=44,a=2067,s=496} +{x=2036,m=264,a=79,s=2244} +{x=2461,m=1339,a=466,s=291} +{x=2127,m=1623,a=2188,s=1013}"/utf8>>, + <<"19114"/utf8>>}], + fun(Example) -> _pipe@1 = day19@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"px{a<2006:qkq,m>2090:A,rfg} +pv{a>1716:R,A} +lnx{m>1548:A,A} +rfg{s<537:gd,x>2440:R,A} +qs{s>3448:A,lnx} +qkq{x<1416:A,crn} +crn{x>2662:A,R} +in{s<1351:px,qqz} +qqz{s>2770:qs,m<1801:hdj,R} +gd{a>3333:R,R} +hdj{m>838:A,pv} + +{x=787,m=2655,a=1222,s=2876} +{x=1679,m=44,a=2067,s=496} +{x=2036,m=264,a=79,s=2244} +{x=2461,m=1339,a=466,s=291} +{x=2127,m=1623,a=2188,s=1013}"/utf8>>, + <<"167409079868000"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"px{a<2006:qkq,m>2090:A,rfg} +pv{a>1716:R,A} +lnx{m>1548:A,A} +rfg{s<537:gd,x>2440:R,A} +qs{s>3448:A,lnx} +qkq{x<1416:A,crn} +crn{x>2662:A,R} +in{s<1351:px,qqz} +qqz{s>2770:qs,m<1801:hdj,R} +gd{a>3333:R,R} +hdj{m>838:A,pv} + +{x=787,m=2655,a=1222,s=2876} +{x=1679,m=44,a=2067,s=496} +{x=2036,m=264,a=79,s=2244} +{x=2461,m=1339,a=466,s=291} +{x=2127,m=1623,a=2188,s=1013}"/utf8>>, + <<"167409079868000"/utf8>>}], + fun(Example) -> _pipe@1 = day19@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache Binary files differnew file mode 100644 index 0000000..45dad16 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache_meta Binary files differnew file mode 100644 index 0000000..8e99d6a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.erl new file mode 100644 index 0000000..2f49f41 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day19@solve.erl @@ -0,0 +1,459 @@ +-module(day19@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([rating/0, part/0, action/0, rule/0, interval/0, part_range/0]). + +-type rating() :: xtremely_cool | musical | aerodynamic | shiny. + +-type part() :: {part, integer(), integer(), integer(), integer()}. + +-type action() :: accept | reject | {send_to, binary()}. + +-type rule() :: {'if', rating(), gleam@order:order(), integer(), action()} | + {just, action()}. + +-type interval() :: {interval, integer(), integer()}. + +-type part_range() :: {part_range, + interval(), + interval(), + interval(), + interval()}. + +-spec to_instruction(binary()) -> action(). +to_instruction(Rule) -> + case Rule of + <<"A"/utf8>> -> + accept; + + <<"R"/utf8>> -> + reject; + + Name -> + {send_to, Name} + end. + +-spec to_rating(binary()) -> rating(). +to_rating(Rating) -> + case Rating of + <<"x"/utf8>> -> + xtremely_cool; + + <<"m"/utf8>> -> + musical; + + <<"a"/utf8>> -> + aerodynamic; + + _ -> + shiny + end. + +-spec get_rating(part(), rating()) -> integer(). +get_rating(Part, Rating) -> + case Rating of + xtremely_cool -> + erlang:element(2, Part); + + musical -> + erlang:element(3, Part); + + aerodynamic -> + erlang:element(4, Part); + + shiny -> + erlang:element(5, Part) + end. + +-spec to_comp(binary()) -> gleam@order:order(). +to_comp(Comp) -> + case Comp of + <<"<"/utf8>> -> + lt; + + _ -> + gt + end. + +-spec to_val(binary()) -> integer(). +to_val(Val) -> + _assert_subject = gleam@int:parse(Val), + {ok, N} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"to_val"/utf8>>, + line => 100}) + end, + N. + +-spec parse_rules(list(binary())) -> list(rule()). +parse_rules(Rules) -> + _assert_subject = gleam@regex:from_string(<<"(.*)(>|<)(.*):(.*)"/utf8>>), + {ok, Re_rule} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"parse_rules"/utf8>>, + line => 57}) + end, + gleam@list:map(Rules, fun(Rule) -> case gleam@regex:scan(Re_rule, Rule) of + [{match, _, [{some, R}, {some, C}, {some, T}, {some, I}]}] -> + {'if', + to_rating(R), + to_comp(C), + to_val(T), + to_instruction(I)}; + + _ -> + {just, to_instruction(Rule)} + end end). + +-spec parse_workflow(binary()) -> gleam@dict:dict(binary(), list(rule())). +parse_workflow(Input) -> + _assert_subject = gleam@regex:from_string(<<"(.*){(.*)}"/utf8>>), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"parse_workflow"/utf8>>, + line => 45}) + end, + gleam@list:fold( + gleam@string:split(Input, <<"\n"/utf8>>), + gleam@dict:new(), + fun(Acc, Line) -> + _assert_subject@1 = gleam@regex:scan(Re, Line), + [{match, _, [{some, Name}, {some, All_rules}]}] = case _assert_subject@1 of + [{match, _, [{some, _}, {some, _}]}] -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day19/solve"/utf8>>, + function => <<"parse_workflow"/utf8>>, + line => 48}) + end, + Rules = begin + _pipe = gleam@string:split(All_rules, <<","/utf8>>), + parse_rules(_pipe) + end, + gleam@dict:insert(Acc, Name, Rules) + end + ). + +-spec parse_parts(binary()) -> list(part()). +parse_parts(Input) -> + _assert_subject = gleam@regex:from_string( + <<"{x=(.*),m=(.*),a=(.*),s=(.*)}"/utf8>> + ), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"parse_parts"/utf8>>, + line => 105}) + end, + gleam@list:map( + gleam@string:split(Input, <<"\n"/utf8>>), + fun(Part) -> + _assert_subject@1 = gleam@regex:scan(Re, Part), + [{match, _, [{some, X}, {some, M}, {some, A}, {some, S}]}] = case _assert_subject@1 of + [{match, _, [{some, _}, {some, _}, {some, _}, {some, _}]}] -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day19/solve"/utf8>>, + function => <<"parse_parts"/utf8>>, + line => 108}) + end, + {part, to_val(X), to_val(M), to_val(A), to_val(S)} + end + ). + +-spec evaluate_rules(part(), list(rule())) -> action(). +evaluate_rules(Part, Rules) -> + case Rules of + [] -> + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"day19/solve"/utf8>>, + function => <<"evaluate_rules"/utf8>>, + line => 128}); + + [{just, Do} | _] -> + Do; + + [{'if', Rating, Comparison, Threshold, Do@1} | Rest] -> + case gleam@int:compare(get_rating(Part, Rating), Threshold) =:= Comparison of + true -> + Do@1; + + false -> + evaluate_rules(Part, Rest) + end + end. + +-spec evaluate_workflow( + part(), + binary(), + gleam@dict:dict(binary(), list(rule())) +) -> integer(). +evaluate_workflow(Part, Name, Workflow) -> + _assert_subject = gleam@dict:get(Workflow, Name), + {ok, Rules} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"evaluate_workflow"/utf8>>, + line => 118}) + end, + case evaluate_rules(Part, Rules) of + accept -> + ((erlang:element(2, Part) + erlang:element(3, Part)) + erlang:element( + 4, + Part + )) + + erlang:element(5, Part); + + reject -> + 0; + + {send_to, Name@1} -> + evaluate_workflow(Part, Name@1, Workflow) + end. + +-spec start_evaluating_workflow(part(), gleam@dict:dict(binary(), list(rule()))) -> integer(). +start_evaluating_workflow(Part, Workflow) -> + evaluate_workflow(Part, <<"in"/utf8>>, Workflow). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _assert_subject = gleam@string:split_once(Input, <<"\n\n"/utf8>>), + {ok, {Workflows_str, Parts_str}} = case _assert_subject of + {ok, {_, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 139}) + end, + Workflows = parse_workflow(Workflows_str), + Parts = parse_parts(Parts_str), + _pipe = gleam@list:map( + Parts, + fun(_capture) -> start_evaluating_workflow(_capture, Workflows) end + ), + _pipe@1 = gleam@int:sum(_pipe), + gleam@string:inspect(_pipe@1). + +-spec size(interval()) -> integer(). +size(Interval) -> + (erlang:element(3, Interval) - erlang:element(2, Interval)) + 1. + +-spec all_in_range(part_range()) -> integer(). +all_in_range(Pr) -> + ((size(erlang:element(2, Pr)) * size(erlang:element(3, Pr))) * size( + erlang:element(4, Pr) + )) + * size(erlang:element(5, Pr)). + +-spec get_partrange(part_range(), rating()) -> interval(). +get_partrange(Pr, Rating) -> + case Rating of + xtremely_cool -> + erlang:element(2, Pr); + + musical -> + erlang:element(3, Pr); + + aerodynamic -> + erlang:element(4, Pr); + + shiny -> + erlang:element(5, Pr) + end. + +-spec update_partrange(part_range(), rating(), interval()) -> part_range(). +update_partrange(Pr, Rating, I) -> + case Rating of + xtremely_cool -> + erlang:setelement(2, Pr, I); + + musical -> + erlang:setelement(3, Pr, I); + + aerodynamic -> + erlang:setelement(4, Pr, I); + + shiny -> + erlang:setelement(5, Pr, I) + end. + +-spec evaluate_rules_on_range( + part_range(), + list(rule()), + gleam@dict:dict(binary(), list(rule())) +) -> integer(). +evaluate_rules_on_range(Pr, Rules, Workflow) -> + case Rules of + [{just, accept} | _] -> + all_in_range(Pr); + + [{just, reject} | _] -> + 0; + + [{just, {send_to, Name}} | _] -> + evaluate_workflow_on_range(Pr, Name, Workflow); + + [{'if', Rating, Comparison, T, Action} | Rest] -> + Mod_i = get_partrange(Pr, Rating), + case Comparison of + lt -> + split_range( + update_partrange( + Pr, + Rating, + {interval, erlang:element(2, Mod_i), T - 1} + ), + Action, + update_partrange( + Pr, + Rating, + {interval, T, erlang:element(3, Mod_i)} + ), + Rest, + Workflow + ); + + _ -> + split_range( + update_partrange( + Pr, + Rating, + {interval, T + 1, erlang:element(3, Mod_i)} + ), + Action, + update_partrange( + Pr, + Rating, + {interval, erlang:element(2, Mod_i), T} + ), + Rest, + Workflow + ) + end; + + [] -> + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"day19/solve"/utf8>>, + function => <<"evaluate_rules_on_range"/utf8>>, + line => 225}) + end. + +-spec evaluate_workflow_on_range( + part_range(), + binary(), + gleam@dict:dict(binary(), list(rule())) +) -> integer(). +evaluate_workflow_on_range(Pr, Name, Workflow) -> + _assert_subject = gleam@dict:get(Workflow, Name), + {ok, Rules} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"evaluate_workflow_on_range"/utf8>>, + line => 191}) + end, + evaluate_rules_on_range(Pr, Rules, Workflow). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _assert_subject = gleam@string:split_once(Input, <<"\n\n"/utf8>>), + {ok, {Workflows_str, _}} = case _assert_subject of + {ok, {_, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 176}) + end, + Workflow = parse_workflow(Workflows_str), + Start = {interval, 1, 4000}, + _pipe = {part_range, Start, Start, Start, Start}, + _pipe@1 = evaluate_workflow_on_range(_pipe, <<"in"/utf8>>, Workflow), + gleam@string:inspect(_pipe@1). + +-spec split_range( + part_range(), + action(), + part_range(), + list(rule()), + gleam@dict:dict(binary(), list(rule())) +) -> integer(). +split_range(Keep, Action, Pass, Rest, Workflow) -> + gleam@int:add( + evaluate_rules_on_range(Keep, [{just, Action}], Workflow), + evaluate_rules_on_range(Pass, Rest, Workflow) + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day19/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 243}) + end, + _assert_subject@1 = adglent:get_input(<<"19"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day19/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 244}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache Binary files differnew file mode 100644 index 0000000..77a1d03 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache_meta Binary files differnew file mode 100644 index 0000000..da0b837 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.erl new file mode 100644 index 0000000..22e3cdd --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@day1_test.erl @@ -0,0 +1,50 @@ +-module(day1@day1_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet"/utf8>>, + <<"142"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet"/utf8>>, + <<"142"/utf8>>}], + fun(Example) -> _pipe@1 = day1@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen"/utf8>>, + <<"281"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen"/utf8>>, + <<"281"/utf8>>}], + fun(Example) -> _pipe@1 = day1@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache Binary files differnew file mode 100644 index 0000000..a1932c5 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache_meta Binary files differnew file mode 100644 index 0000000..b3e1773 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.erl new file mode 100644 index 0000000..0d89b63 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day1@solve.erl @@ -0,0 +1,118 @@ +-module(day1@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _assert_subject = gleam@regex:from_string(<<"[1-9]"/utf8>>), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day1/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 9}) + end, + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:fold( + _pipe@1, + 0, + fun(Acc, S) -> + Matches = gleam@regex:scan(Re, S), + _assert_subject@1 = gleam@list:first(Matches), + {ok, {match, First, _}} = case _assert_subject@1 of + {ok, {match, _, _}} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day1/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 16}) + end, + _assert_subject@2 = gleam@list:last(Matches), + {ok, {match, Last, _}} = case _assert_subject@2 of + {ok, {match, _, _}} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day1/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 17}) + end, + _assert_subject@3 = gleam@int:parse(<<First/binary, Last/binary>>), + {ok, I} = case _assert_subject@3 of + {ok, _} -> _assert_subject@3; + _assert_fail@3 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@3, + module => <<"day1/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 18}) + end, + Acc + I + end + ), + gleam@string:inspect(_pipe@2). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _pipe = gleam@list:fold( + [{<<"one"/utf8>>, <<"o1e"/utf8>>}, + {<<"two"/utf8>>, <<"t2o"/utf8>>}, + {<<"three"/utf8>>, <<"t3e"/utf8>>}, + {<<"four"/utf8>>, <<"4"/utf8>>}, + {<<"five"/utf8>>, <<"5e"/utf8>>}, + {<<"six"/utf8>>, <<"6"/utf8>>}, + {<<"seven"/utf8>>, <<"7n"/utf8>>}, + {<<"eight"/utf8>>, <<"e8t"/utf8>>}, + {<<"nine"/utf8>>, <<"n9e"/utf8>>}], + Input, + fun(Acc, Sub) -> + {From, To} = Sub, + gleam@string:replace(Acc, From, To) + end + ), + part1(_pipe). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day1/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 45}) + end, + _assert_subject@1 = adglent:get_input(<<"1"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day1/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 46}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache Binary files differnew file mode 100644 index 0000000..7571e58 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache_meta Binary files differnew file mode 100644 index 0000000..74efc1e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.erl new file mode 100644 index 0000000..4ae59a9 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@day20_test.erl @@ -0,0 +1,42 @@ +-module(day20@day20_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"broadcaster -> a, b, c +%a -> b +%b -> c +%c -> inv +&inv -> a"/utf8>>, + <<"32000000"/utf8>>}, + {example, + <<"broadcaster -> a +%a -> inv, con +&inv -> b +%b -> con +&con -> output +output -> "/utf8>>, + <<"11687500"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"broadcaster -> a, b, c +%a -> b +%b -> c +%c -> inv +&inv -> a"/utf8>>, + <<"32000000"/utf8>>}, + {example, + <<"broadcaster -> a +%a -> inv, con +&inv -> b +%b -> con +&con -> output +output -> "/utf8>>, + <<"11687500"/utf8>>}], + fun(Example) -> _pipe@1 = day20@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache Binary files differnew file mode 100644 index 0000000..a8d7071 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache_meta Binary files differnew file mode 100644 index 0000000..a6f2f83 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.erl new file mode 100644 index 0000000..a496b49 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day20@solve.erl @@ -0,0 +1,460 @@ +-module(day20@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([node_/0, tone/0, power/0, tone_pitch/0, state/0]). + +-type node_() :: {broadcaster, list(binary())} | + {flipflop, list(binary()), power()} | + {conjunction, list(binary()), gleam@dict:dict(binary(), tone_pitch())} | + ground. + +-type tone() :: {tone, binary(), binary(), tone_pitch()}. + +-type power() :: on | off. + +-type tone_pitch() :: low | high. + +-type state() :: {state, + gleam@dict:dict(binary(), node_()), + integer(), + integer(), + integer(), + gleam@dict:dict(binary(), integer())}. + +-spec flip_power(power()) -> power(). +flip_power(P) -> + case P of + on -> + off; + + off -> + on + end. + +-spec flip_flop_pitch(power()) -> tone_pitch(). +flip_flop_pitch(P) -> + case P of + off -> + high; + + on -> + low + end. + +-spec combinator_pitch(gleam@dict:dict(any(), tone_pitch())) -> tone_pitch(). +combinator_pitch(State) -> + case gleam@list:unique(gleam@dict:values(State)) of + [high] -> + low; + + _ -> + high + end. + +-spec get_children(node_()) -> list(binary()). +get_children(Node) -> + case Node of + {flipflop, Cs, _} -> + Cs; + + {conjunction, Cs@1, _} -> + Cs@1; + + {broadcaster, Cs@2} -> + Cs@2; + + ground -> + [] + end. + +-spec parse_node(binary()) -> {binary(), node_()}. +parse_node(Input) -> + _assert_subject = gleam@string:split(Input, <<" -> "/utf8>>), + [Full_name, Children_str] = case _assert_subject of + [_, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"parse_node"/utf8>>, + line => 73}) + end, + Children = gleam@string:split(Children_str, <<", "/utf8>>), + case Full_name of + <<"%"/utf8, Name/binary>> -> + {Name, {flipflop, Children, off}}; + + <<"&"/utf8, Name@1/binary>> -> + {Name@1, {conjunction, Children, gleam@dict:new()}}; + + <<"broadcaster"/utf8>> -> + {<<"broadcaster"/utf8>>, {broadcaster, Children}}; + + Name@2 -> + {Name@2, ground} + end. + +-spec to_initial_state(list({binary(), node_()})) -> gleam@dict:dict(binary(), node_()). +to_initial_state(Nodes) -> + Node_dict = gleam@dict:from_list(Nodes), + Node_names = gleam@dict:keys(Node_dict), + Node_dict@1 = begin + _pipe = Node_dict, + _pipe@1 = gleam@dict:values(_pipe), + _pipe@2 = gleam@list:map(_pipe@1, fun get_children/1), + _pipe@3 = gleam@list:concat(_pipe@2), + _pipe@4 = gleam@set:from_list(_pipe@3), + _pipe@5 = gleam@set:drop(_pipe@4, gleam@dict:keys(Node_dict)), + _pipe@6 = gleam@set:to_list(_pipe@5), + gleam@list:fold( + _pipe@6, + Node_dict, + fun(Acc, N) -> gleam@dict:insert(Acc, N, ground) end + ) + end, + gleam@dict:map_values(Node_dict@1, fun(Name, Node) -> case Node of + {conjunction, Chs, _} -> + _pipe@7 = Node_names, + _pipe@8 = gleam@list:filter( + _pipe@7, + fun(N@1) -> + _assert_subject = gleam@dict:get(Node_dict@1, N@1), + {ok, Node@1} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"to_initial_state"/utf8>>, + line => 103}) + end, + gleam@list:contains(get_children(Node@1), Name) + end + ), + _pipe@9 = gleam@list:map( + _pipe@8, + fun(N@2) -> {N@2, low} end + ), + _pipe@10 = gleam@dict:from_list(_pipe@9), + (fun(Dict) -> {conjunction, Chs, Dict} end)(_pipe@10); + + Other -> + Other + end end). + +-spec add_to_queue( + binary(), + list(binary()), + tone_pitch(), + gleam@queue:queue(tone()) +) -> gleam@queue:queue(tone()). +add_to_queue(From, Children, Pitch, Queue) -> + gleam@list:fold( + Children, + Queue, + fun(Acc, C) -> gleam@queue:push_back(Acc, {tone, From, C, Pitch}) end + ). + +-spec add_tones( + state(), + gleam@dict:dict(binary(), node_()), + tone_pitch(), + integer() +) -> state(). +add_tones(State, Nodes, Pitch, N) -> + case Pitch of + low -> + erlang:setelement( + 5, + erlang:setelement( + 3, + erlang:setelement(2, State, Nodes), + erlang:element(3, State) + N + ), + erlang:element(5, State) + 1 + ); + + high -> + erlang:setelement( + 5, + erlang:setelement( + 4, + erlang:setelement(2, State, Nodes), + erlang:element(4, State) + N + ), + erlang:element(5, State) + 1 + ) + end. + +-spec check_for_interesting_node(state(), binary(), tone_pitch()) -> state(). +check_for_interesting_node(State, Name, Pitch_out) -> + case {Name, Pitch_out} of + {<<"rk"/utf8>>, high} -> + erlang:setelement( + 6, + State, + gleam@dict:insert( + erlang:element(6, State), + Name, + erlang:element(5, State) + ) + ); + + {<<"cd"/utf8>>, high} -> + erlang:setelement( + 6, + State, + gleam@dict:insert( + erlang:element(6, State), + Name, + erlang:element(5, State) + ) + ); + + {<<"zf"/utf8>>, high} -> + erlang:setelement( + 6, + State, + gleam@dict:insert( + erlang:element(6, State), + Name, + erlang:element(5, State) + ) + ); + + {<<"qx"/utf8>>, high} -> + erlang:setelement( + 6, + State, + gleam@dict:insert( + erlang:element(6, State), + Name, + erlang:element(5, State) + ) + ); + + {_, _} -> + State + end. + +-spec press_button_once(state(), gleam@queue:queue(tone())) -> state(). +press_button_once(Initial, Queue) -> + {state, Nodes, _, _, _, _} = Initial, + gleam@bool:guard( + gleam@queue:is_empty(Queue), + Initial, + fun() -> + _assert_subject = gleam@queue:pop_front(Queue), + {ok, {{tone, From_name, To_name, Pitch}, Rest}} = case _assert_subject of + {ok, {{tone, _, _, _}, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"press_button_once"/utf8>>, + line => 131}) + end, + _assert_subject@1 = gleam@dict:get(Nodes, To_name), + {ok, To_node} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day20/solve"/utf8>>, + function => <<"press_button_once"/utf8>>, + line => 134}) + end, + case To_node of + {broadcaster, Children} -> + New_state = add_tones( + Initial, + Nodes, + Pitch, + gleam@list:length(Children) + 1 + ), + New_queue = add_to_queue(To_name, Children, Pitch, Rest), + press_button_once(New_state, New_queue); + + {conjunction, Children@1, State} -> + New_state@1 = begin + _pipe = State, + gleam@dict:insert(_pipe, From_name, Pitch) + end, + Updated_nodes = begin + _pipe@1 = {conjunction, Children@1, New_state@1}, + gleam@dict:insert(Nodes, To_name, _pipe@1) + end, + Pitch_out = combinator_pitch(New_state@1), + New_state@2 = begin + _pipe@2 = add_tones( + Initial, + Updated_nodes, + Pitch_out, + gleam@list:length(Children@1) + ), + check_for_interesting_node( + _pipe@2, + From_name, + Pitch_out + ) + end, + _pipe@3 = add_to_queue(To_name, Children@1, Pitch_out, Rest), + press_button_once(New_state@2, _pipe@3); + + {flipflop, _, _} when Pitch =:= high -> + press_button_once( + erlang:setelement( + 5, + Initial, + erlang:element(5, Initial) + 1 + ), + Rest + ); + + {flipflop, Children@2, State@1} -> + Updated_nodes@1 = begin + _pipe@4 = {flipflop, Children@2, flip_power(State@1)}, + gleam@dict:insert(Nodes, To_name, _pipe@4) + end, + Pitch_out@1 = flip_flop_pitch(State@1), + New_state@3 = add_tones( + Initial, + Updated_nodes@1, + Pitch_out@1, + gleam@list:length(Children@2) + ), + _pipe@5 = add_to_queue( + To_name, + Children@2, + flip_flop_pitch(State@1), + Rest + ), + press_button_once(New_state@3, _pipe@5); + + ground -> + press_button_once( + erlang:setelement( + 5, + Initial, + erlang:element(5, Initial) + 1 + ), + Rest + ) + end + end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + Initial_state = begin + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun parse_node/1), + to_initial_state(_pipe@2) + end, + _pipe@3 = gleam@iterator:iterate( + {state, Initial_state, 0, 0, 1, gleam@dict:new()}, + fun(_capture) -> + press_button_once( + _capture, + gleam@queue:from_list( + [{tone, <<"button"/utf8>>, <<"broadcaster"/utf8>>, low}] + ) + ) + end + ), + _pipe@4 = gleam@iterator:at(_pipe@3, 1000), + _pipe@5 = (fun(S) -> + {ok, {state, _, Low, High, _, _}} = case S of + {ok, {state, _, _, _, _, _}} -> S; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 199}) + end, + High * Low + end)(_pipe@4), + gleam@string:inspect(_pipe@5). + +-spec part2(binary()) -> binary(). +part2(Input) -> + Initial_state = begin + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun parse_node/1), + to_initial_state(_pipe@2) + end, + _pipe@3 = gleam@iterator:iterate( + {state, Initial_state, 0, 0, 1, gleam@dict:new()}, + fun(_capture) -> + press_button_once( + _capture, + gleam@queue:from_list( + [{tone, <<"button"/utf8>>, <<"broadcaster"/utf8>>, low}] + ) + ) + end + ), + _pipe@4 = gleam@iterator:drop_while( + _pipe@3, + fun(S) -> gleam@dict:size(erlang:element(6, S)) < 4 end + ), + _pipe@5 = gleam@iterator:step(_pipe@4), + _pipe@6 = (fun(S@1) -> + {next, Goal, _} = case S@1 of + {next, _, _} -> S@1; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 232}) + end, + erlang:element(6, Goal) + end)(_pipe@5), + gleam@string:inspect(_pipe@6). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day20/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 239}) + end, + _assert_subject@1 = adglent:get_input(<<"20"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day20/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 240}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache Binary files differnew file mode 100644 index 0000000..7eec8c7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache_meta Binary files differnew file mode 100644 index 0000000..10d8749 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.erl new file mode 100644 index 0000000..f2b842c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@day21_test.erl @@ -0,0 +1,24 @@ +-module(day21@day21_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [], + fun(Example) -> _pipe@1 = day21@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [], + fun(Example) -> _pipe@1 = day21@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache Binary files differnew file mode 100644 index 0000000..eb2a3e9 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache_meta Binary files differnew file mode 100644 index 0000000..d810856 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.erl new file mode 100644 index 0000000..be4464d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day21@solve.erl @@ -0,0 +1,56 @@ +-module(day21@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). + +-spec part1(binary()) -> any(). +part1(Input) -> + erlang:error(#{gleam_error => todo, + message => <<"Implement solution to part 1"/utf8>>, + module => <<"day21/solve"/utf8>>, + function => <<"part1"/utf8>>, + line => 5}). + +-spec part2(binary()) -> any(). +part2(Input) -> + erlang:error(#{gleam_error => todo, + message => <<"Implement solution to part 2"/utf8>>, + module => <<"day21/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 9}). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day21/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 13}) + end, + _assert_subject@1 = adglent:get_input(<<"21"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day21/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 14}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache Binary files differnew file mode 100644 index 0000000..48b46ff --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache_meta Binary files differnew file mode 100644 index 0000000..c0c6c8a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.erl new file mode 100644 index 0000000..e571215 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@day22_test.erl @@ -0,0 +1,56 @@ +-module(day22@day22_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9"/utf8>>, + 5}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9"/utf8>>, + 5}], + fun(Example) -> _pipe@1 = day22@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9"/utf8>>, + 7}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"1,0,1~1,2,1 +0,0,2~2,0,2 +0,2,3~2,2,3 +0,0,4~0,2,4 +2,0,5~2,2,5 +0,1,6~2,1,6 +1,1,8~1,1,9"/utf8>>, + 7}], + fun(Example) -> _pipe@1 = day22@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache Binary files differnew file mode 100644 index 0000000..6fb1a11 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache_meta Binary files differnew file mode 100644 index 0000000..2a4dc01 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.erl new file mode 100644 index 0000000..6d6b33c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day22@solve.erl @@ -0,0 +1,369 @@ +-module(day22@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([point/0, block/0]). + +-type point() :: {point, integer(), integer(), integer()}. + +-type block() :: {block, integer(), point(), point()}. + +-spec down_one(point()) -> point(). +down_one(P) -> + erlang:setelement(4, P, erlang:element(4, P) - 1). + +-spec compare_blocks(block(), block()) -> gleam@order:order(). +compare_blocks(B1, B2) -> + gleam@int:compare( + erlang:element(4, erlang:element(4, B1)), + erlang:element(4, erlang:element(4, B2)) + ). + +-spec parse_block(integer(), binary()) -> block(). +parse_block(Index, Input) -> + _assert_subject = gleam@regex:from_string( + <<"(.*),(.*),(.*)~(.*),(.*),(.*)"/utf8>> + ), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day22/solve"/utf8>>, + function => <<"parse_block"/utf8>>, + line => 39}) + end, + _assert_subject@1 = gleam@regex:scan(Re, Input), + [Scan] = case _assert_subject@1 of + [_] -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day22/solve"/utf8>>, + function => <<"parse_block"/utf8>>, + line => 41}) + end, + _assert_subject@2 = begin + _pipe = erlang:element(3, Scan), + _pipe@1 = gleam@option:all(_pipe), + _pipe@2 = gleam@option:unwrap(_pipe@1, []), + _pipe@3 = gleam@list:map(_pipe@2, fun gleam@int:parse/1), + gleam@result:values(_pipe@3) + end, + [X1, Y1, Z1, X2, Y2, Z2] = case _assert_subject@2 of + [_, _, _, _, _, _] -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day22/solve"/utf8>>, + function => <<"parse_block"/utf8>>, + line => 43}) + end, + {block, Index, {point, X1, Y1, Z1}, {point, X2, Y2, Z2}}. + +-spec cross_section_at_level(block(), integer()) -> list(point()). +cross_section_at_level(B, Z) -> + gleam@list:flat_map( + gleam@list:range( + erlang:element(2, erlang:element(3, B)), + erlang:element(2, erlang:element(4, B)) + ), + fun(X) -> + gleam@list:map( + gleam@list:range( + erlang:element(3, erlang:element(3, B)), + erlang:element(3, erlang:element(4, B)) + ), + fun(Y) -> {point, X, Y, Z} end + ) + end + ). + +-spec place_block(gleam@dict:dict(point(), block()), block(), integer()) -> gleam@dict:dict(point(), block()). +place_block(Space, B, Z) -> + Now_occupied = (gleam@list:flat_map( + gleam@list:range( + erlang:element(2, erlang:element(3, B)), + erlang:element(2, erlang:element(4, B)) + ), + fun(X) -> + gleam@list:flat_map( + gleam@list:range( + erlang:element(3, erlang:element(3, B)), + erlang:element(3, erlang:element(4, B)) + ), + fun(Y) -> + gleam@list:map( + gleam@list:range( + Z, + (Z + erlang:element(4, erlang:element(4, B))) - erlang:element( + 4, + erlang:element(3, B) + ) + ), + fun(Z@1) -> {{point, X, Y, Z@1}, B} end + ) + end + ) + end + )), + gleam@dict:merge(Space, gleam@dict:from_list(Now_occupied)). + +-spec do_find_lowest(gleam@dict:dict(point(), block()), block(), integer()) -> gleam@dict:dict(point(), block()). +do_find_lowest(Space, B, Z) -> + Is_intersecting = gleam@list:any( + cross_section_at_level(B, Z), + fun(_capture) -> gleam@dict:has_key(Space, _capture) end + ), + case {Z, Is_intersecting} of + {0, _} -> + place_block(Space, B, 1); + + {_, true} -> + place_block(Space, B, Z + 1); + + {_, false} -> + do_find_lowest(Space, B, Z - 1) + end. + +-spec find_lowest_level(gleam@dict:dict(point(), block()), block()) -> gleam@dict:dict(point(), block()). +find_lowest_level(Space, B) -> + do_find_lowest(Space, B, erlang:element(4, erlang:element(3, B))). + +-spec to_block_positions(gleam@dict:dict(point(), block())) -> gleam@dict:dict(block(), list(point())). +to_block_positions(Space) -> + gleam@dict:fold( + Space, + gleam@dict:new(), + fun(Acc, Point, Index) -> + gleam@dict:update(Acc, Index, fun(Points) -> case Points of + {some, Ps} -> + [Point | Ps]; + + none -> + [Point] + end end) + end + ). + +-spec above_blocks(gleam@dict:dict(block(), list(point()))) -> gleam@dict:dict(integer(), gleam@set:set(integer())). +above_blocks(Blocks) -> + gleam@dict:fold( + Blocks, + gleam@dict:new(), + fun(Acc, Block, Points) -> + gleam@dict:update( + Acc, + erlang:element(2, Block), + fun(_) -> + _pipe = (gleam@dict:filter( + Blocks, + fun(Above_block, Above_points) -> + (erlang:element(2, Above_block) /= erlang:element( + 2, + Block + )) + andalso gleam@list:any( + Above_points, + fun(P) -> + gleam@list:contains(Points, down_one(P)) + end + ) + end + )), + _pipe@1 = gleam@dict:keys(_pipe), + _pipe@2 = gleam@list:map( + _pipe@1, + fun(B) -> erlang:element(2, B) end + ), + gleam@set:from_list(_pipe@2) + end + ) + end + ). + +-spec below_blocks(gleam@dict:dict(integer(), gleam@set:set(integer()))) -> gleam@dict:dict(integer(), gleam@set:set(integer())). +below_blocks(Blocktree) -> + gleam@dict:fold( + Blocktree, + gleam@dict:new(), + fun(Acc, Block, _) -> + gleam@dict:update( + Acc, + Block, + fun(_) -> + _pipe = (gleam@dict:filter( + Blocktree, + fun(_, Aboves) -> gleam@set:contains(Aboves, Block) end + )), + _pipe@1 = gleam@dict:keys(_pipe), + gleam@set:from_list(_pipe@1) + end + ) + end + ). + +-spec vulnerable_blocks(gleam@dict:dict(integer(), gleam@set:set(integer()))) -> list(integer()). +vulnerable_blocks(Below_tree) -> + gleam@list:filter( + gleam@dict:keys(Below_tree), + fun(Block) -> + gleam@list:any( + gleam@dict:values(Below_tree), + fun(Bs) -> + not (gleam@set:size(Bs) =:= 0) andalso (gleam@set:size( + gleam@set:delete(Bs, Block) + ) + =:= 0) + end + ) + end + ). + +-spec part1(binary()) -> integer(). +part1(Input) -> + Settled_blocks = begin + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:index_map(_pipe@1, fun parse_block/2), + _pipe@3 = gleam@list:sort(_pipe@2, fun compare_blocks/2), + gleam@list:fold(_pipe@3, gleam@dict:new(), fun find_lowest_level/2) + end, + Block_positions = to_block_positions(Settled_blocks), + Above_blocks = above_blocks(Block_positions), + Below_blocks = below_blocks(Above_blocks), + Vulnerable_blocks = vulnerable_blocks(Below_blocks), + gleam@list:length(gleam@dict:keys(Block_positions)) - gleam@list:length( + Vulnerable_blocks + ). + +-spec do_falling_blocks( + gleam@set:set(integer()), + gleam@set:set(integer()), + gleam@dict:dict(integer(), gleam@set:set(integer())), + gleam@dict:dict(integer(), gleam@set:set(integer())) +) -> integer(). +do_falling_blocks(Fallen, Blocks, Above, Below) -> + gleam@bool:guard( + gleam@set:size(Blocks) =:= 0, + gleam@set:size(Fallen) - 1, + fun() -> + Blocks_above = begin + _pipe = (gleam@list:flat_map( + gleam@set:to_list(Blocks), + fun(Block) -> + _assert_subject = gleam@dict:get(Above, Block), + {ok, Supports} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day22/solve"/utf8>>, + function => <<"do_falling_blocks"/utf8>>, + line => 156}) + end, + gleam@list:filter( + gleam@set:to_list(Supports), + fun(Support) -> + _assert_subject@1 = gleam@dict:get( + Below, + Support + ), + {ok, Supportings} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error( + #{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day22/solve"/utf8>>, + function => <<"do_falling_blocks"/utf8>>, + line => 158} + ) + end, + gleam@list:all( + gleam@set:to_list(Supportings), + fun(Supporting) -> + gleam@set:contains(Fallen, Supporting) + end + ) + end + ) + end + )), + gleam@set:from_list(_pipe) + end, + _pipe@1 = gleam@set:union(Fallen, Blocks_above), + do_falling_blocks(_pipe@1, Blocks_above, Above, Below) + end + ). + +-spec all_falling_blocks( + integer(), + gleam@dict:dict(integer(), gleam@set:set(integer())), + gleam@dict:dict(integer(), gleam@set:set(integer())) +) -> integer(). +all_falling_blocks(N, Above, Below) -> + Starting_set = gleam@set:insert(gleam@set:new(), N), + do_falling_blocks(Starting_set, Starting_set, Above, Below). + +-spec part2(binary()) -> integer(). +part2(Input) -> + Settled_blocks = begin + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:index_map(_pipe@1, fun parse_block/2), + _pipe@3 = gleam@list:sort(_pipe@2, fun compare_blocks/2), + gleam@list:fold(_pipe@3, gleam@dict:new(), fun find_lowest_level/2) + end, + Block_positions = to_block_positions(Settled_blocks), + Above_blocks = above_blocks(Block_positions), + Below_blocks = below_blocks(Above_blocks), + Vulnerable_blocks = vulnerable_blocks(Below_blocks), + gleam@list:fold( + Vulnerable_blocks, + 0, + fun(Acc, B) -> + Acc + all_falling_blocks(B, Above_blocks, Below_blocks) + end + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day22/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 187}) + end, + _assert_subject@1 = adglent:get_input(<<"22"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day22/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 188}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache Binary files differnew file mode 100644 index 0000000..3a1c3d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache_meta Binary files differnew file mode 100644 index 0000000..128bc18 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.erl new file mode 100644 index 0000000..fe9d666 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@day23_test.erl @@ -0,0 +1,120 @@ +-module(day23@day23_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"#.##################### +#.......#########...### +#######.#########.#.### +###.....#.>.>.###.#.### +###v#####.#v#.###.#.### +###.>...#.#.#.....#...# +###v###.#.#.#########.# +###...#.#.#.......#...# +#####.#.#.#######.#.### +#.....#.#.#.......#...# +#.#####.#.#.#########v# +#.#...#...#...###...>.# +#.#.#v#######v###.###v# +#...#.>.#...>.>.#.###.# +#####v#.#.###v#.#.###.# +#.....#...#...#.#.#...# +#.#########.###.#.#.### +#...###...#...#...#.### +###.###.#.###v#####v### +#...#...#.#.>.>.#.>.### +#.###.###.#.###.#.#v### +#.....###...###...#...# +#####################.#"/utf8>>, + 94}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"#.##################### +#.......#########...### +#######.#########.#.### +###.....#.>.>.###.#.### +###v#####.#v#.###.#.### +###.>...#.#.#.....#...# +###v###.#.#.#########.# +###...#.#.#.......#...# +#####.#.#.#######.#.### +#.....#.#.#.......#...# +#.#####.#.#.#########v# +#.#...#...#...###...>.# +#.#.#v#######v###.###v# +#...#.>.#...>.>.#.###.# +#####v#.#.###v#.#.###.# +#.....#...#...#.#.#...# +#.#########.###.#.#.### +#...###...#...#...#.### +###.###.#.###v#####v### +#...#...#.#.>.>.#.>.### +#.###.###.#.###.#.#v### +#.....###...###...#...# +#####################.#"/utf8>>, + 94}], + fun(Example) -> _pipe@1 = day23@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"#.##################### +#.......#########...### +#######.#########.#.### +###.....#.>.>.###.#.### +###v#####.#v#.###.#.### +###.>...#.#.#.....#...# +###v###.#.#.#########.# +###...#.#.#.......#...# +#####.#.#.#######.#.### +#.....#.#.#.......#...# +#.#####.#.#.#########v# +#.#...#...#...###...>.# +#.#.#v#######v###.###v# +#...#.>.#...>.>.#.###.# +#####v#.#.###v#.#.###.# +#.....#...#...#.#.#...# +#.#########.###.#.#.### +#...###...#...#...#.### +###.###.#.###v#####v### +#...#...#.#.>.>.#.>.### +#.###.###.#.###.#.#v### +#.....###...###...#...# +#####################.#"/utf8>>, + 154}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"#.##################### +#.......#########...### +#######.#########.#.### +###.....#.>.>.###.#.### +###v#####.#v#.###.#.### +###.>...#.#.#.....#...# +###v###.#.#.#########.# +###...#.#.#.......#...# +#####.#.#.#######.#.### +#.....#.#.#.......#...# +#.#####.#.#.#########v# +#.#...#...#...###...>.# +#.#.#v#######v###.###v# +#...#.>.#...>.>.#.###.# +#####v#.#.###v#.#.###.# +#.....#...#...#.#.#...# +#.#########.###.#.#.### +#...###...#...#...#.### +###.###.#.###v#####v### +#...#...#.#.>.>.#.>.### +#.###.###.#.###.#.#v### +#.....###...###...#...# +#####################.#"/utf8>>, + 154}], + fun(Example) -> _pipe@1 = day23@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache Binary files differnew file mode 100644 index 0000000..55cbb25 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache_meta Binary files differnew file mode 100644 index 0000000..925bbea --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.erl new file mode 100644 index 0000000..8a57e88 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day23@solve.erl @@ -0,0 +1,337 @@ +-module(day23@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([path/0, route/0]). + +-type path() :: unknown | straight | junction. + +-type route() :: {route, utilities@array2d:posn(), integer()}. + +-spec append_to_key(gleam@option:option(list(RTF)), RTF) -> list(RTF). +append_to_key(V, New) -> + case V of + none -> + [New]; + + {some, Xs} -> + [New | Xs] + end. + +-spec first_parse_path(binary()) -> {ok, path()} | {error, nil}. +first_parse_path(C) -> + case C of + <<"#"/utf8>> -> + {error, nil}; + + _ -> + {ok, unknown} + end. + +-spec junction_neighbors(utilities@array2d:posn()) -> list(utilities@array2d:posn()). +junction_neighbors(P) -> + [erlang:setelement(2, P, erlang:element(2, P) + 1), + erlang:setelement(3, P, erlang:element(3, P) + 1)]. + +-spec mark_junctions(gleam@dict:dict(utilities@array2d:posn(), path())) -> gleam@dict:dict(utilities@array2d:posn(), path()). +mark_junctions(Trails) -> + gleam@dict:map_values( + Trails, + fun(Trail, _) -> + Valid_neighbors = begin + _pipe = Trail, + _pipe@1 = utilities@array2d:ortho_neighbors(_pipe), + gleam@list:filter( + _pipe@1, + fun(_capture) -> gleam@dict:has_key(Trails, _capture) end + ) + end, + case gleam@list:length(Valid_neighbors) of + 2 -> + straight; + + _ -> + junction + end + end + ). + +-spec walk_to_next_junction( + utilities@array2d:posn(), + utilities@array2d:posn(), + integer(), + gleam@set:set(utilities@array2d:posn()), + gleam@dict:dict(utilities@array2d:posn(), path()) +) -> {utilities@array2d:posn(), route()}. +walk_to_next_junction(Start, Current, Length, Seen, Trails) -> + _assert_subject = begin + _pipe = Current, + _pipe@1 = utilities@array2d:ortho_neighbors(_pipe), + gleam@list:filter( + _pipe@1, + fun(N) -> + gleam@dict:has_key(Trails, N) andalso not gleam@set:contains( + Seen, + N + ) + end + ) + end, + [Next] = case _assert_subject of + [_] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day23/solve"/utf8>>, + function => <<"walk_to_next_junction"/utf8>>, + line => 73}) + end, + case gleam@dict:get(Trails, Next) of + {ok, junction} -> + {Start, {route, Next, Length + 1}}; + + _ -> + Seen@1 = gleam@set:insert(Seen, Current), + walk_to_next_junction(Start, Next, (Length + 1), Seen@1, Trails) + end. + +-spec start_walking_to_next_junction( + utilities@array2d:posn(), + utilities@array2d:posn(), + gleam@dict:dict(utilities@array2d:posn(), path()) +) -> {utilities@array2d:posn(), route()}. +start_walking_to_next_junction(Start, Next, Trails) -> + Seen = begin + _pipe = gleam@set:new(), + _pipe@1 = gleam@set:insert(_pipe, Start), + gleam@set:insert(_pipe@1, Next) + end, + walk_to_next_junction(Start, Next, 1, Seen, Trails). + +-spec find_routes( + list(utilities@array2d:posn()), + gleam@dict:dict(utilities@array2d:posn(), path()) +) -> list({utilities@array2d:posn(), route()}). +find_routes(Junctions, Trails) -> + gleam@list:flat_map( + Junctions, + fun(Junction) -> + gleam@list:filter_map( + junction_neighbors(Junction), + fun(Neighbor) -> case gleam@dict:has_key(Trails, Neighbor) of + true -> + {ok, + start_walking_to_next_junction( + Junction, + Neighbor, + Trails + )}; + + false -> + {error, nil} + end end + ) + end + ). + +-spec generate_routes( + list(utilities@array2d:posn()), + gleam@dict:dict(utilities@array2d:posn(), path()) +) -> gleam@dict:dict(utilities@array2d:posn(), list(route())). +generate_routes(Junctions, Trails) -> + gleam@list:fold( + find_routes(Junctions, Trails), + gleam@dict:new(), + fun(Acc, _use1) -> + {From, Route} = _use1, + gleam@dict:update( + Acc, + From, + fun(_capture) -> append_to_key(_capture, Route) end + ) + end + ). + +-spec generate_2way_routes( + list(utilities@array2d:posn()), + gleam@dict:dict(utilities@array2d:posn(), path()) +) -> gleam@dict:dict(utilities@array2d:posn(), list(route())). +generate_2way_routes(Junctions, Trails) -> + gleam@list:fold( + find_routes(Junctions, Trails), + gleam@dict:new(), + fun(Acc, _use1) -> + {From, Route} = _use1, + _pipe = Acc, + _pipe@1 = gleam@dict:update( + _pipe, + From, + fun(_capture) -> append_to_key(_capture, Route) end + ), + gleam@dict:update( + _pipe@1, + erlang:element(2, Route), + fun(_capture@1) -> + append_to_key( + _capture@1, + {route, From, erlang:element(3, Route)} + ) + end + ) + end + ). + +-spec do_dfs( + gleam@dict:dict(utilities@array2d:posn(), list(route())), + utilities@array2d:posn(), + utilities@array2d:posn(), + integer(), + gleam@set:set(utilities@array2d:posn()) +) -> integer(). +do_dfs(Routes, From, To, Acc, Seen) -> + gleam@bool:guard( + To =:= From, + Acc, + fun() -> + _assert_subject = gleam@dict:get(Routes, From), + {ok, All_routes} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day23/solve"/utf8>>, + function => <<"do_dfs"/utf8>>, + line => 134}) + end, + Neighbors = gleam@list:filter( + All_routes, + fun(R) -> not gleam@set:contains(Seen, erlang:element(2, R)) end + ), + case Neighbors of + [] -> + 0; + + Neighbors@1 -> + gleam@list:fold( + Neighbors@1, + Acc, + fun(Inner_acc, N) -> + Score = do_dfs( + Routes, + erlang:element(2, N), + To, + Acc + erlang:element(3, N), + gleam@set:insert(Seen, erlang:element(2, N)) + ), + gleam@int:max(Score, Inner_acc) + end + ) + end + end + ). + +-spec dfs( + gleam@dict:dict(utilities@array2d:posn(), list(route())), + utilities@array2d:posn(), + utilities@array2d:posn() +) -> integer(). +dfs(Routes, From, To) -> + Seen = gleam@set:insert(gleam@set:new(), From), + do_dfs(Routes, From, To, 0, Seen). + +-spec solve_using( + binary(), + fun((list(utilities@array2d:posn()), gleam@dict:dict(utilities@array2d:posn(), path())) -> gleam@dict:dict(utilities@array2d:posn(), list(route()))) +) -> integer(). +solve_using(Input, Using) -> + Min_row = 0, + Max_row = gleam@list:length(gleam@string:split(Input, <<"\n"/utf8>>)) - 1, + Trails = begin + _pipe = Input, + _pipe@1 = utilities@array2d:parse_grid_using( + _pipe, + fun first_parse_path/1 + ), + mark_junctions(_pipe@1) + end, + Junctions = begin + _pipe@2 = Trails, + _pipe@3 = gleam@dict:filter(_pipe@2, fun(_, V) -> V =:= junction end), + gleam@dict:keys(_pipe@3) + end, + _assert_subject = gleam@list:find( + Junctions, + fun(J) -> erlang:element(2, J) =:= Min_row end + ), + {ok, Start} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day23/solve"/utf8>>, + function => <<"solve_using"/utf8>>, + line => 165}) + end, + _assert_subject@1 = gleam@list:find( + Junctions, + fun(J@1) -> erlang:element(2, J@1) =:= Max_row end + ), + {ok, End} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day23/solve"/utf8>>, + function => <<"solve_using"/utf8>>, + line => 166}) + end, + Routes = Using(Junctions, Trails), + dfs(Routes, Start, End). + +-spec part1(binary()) -> integer(). +part1(Input) -> + solve_using(Input, fun generate_routes/2). + +-spec part2(binary()) -> integer(). +part2(Input) -> + solve_using(Input, fun generate_2way_routes/2). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day23/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 182}) + end, + _assert_subject@1 = adglent:get_input(<<"23"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day23/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 183}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache Binary files differnew file mode 100644 index 0000000..60923b3 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache_meta Binary files differnew file mode 100644 index 0000000..6e09c6a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.erl new file mode 100644 index 0000000..693c962 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@day2_test.erl @@ -0,0 +1,54 @@ +-module(day2@day2_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"/utf8>>, + 8}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"/utf8>>, + 8}], + fun(Example) -> _pipe@1 = day2@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"/utf8>>, + 2286}, + {example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"/utf8>>, + 48}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"/utf8>>, + 2286}, + {example, + <<"Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"/utf8>>, + 48}], + fun(Example) -> _pipe@1 = day2@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache Binary files differnew file mode 100644 index 0000000..f550ee3 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache_meta Binary files differnew file mode 100644 index 0000000..b39c267 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.erl new file mode 100644 index 0000000..e7e3e63 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day2@solve.erl @@ -0,0 +1,166 @@ +-module(day2@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([game/0]). + +-type game() :: {game, integer(), integer(), integer()}. + +-spec parse(binary()) -> list(list(game())). +parse(Input) -> + gleam@list:map( + gleam@string:split(Input, <<"\n"/utf8>>), + fun(Line) -> + _assert_subject = gleam@string:split(Line, <<": "/utf8>>), + [_, Rounds] = case _assert_subject of + [_, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day2/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 13}) + end, + gleam@list:map( + gleam@string:split(Rounds, <<"; "/utf8>>), + fun(Match) -> + gleam@list:fold( + gleam@string:split(Match, <<", "/utf8>>), + {game, 0, 0, 0}, + fun(Acc, Draw) -> + _assert_subject@1 = gleam@string:split_once( + Draw, + <<" "/utf8>> + ), + {ok, {N_str, Color}} = case _assert_subject@1 of + {ok, {_, _}} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day2/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 19}) + end, + _assert_subject@2 = gleam@int:parse(N_str), + {ok, N} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day2/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 20}) + end, + case Color of + <<"red"/utf8>> -> + erlang:setelement(2, Acc, N); + + <<"blue"/utf8>> -> + erlang:setelement(3, Acc, N); + + <<"green"/utf8>> -> + erlang:setelement(4, Acc, N); + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"unrecognized color"/utf8>>, + module => <<"day2/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 25}) + end + end + ) + end + ) + end + ). + +-spec part1(binary()) -> integer(). +part1(Input) -> + gleam@list:index_fold( + parse(Input), + 0, + fun(Acc, Game, I) -> + case gleam@list:any( + Game, + fun(M) -> + ((erlang:element(2, M) > 12) orelse (erlang:element(4, M) > 13)) + orelse (erlang:element(3, M) > 14) + end + ) of + false -> + (Acc + I) + 1; + + true -> + Acc + end + end + ). + +-spec part2(binary()) -> integer(). +part2(Input) -> + _pipe = (gleam@list:map( + parse(Input), + fun(Game) -> + gleam@list:fold( + Game, + {game, 0, 0, 0}, + fun(Acc, Match) -> + {game, Red, Blue, Green} = Match, + {game, + gleam@int:max(Red, erlang:element(2, Acc)), + gleam@int:max(Blue, erlang:element(3, Acc)), + gleam@int:max(Green, erlang:element(4, Acc))} + end + ) + end + )), + gleam@list:fold( + _pipe, + 0, + fun(Acc@1, G) -> + Acc@1 + ((erlang:element(2, G) * erlang:element(3, G)) * erlang:element( + 4, + G + )) + end + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day2/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 54}) + end, + _assert_subject@1 = adglent:get_input(<<"2"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day2/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 55}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache Binary files differnew file mode 100644 index 0000000..49b0c33 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache_meta Binary files differnew file mode 100644 index 0000000..a5246d6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.erl new file mode 100644 index 0000000..33a8c22 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@day3_test.erl @@ -0,0 +1,68 @@ +-module(day3@day3_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.."/utf8>>, + 4361}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.."/utf8>>, + 4361}], + fun(Example) -> _pipe@1 = day3@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.."/utf8>>, + 467835}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.."/utf8>>, + 467835}], + fun(Example) -> _pipe@1 = day3@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache Binary files differnew file mode 100644 index 0000000..7024510 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache_meta Binary files differnew file mode 100644 index 0000000..8b7792a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.erl new file mode 100644 index 0000000..9082643 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day3@solve.erl @@ -0,0 +1,254 @@ +-module(day3@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([coord/0, symbol_kind/0, symbol/0, cell/0, part/0]). + +-type coord() :: {coord, integer(), integer()}. + +-type symbol_kind() :: gear | something_else. + +-type symbol() :: {number, integer()} | {symbol, symbol_kind()} | empty. + +-type cell() :: {cell, coord(), symbol()}. + +-type part() :: {part, list(coord()), integer()}. + +-spec to_symbol(binary()) -> symbol(). +to_symbol(C) -> + case {gleam@int:parse(C), C} of + {{ok, N}, _} -> + {number, N}; + + {_, <<"."/utf8>>} -> + empty; + + {_, <<"*"/utf8>>} -> + {symbol, gear}; + + {_, _} -> + {symbol, something_else} + end. + +-spec to_board(binary()) -> gleam@dict:dict(coord(), symbol()). +to_board(Input) -> + _pipe = (gleam@list:index_map( + gleam@string:split(Input, <<"\n"/utf8>>), + fun(Y, R) -> + gleam@list:index_map( + gleam@string:to_graphemes(R), + fun(X, C) -> {{coord, X, Y}, to_symbol(C)} end + ) + end + )), + _pipe@1 = gleam@list:flatten(_pipe), + gleam@dict:from_list(_pipe@1). + +-spec cell_compare(cell(), cell()) -> gleam@order:order(). +cell_compare(A, B) -> + case gleam@int:compare( + erlang:element(3, erlang:element(2, A)), + erlang:element(3, erlang:element(2, B)) + ) of + eq -> + gleam@int:compare( + erlang:element(2, erlang:element(2, A)), + erlang:element(2, erlang:element(2, B)) + ); + + Other -> + Other + end. + +-spec find_all_part_digits(gleam@dict:dict(coord(), symbol())) -> list(cell()). +find_all_part_digits(B) -> + _pipe = B, + _pipe@1 = gleam@dict:filter(_pipe, fun(_, V) -> case V of + {number, _} -> + true; + + _ -> + false + end end), + _pipe@2 = gleam@dict:to_list(_pipe@1), + _pipe@3 = gleam@list:map( + _pipe@2, + fun(Tup) -> {cell, erlang:element(1, Tup), erlang:element(2, Tup)} end + ), + gleam@list:sort(_pipe@3, fun cell_compare/2). + +-spec do_parts(list(cell()), list(part())) -> list(part()). +do_parts(Cells, Parts) -> + case Cells of + [] -> + Parts; + + [{cell, Next, {number, N}} | T] -> + case Parts of + [] -> + do_parts(T, [{part, [Next], N} | Parts]); + + [{part, [Prev | _] = Coords, N0} | Rest_parts] -> + case {(erlang:element(2, Next) - erlang:element(2, Prev)), + (erlang:element(3, Next) - erlang:element(3, Prev))} of + {1, 0} -> + do_parts( + T, + [{part, [Next | Coords], (N0 * 10) + N} | + Rest_parts] + ); + + {_, _} -> + do_parts(T, [{part, [Next], N} | Parts]) + end; + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"day3/solve"/utf8>>, + function => <<"do_parts"/utf8>>, + line => 90}) + end; + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"panic expression evaluated"/utf8>>, + module => <<"day3/solve"/utf8>>, + function => <<"do_parts"/utf8>>, + line => 93}) + end. + +-spec to_parts(list(cell())) -> list(part()). +to_parts(Cells) -> + do_parts(Cells, []). + +-spec all_neighbors(coord()) -> list(coord()). +all_neighbors(C) -> + gleam@list:flat_map( + [-1, 0, 1], + fun(Dx) -> gleam@list:filter_map([-1, 0, 1], fun(Dy) -> case {Dx, Dy} of + {0, 0} -> + {error, nil}; + + {_, _} -> + {ok, + {coord, + erlang:element(2, C) + Dx, + erlang:element(3, C) + Dy}} + end end) end + ). + +-spec sum_valid_parts(integer(), part(), gleam@dict:dict(coord(), symbol())) -> integer(). +sum_valid_parts(Acc, Part, Board) -> + Neighbors = begin + _pipe = erlang:element(2, Part), + _pipe@1 = gleam@list:flat_map(_pipe, fun all_neighbors/1), + gleam@list:unique(_pipe@1) + end, + Sym = [{ok, {symbol, gear}}, {ok, {symbol, something_else}}], + case gleam@list:any( + Neighbors, + fun(C) -> gleam@list:contains(Sym, gleam@dict:get(Board, C)) end + ) of + true -> + Acc + erlang:element(3, Part); + + false -> + Acc + end. + +-spec part1(binary()) -> integer(). +part1(Input) -> + Board = to_board(Input), + _pipe = Board, + _pipe@1 = find_all_part_digits(_pipe), + _pipe@2 = to_parts(_pipe@1), + gleam@list:fold( + _pipe@2, + 0, + fun(Acc, P) -> sum_valid_parts(Acc, P, Board) end + ). + +-spec to_part_with_neighbors(part()) -> part(). +to_part_with_neighbors(Part) -> + _pipe = erlang:element(2, Part), + _pipe@1 = gleam@list:flat_map(_pipe, fun all_neighbors/1), + _pipe@2 = gleam@list:unique(_pipe@1), + {part, _pipe@2, erlang:element(3, Part)}. + +-spec find_part_numbers_near_gear(coord(), list(part())) -> list(integer()). +find_part_numbers_near_gear(Gear, Parts) -> + gleam@list:filter_map( + Parts, + fun(Part) -> case gleam@list:contains(erlang:element(2, Part), Gear) of + true -> + {ok, erlang:element(3, Part)}; + + false -> + {error, nil} + end end + ). + +-spec to_sum_of_gear_ratios(list(list(integer()))) -> integer(). +to_sum_of_gear_ratios(Adjacent_parts) -> + gleam@list:fold(Adjacent_parts, 0, fun(Acc, Ps) -> case Ps of + [P1, P2] -> + Acc + (P1 * P2); + + _ -> + Acc + end end). + +-spec part2(binary()) -> integer(). +part2(Input) -> + Board = to_board(Input), + Parts = begin + _pipe = Board, + _pipe@1 = find_all_part_digits(_pipe), + _pipe@2 = to_parts(_pipe@1), + gleam@list:map(_pipe@2, fun to_part_with_neighbors/1) + end, + _pipe@3 = Board, + _pipe@4 = gleam@dict:filter(_pipe@3, fun(_, V) -> V =:= {symbol, gear} end), + _pipe@5 = gleam@dict:keys(_pipe@4), + _pipe@6 = gleam@list:map( + _pipe@5, + fun(_capture) -> find_part_numbers_near_gear(_capture, Parts) end + ), + to_sum_of_gear_ratios(_pipe@6). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day3/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 168}) + end, + _assert_subject@1 = adglent:get_input(<<"3"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day3/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 169}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache Binary files differnew file mode 100644 index 0000000..4c2e06a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache_meta Binary files differnew file mode 100644 index 0000000..98d2944 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.erl new file mode 100644 index 0000000..b739e61 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@day4_test.erl @@ -0,0 +1,52 @@ +-module(day4@day4_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"/utf8>>, + 13}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"/utf8>>, + 13}], + fun(Example) -> _pipe@1 = day4@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"/utf8>>, + 30}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 +Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 +Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 +Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 +Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 +Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"/utf8>>, + 30}], + fun(Example) -> _pipe@1 = day4@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache Binary files differnew file mode 100644 index 0000000..af204ff --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache_meta Binary files differnew file mode 100644 index 0000000..1db4b46 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.erl new file mode 100644 index 0000000..7cc0186 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day4@solve.erl @@ -0,0 +1,169 @@ +-module(day4@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([card/0]). + +-type card() :: {card, integer(), integer()}. + +-spec numbers_to_set(binary()) -> gleam@set:set(integer()). +numbers_to_set(Str) -> + _pipe = Str, + _pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun gleam@int:parse/1), + _pipe@3 = gleam@result:values(_pipe@2), + gleam@set:from_list(_pipe@3). + +-spec parse_card(binary()) -> card(). +parse_card(Card) -> + _assert_subject = gleam@string:split_once(Card, <<": "/utf8>>), + {ok, {<<"Card"/utf8, N_str/binary>>, Rest}} = case _assert_subject of + {ok, {<<"Card"/utf8, _/binary>>, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day4/solve"/utf8>>, + function => <<"parse_card"/utf8>>, + line => 25}) + end, + _assert_subject@1 = gleam@string:split_once(Rest, <<" | "/utf8>>), + {ok, {Winning_str, Has_str}} = case _assert_subject@1 of + {ok, {_, _}} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day4/solve"/utf8>>, + function => <<"parse_card"/utf8>>, + line => 26}) + end, + _assert_subject@2 = gleam@int:parse(gleam@string:trim(N_str)), + {ok, N} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day4/solve"/utf8>>, + function => <<"parse_card"/utf8>>, + line => 27}) + end, + Winning = numbers_to_set(Winning_str), + Has = numbers_to_set(Has_str), + Winners = gleam@set:size(gleam@set:intersection(Winning, Has)), + {card, N, Winners}. + +-spec win_points(integer()) -> integer(). +win_points(N) -> + gleam@bool:guard(N < 2, N, fun() -> 2 * win_points(N - 1) end). + +-spec part1(binary()) -> integer(). +part1(Input) -> + gleam@list:fold( + gleam@string:split(Input, <<"\n"/utf8>>), + 0, + fun(Acc, C) -> _pipe = C, + _pipe@1 = parse_card(_pipe), + _pipe@2 = (fun(C@1) -> win_points(erlang:element(3, C@1)) end)( + _pipe@1 + ), + gleam@int:add(_pipe@2, Acc) end + ). + +-spec update_counts(integer(), card(), gleam@dict:dict(integer(), integer())) -> gleam@dict:dict(integer(), integer()). +update_counts(N, Card, Count) -> + _assert_subject = gleam@dict:get(Count, erlang:element(2, Card)), + {ok, Bonus} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day4/solve"/utf8>>, + function => <<"update_counts"/utf8>>, + line => 65}) + end, + gleam@list:fold( + gleam@list:range( + erlang:element(2, Card) + 1, + erlang:element(2, Card) + N + ), + Count, + fun(Acc, N@1) -> gleam@dict:update(Acc, N@1, fun(C) -> case C of + {some, I} -> + I + Bonus; + + none -> + erlang:error(#{gleam_error => panic, + message => <<"won a card that doesn't exist in the card pile"/utf8>>, + module => <<"day4/solve"/utf8>>, + function => <<"update_counts"/utf8>>, + line => 70}) + end end) end + ). + +-spec win_more_cards(list(binary()), gleam@dict:dict(integer(), integer())) -> integer(). +win_more_cards(Cards, Count) -> + case Cards of + [] -> + _pipe = Count, + _pipe@1 = gleam@dict:values(_pipe), + gleam@int:sum(_pipe@1); + + [Raw_card | Rest] -> + Card = parse_card(Raw_card), + case erlang:element(3, Card) of + 0 -> + win_more_cards(Rest, Count); + + N -> + win_more_cards(Rest, update_counts(N, Card, Count)) + end + end. + +-spec part2(binary()) -> integer(). +part2(Input) -> + Cards = gleam@string:split(Input, <<"\n"/utf8>>), + Count = begin + _pipe = gleam@list:range(1, gleam@list:length(Cards)), + _pipe@1 = gleam@list:map(_pipe, fun(N) -> {N, 1} end), + gleam@dict:from_list(_pipe@1) + end, + win_more_cards(Cards, Count). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day4/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 86}) + end, + _assert_subject@1 = adglent:get_input(<<"4"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day4/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 87}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache Binary files differnew file mode 100644 index 0000000..07488c8 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache_meta Binary files differnew file mode 100644 index 0000000..0ca1b7d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.erl new file mode 100644 index 0000000..170eddd --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@day5_test.erl @@ -0,0 +1,160 @@ +-module(day5@day5_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4"/utf8>>, + <<"35"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4"/utf8>>, + <<"35"/utf8>>}], + fun(Example) -> _pipe@1 = day5@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4"/utf8>>, + <<"46"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"seeds: 79 14 55 13 + +seed-to-soil map: +50 98 2 +52 50 48 + +soil-to-fertilizer map: +0 15 37 +37 52 2 +39 0 15 + +fertilizer-to-water map: +49 53 8 +0 11 42 +42 0 7 +57 7 4 + +water-to-light map: +88 18 7 +18 25 70 + +light-to-temperature map: +45 77 23 +81 45 19 +68 64 13 + +temperature-to-humidity map: +0 69 1 +1 0 69 + +humidity-to-location map: +60 56 37 +56 93 4"/utf8>>, + <<"46"/utf8>>}], + fun(Example) -> _pipe@1 = day5@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache Binary files differnew file mode 100644 index 0000000..22ec6e4 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache_meta Binary files differnew file mode 100644 index 0000000..2e8355d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.erl new file mode 100644 index 0000000..5bb23ee --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day5@solve.erl @@ -0,0 +1,269 @@ +-module(day5@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([almanac/0, mapping_range/0, seed_range/0]). + +-type almanac() :: {almanac, list(integer()), list(list(mapping_range()))}. + +-type mapping_range() :: {m_range, integer(), integer(), integer()}. + +-type seed_range() :: {s_range, integer(), integer()}. + +-spec string_to_int_list(binary()) -> list(integer()). +string_to_int_list(Str) -> + _pipe = Str, + _pipe@1 = gleam@string:split(_pipe, <<" "/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun gleam@int:parse/1), + gleam@result:values(_pipe@2). + +-spec parse_mrange(binary()) -> mapping_range(). +parse_mrange(Str) -> + _assert_subject = string_to_int_list(Str), + [Destination, Source, Range_width] = case _assert_subject of + [_, _, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day5/solve"/utf8>>, + function => <<"parse_mrange"/utf8>>, + line => 55}) + end, + {m_range, Source, (Source + Range_width) - 1, Destination - Source}. + +-spec parse_mapper(list(binary())) -> list(mapping_range()). +parse_mapper(Strs) -> + [_ | Raw_ranges] = case Strs of + [_ | _] -> Strs; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day5/solve"/utf8>>, + function => <<"parse_mapper"/utf8>>, + line => 49}) + end, + _pipe = gleam@list:map(Raw_ranges, fun parse_mrange/1), + gleam@list:sort( + _pipe, + fun(A, B) -> + gleam@int:compare(erlang:element(2, A), erlang:element(2, B)) + end + ). + +-spec parse_input(binary()) -> almanac(). +parse_input(Input) -> + _assert_subject = gleam@string:split(Input, <<"\n\n"/utf8>>), + [<<"seeds: "/utf8, Raw_seeds/binary>> | Raw_mappers] = case _assert_subject of + [<<"seeds: "/utf8, _/binary>> | _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day5/solve"/utf8>>, + function => <<"parse_input"/utf8>>, + line => 29}) + end, + Seeds = string_to_int_list(Raw_seeds), + Mappers = gleam@list:map( + Raw_mappers, + gleam@function:compose( + fun(_capture) -> gleam@string:split(_capture, <<"\n"/utf8>>) end, + fun parse_mapper/1 + ) + ), + {almanac, Seeds, Mappers}. + +-spec correspond(integer(), list(mapping_range())) -> integer(). +correspond(N, Mapper) -> + gleam@list:fold_until( + Mapper, + N, + fun(Acc, Mrange) -> + case (erlang:element(2, Mrange) =< Acc) andalso (Acc =< erlang:element( + 3, + Mrange + )) of + true -> + {stop, Acc + erlang:element(4, Mrange)}; + + false -> + {continue, Acc} + end + end + ). + +-spec part1(binary()) -> binary(). +part1(Input) -> + {almanac, Seeds, Mappers} = parse_input(Input), + _pipe = gleam@list:map( + Seeds, + fun(_capture) -> + gleam@list:fold(Mappers, _capture, fun correspond/2) + end + ), + _pipe@1 = gleam@list:reduce(_pipe, fun gleam@int:min/2), + _pipe@2 = gleam@result:unwrap(_pipe@1, 0), + gleam@string:inspect(_pipe@2). + +-spec transform_range(seed_range(), mapping_range()) -> seed_range(). +transform_range(R, Mapper) -> + {s_range, + erlang:element(2, R) + erlang:element(4, Mapper), + erlang:element(3, R) + erlang:element(4, Mapper)}. + +-spec do_remap_range(seed_range(), list(mapping_range()), list(seed_range())) -> list(seed_range()). +do_remap_range(R, Mapper, Acc) -> + case Mapper of + [] -> + [R | Acc]; + + [M | _] when erlang:element(3, R) < erlang:element(2, M) -> + [R | Acc]; + + [M@1 | Ms] when erlang:element(2, R) > erlang:element(3, M@1) -> + do_remap_range(R, Ms, Acc); + + [M@2 | _] when (erlang:element(2, R) >= erlang:element(2, M@2)) andalso (erlang:element( + 3, + R + ) =< erlang:element(3, M@2)) -> + [transform_range(R, M@2) | Acc]; + + [M@3 | _] when (erlang:element(2, R) < erlang:element(2, M@3)) andalso (erlang:element( + 3, + R + ) =< erlang:element(3, M@3)) -> + [{s_range, erlang:element(2, R), erlang:element(2, M@3) - 1}, + transform_range( + {s_range, erlang:element(2, M@3), erlang:element(3, R)}, + M@3 + ) | + Acc]; + + [M@4 | Ms@1] when (erlang:element(2, R) >= erlang:element(2, M@4)) andalso (erlang:element( + 3, + R + ) > erlang:element(3, M@4)) -> + do_remap_range( + {s_range, erlang:element(3, M@4) + 1, erlang:element(3, R)}, + Ms@1, + [transform_range( + {s_range, erlang:element(2, R), erlang:element(3, M@4)}, + M@4 + ) | + Acc] + ); + + [M@5 | Ms@2] -> + do_remap_range( + {s_range, erlang:element(3, M@5) + 1, erlang:element(3, R)}, + Ms@2, + [{s_range, erlang:element(2, R), erlang:element(2, M@5) - 1}, + transform_range( + {s_range, + erlang:element(2, M@5), + erlang:element(3, M@5)}, + M@5 + ) | + Acc] + ) + end. + +-spec remap_range(seed_range(), list(mapping_range())) -> list(seed_range()). +remap_range(R, Mapper) -> + do_remap_range(R, Mapper, []). + +-spec remap_all_seed_ranges(list(seed_range()), list(list(mapping_range()))) -> list(seed_range()). +remap_all_seed_ranges(Srs, Mappers) -> + case Mappers of + [] -> + Srs; + + [Mapper | Rest] -> + _pipe = gleam@list:flat_map( + Srs, + fun(_capture) -> remap_range(_capture, Mapper) end + ), + remap_all_seed_ranges(_pipe, Rest) + end. + +-spec part2(binary()) -> binary(). +part2(Input) -> + {almanac, Seeds, Mappers} = parse_input(Input), + _assert_subject = begin + _pipe = Seeds, + _pipe@1 = gleam@list:sized_chunk(_pipe, 2), + _pipe@3 = gleam@list:map( + _pipe@1, + fun(Chunk) -> + [Start, Length] = case Chunk of + [_, _] -> Chunk; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day5/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 87}) + end, + _pipe@2 = [{s_range, Start, (Start + Length) - 1}], + remap_all_seed_ranges(_pipe@2, Mappers) + end + ), + _pipe@4 = gleam@list:flatten(_pipe@3), + gleam@list:sort( + _pipe@4, + fun(A, B) -> + gleam@int:compare(erlang:element(2, A), erlang:element(2, B)) + end + ) + end, + [{s_range, Answer, _} | _] = case _assert_subject of + [{s_range, _, _} | _] -> _assert_subject; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day5/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 83}) + end, + gleam@string:inspect(Answer). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day5/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 150}) + end, + _assert_subject@1 = adglent:get_input(<<"5"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day5/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 151}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache Binary files differnew file mode 100644 index 0000000..1b29ca0 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache_meta Binary files differnew file mode 100644 index 0000000..6ae533d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.erl new file mode 100644 index 0000000..9e02cea --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@day6_test.erl @@ -0,0 +1,36 @@ +-module(day6@day6_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"Time: 7 15 30 +Distance: 9 40 200"/utf8>>, + <<"288"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Time: 7 15 30 +Distance: 9 40 200"/utf8>>, + <<"288"/utf8>>}], + fun(Example) -> _pipe@1 = day6@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"Time: 7 15 30 +Distance: 9 40 200"/utf8>>, + <<"71503"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"Time: 7 15 30 +Distance: 9 40 200"/utf8>>, + <<"71503"/utf8>>}], + fun(Example) -> _pipe@1 = day6@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache Binary files differnew file mode 100644 index 0000000..2a735ee --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache_meta Binary files differnew file mode 100644 index 0000000..e1a7797 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.erl new file mode 100644 index 0000000..6f70ab5 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day6@solve.erl @@ -0,0 +1,131 @@ +-module(day6@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([race/0]). + +-type race() :: {race, integer(), integer()}. + +-spec parse_with_bad_kerning(binary()) -> list(race()). +parse_with_bad_kerning(Input) -> + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@5 = gleam@list:map(_pipe@1, fun(Str) -> _pipe@2 = Str, + _pipe@3 = gleam@string:split(_pipe@2, <<" "/utf8>>), + _pipe@4 = gleam@list:map(_pipe@3, fun gleam@int:parse/1), + gleam@result:values(_pipe@4) end), + _pipe@6 = gleam@list:transpose(_pipe@5), + gleam@list:map( + _pipe@6, + fun(Ns) -> + [T, D] = case Ns of + [_, _] -> Ns; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day6/solve"/utf8>>, + function => <<"parse_with_bad_kerning"/utf8>>, + line => 23}) + end, + {race, T, D} + end + ). + +-spec find_bound(race(), integer(), integer()) -> integer(). +find_bound(Race, Button_time, Step) -> + Travel_time = erlang:element(2, Race) - Button_time, + case (Button_time * Travel_time) > erlang:element(3, Race) of + true -> + Button_time; + + false -> + find_bound(Race, Button_time + Step, Step) + end. + +-spec lower_bound(race()) -> integer(). +lower_bound(Race) -> + find_bound(Race, 1, 1). + +-spec upper_bound(race()) -> integer(). +upper_bound(Race) -> + find_bound(Race, erlang:element(2, Race), -1). + +-spec part1(binary()) -> binary(). +part1(Input) -> + _pipe = (gleam@list:fold( + parse_with_bad_kerning(Input), + 1, + fun(Acc, Race) -> + Acc * ((upper_bound(Race) - lower_bound(Race)) + 1) + end + )), + gleam@string:inspect(_pipe). + +-spec parse_properly(binary()) -> list(integer()). +parse_properly(Input) -> + _pipe = Input, + _pipe@1 = gleam@string:replace(_pipe, <<" "/utf8>>, <<""/utf8>>), + _pipe@2 = gleam@string:split(_pipe@1, <<"\n"/utf8>>), + _pipe@3 = gleam@list:flat_map( + _pipe@2, + fun(_capture) -> gleam@string:split(_capture, <<":"/utf8>>) end + ), + _pipe@4 = gleam@list:map(_pipe@3, fun gleam@int:parse/1), + gleam@result:values(_pipe@4). + +-spec part2(binary()) -> binary(). +part2(Input) -> + _assert_subject = begin + _pipe = Input, + parse_properly(_pipe) + end, + [Time, Distance] = case _assert_subject of + [_, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day6/solve"/utf8>>, + function => <<"part2"/utf8>>, + line => 62}) + end, + Race = {race, Time, Distance}, + _pipe@1 = (upper_bound(Race) - lower_bound(Race)) + 1, + gleam@string:inspect(_pipe@1). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day6/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 73}) + end, + _assert_subject@1 = adglent:get_input(<<"6"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day6/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 74}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache Binary files differnew file mode 100644 index 0000000..d4830bb --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache_meta Binary files differnew file mode 100644 index 0000000..f63dc34 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.erl new file mode 100644 index 0000000..57e4a29 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@day7_test.erl @@ -0,0 +1,48 @@ +-module(day7@day7_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483"/utf8>>, + <<"6440"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483"/utf8>>, + <<"6440"/utf8>>}], + fun(Example) -> _pipe@1 = day7@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483"/utf8>>, + <<"5905"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483"/utf8>>, + <<"5905"/utf8>>}], + fun(Example) -> _pipe@1 = day7@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache Binary files differnew file mode 100644 index 0000000..9d72fb4 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache_meta Binary files differnew file mode 100644 index 0000000..ff45788 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.erl new file mode 100644 index 0000000..d6bf6aa --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day7@solve.erl @@ -0,0 +1,242 @@ +-module(day7@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([hand/0]). + +-type hand() :: {hand, list(integer()), integer()}. + +-spec card_counts(hand()) -> list(integer()). +card_counts(Hand) -> + _pipe = erlang:element(2, Hand), + _pipe@1 = gleam@list:sort(_pipe, fun gleam@int:compare/2), + _pipe@2 = gleam@list:chunk(_pipe@1, fun gleam@function:identity/1), + _pipe@3 = gleam@list:map(_pipe@2, fun gleam@list:length/1), + gleam@list:sort(_pipe@3, fun gleam@int:compare/2). + +-spec classify_hand(hand()) -> integer(). +classify_hand(Hand) -> + case {gleam@list:length(gleam@list:unique(erlang:element(2, Hand))), + card_counts(Hand)} of + {1, _} -> + 8; + + {2, [1, 4]} -> + 7; + + {2, [2, 3]} -> + 6; + + {3, [1, 1, 3]} -> + 5; + + {3, [1, 2, 2]} -> + 4; + + {4, _} -> + 3; + + {5, _} -> + 2; + + {_, _} -> + 1 + end. + +-spec card_rank(binary()) -> integer(). +card_rank(Card) -> + case {gleam@int:parse(Card), Card} of + {{ok, N}, _} -> + N; + + {_, <<"A"/utf8>>} -> + 14; + + {_, <<"K"/utf8>>} -> + 13; + + {_, <<"Q"/utf8>>} -> + 12; + + {_, <<"J"/utf8>>} -> + 11; + + {_, <<"T"/utf8>>} -> + 10; + + {_, _} -> + 1 + end. + +-spec parse_hand(binary()) -> hand(). +parse_hand(Str) -> + _assert_subject = gleam@string:split(Str, <<" "/utf8>>), + [Cards, Wager] = case _assert_subject of + [_, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day7/solve"/utf8>>, + function => <<"parse_hand"/utf8>>, + line => 19}) + end, + Cards@1 = begin + _pipe = gleam@string:to_graphemes(Cards), + gleam@list:map(_pipe, fun card_rank/1) + end, + _assert_subject@1 = gleam@int:parse(Wager), + {ok, Wager@1} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day7/solve"/utf8>>, + function => <<"parse_hand"/utf8>>, + line => 23}) + end, + {hand, Cards@1, Wager@1}. + +-spec compare_top_card(list(integer()), list(integer())) -> gleam@order:order(). +compare_top_card(Cards1, Cards2) -> + gleam@bool:guard( + (Cards1 =:= []) orelse (Cards2 =:= []), + eq, + fun() -> + [C1 | Rest1] = case Cards1 of + [_ | _] -> Cards1; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day7/solve"/utf8>>, + function => <<"compare_top_card"/utf8>>, + line => 70}) + end, + [C2 | Rest2] = case Cards2 of + [_ | _] -> Cards2; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day7/solve"/utf8>>, + function => <<"compare_top_card"/utf8>>, + line => 71}) + end, + case gleam@int:compare(C1, C2) of + eq -> + compare_top_card(Rest1, Rest2); + + Other -> + Other + end + end + ). + +-spec compare_hands(hand(), hand(), fun((hand()) -> integer())) -> gleam@order:order(). +compare_hands(Hand1, Hand2, Using) -> + case gleam@int:compare(Using(Hand1), Using(Hand2)) of + eq -> + compare_top_card(erlang:element(2, Hand1), erlang:element(2, Hand2)); + + Other -> + Other + end. + +-spec part(binary(), fun((hand(), hand()) -> gleam@order:order())) -> binary(). +part(Input, Comparator) -> + _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + _pipe@2 = gleam@list:map(_pipe@1, fun parse_hand/1), + _pipe@3 = gleam@list:sort(_pipe@2, Comparator), + _pipe@4 = gleam@list:index_map( + _pipe@3, + fun(I, H) -> (I + 1) * erlang:element(3, H) end + ), + _pipe@5 = gleam@int:sum(_pipe@4), + gleam@string:inspect(_pipe@5). + +-spec compare_without_wilds(hand(), hand()) -> gleam@order:order(). +compare_without_wilds(Hand1, Hand2) -> + compare_hands(Hand1, Hand2, fun classify_hand/1). + +-spec part1(binary()) -> binary(). +part1(Input) -> + part(Input, fun compare_without_wilds/2). + +-spec find_best_joker_substitution(hand()) -> hand(). +find_best_joker_substitution(Hand) -> + gleam@list:fold( + gleam@list:range(2, 14), + {hand, [], 0}, + fun(Acc, Card) -> + Subbed_cards = (gleam@list:map( + erlang:element(2, Hand), + fun(C) -> case C of + 1 -> + Card; + + Other -> + Other + end end + )), + Subbed_hand = erlang:setelement(2, Hand, Subbed_cards), + case compare_hands(Acc, Subbed_hand, fun classify_hand/1) of + lt -> + Subbed_hand; + + _ -> + Acc + end + end + ). + +-spec compare_hands_considering_jokers(hand(), hand()) -> gleam@order:order(). +compare_hands_considering_jokers(Hand1, Hand2) -> + compare_hands(Hand1, Hand2, fun(Hand) -> _pipe = Hand, + _pipe@1 = find_best_joker_substitution(_pipe), + classify_hand(_pipe@1) end). + +-spec part2(binary()) -> binary(). +part2(Input) -> + part( + gleam@string:replace(Input, <<"J"/utf8>>, <<"*"/utf8>>), + fun compare_hands_considering_jokers/2 + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day7/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 128}) + end, + _assert_subject@1 = adglent:get_input(<<"7"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day7/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 129}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache Binary files differnew file mode 100644 index 0000000..3d89b8b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache_meta Binary files differnew file mode 100644 index 0000000..4082d33 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.erl new file mode 100644 index 0000000..b3e591d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@day8_test.erl @@ -0,0 +1,58 @@ +-module(day8@day8_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ)"/utf8>>, + 6}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ)"/utf8>>, + 6}], + fun(Example) -> _pipe@1 = day8@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"LR + +11A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX)"/utf8>>, + 6}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"LR + +11A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX)"/utf8>>, + 6}], + fun(Example) -> _pipe@1 = day8@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache Binary files differnew file mode 100644 index 0000000..a03967b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache_meta Binary files differnew file mode 100644 index 0000000..4389637 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.erl new file mode 100644 index 0000000..30c5133 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day8@solve.erl @@ -0,0 +1,179 @@ +-module(day8@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). +-export_type([paths/0]). + +-type paths() :: {paths, binary(), binary()}. + +-spec parse(binary()) -> {gleam@iterator:iterator(binary()), + gleam@dict:dict(binary(), paths())}. +parse(Input) -> + _assert_subject = gleam@string:split(Input, <<"\n\n"/utf8>>), + [Directions_str, Maze_str] = case _assert_subject of + [_, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day8/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 20}) + end, + Directions = begin + _pipe = Directions_str, + _pipe@1 = gleam@string:to_graphemes(_pipe), + _pipe@2 = gleam@iterator:from_list(_pipe@1), + gleam@iterator:cycle(_pipe@2) + end, + _assert_subject@1 = gleam@regex:from_string( + <<"(...) = \\((...), (...)\\)"/utf8>> + ), + {ok, Re} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day8/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 28}) + end, + Maze = begin + _pipe@3 = Maze_str, + _pipe@4 = gleam@string:split(_pipe@3, <<"\n"/utf8>>), + _pipe@5 = gleam@list:map( + _pipe@4, + fun(Str) -> + _assert_subject@2 = gleam@regex:scan(Re, Str), + [{match, _, [{some, Name}, {some, Left}, {some, Right}]}] = case _assert_subject@2 of + [{match, _, [{some, _}, {some, _}, {some, _}]}] -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"day8/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 33}) + end, + {Name, {paths, Left, Right}} + end + ), + gleam@dict:from_list(_pipe@5) + end, + {Directions, Maze}. + +-spec to_next_step( + binary(), + binary(), + integer(), + gleam@iterator:iterator(binary()), + gleam@dict:dict(binary(), paths()) +) -> integer(). +to_next_step(Current, Stop_at, Count, Directions, Maze) -> + gleam@bool:guard( + gleam@string:ends_with(Current, Stop_at), + Count, + fun() -> + _assert_subject = gleam@iterator:step(Directions), + {next, Next_direction, Rest_directions} = case _assert_subject of + {next, _, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day8/solve"/utf8>>, + function => <<"to_next_step"/utf8>>, + line => 50}) + end, + _assert_subject@1 = gleam@dict:get(Maze, Current), + {ok, Paths} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day8/solve"/utf8>>, + function => <<"to_next_step"/utf8>>, + line => 51}) + end, + _pipe = case Next_direction of + <<"L"/utf8>> -> + erlang:element(2, Paths); + + <<"R"/utf8>> -> + erlang:element(3, Paths); + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"bad direction"/utf8>>, + module => <<"day8/solve"/utf8>>, + function => <<"to_next_step"/utf8>>, + line => 55}) + end, + to_next_step(_pipe, Stop_at, Count + 1, Rest_directions, Maze) + end + ). + +-spec part1(binary()) -> integer(). +part1(Input) -> + {Directions, Maze} = parse(Input), + to_next_step(<<"AAA"/utf8>>, <<"ZZZ"/utf8>>, 0, Directions, Maze). + +-spec part2(binary()) -> integer(). +part2(Input) -> + {Directions, Maze} = parse(Input), + gleam@list:fold( + gleam@dict:keys(Maze), + 1, + fun(Acc, Name) -> case gleam@string:ends_with(Name, <<"A"/utf8>>) of + false -> + Acc; + + true -> + _pipe = to_next_step( + Name, + <<"Z"/utf8>>, + 0, + Directions, + Maze + ), + gleam_community@maths@arithmetics:lcm(_pipe, Acc) + end end + ). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day8/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 79}) + end, + _assert_subject@1 = adglent:get_input(<<"8"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day8/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 80}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache Binary files differnew file mode 100644 index 0000000..32b4cd1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache_meta Binary files differnew file mode 100644 index 0000000..6e5f636 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.erl new file mode 100644 index 0000000..9532be7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@day9_test.erl @@ -0,0 +1,40 @@ +-module(day9@day9_test). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1_test/0, part2_test/0]). + +-spec part1_test() -> list(nil). +part1_test() -> + _pipe = [{example, + <<"0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45"/utf8>>, + <<"114"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45"/utf8>>, + <<"114"/utf8>>}], + fun(Example) -> _pipe@1 = day9@solve:part1(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). + +-spec part2_test() -> list(nil). +part2_test() -> + _pipe = [{example, + <<"0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45"/utf8>>, + <<"2"/utf8>>}], + showtime@tests@should:not_equal(_pipe, []), + gleam@list:map( + [{example, + <<"0 3 6 9 12 15 +1 3 6 10 15 21 +10 13 16 21 30 45"/utf8>>, + <<"2"/utf8>>}], + fun(Example) -> _pipe@1 = day9@solve:part2(erlang:element(2, Example)), + showtime@tests@should:equal(_pipe@1, erlang:element(3, Example)) end + ). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache Binary files differnew file mode 100644 index 0000000..afd006e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache_meta Binary files differnew file mode 100644 index 0000000..7875518 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.erl new file mode 100644 index 0000000..87cd9f7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/day9@solve.erl @@ -0,0 +1,133 @@ +-module(day9@solve). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([part1/1, part2/1, main/0]). + +-spec maybe_backwards(list(SLN), boolean()) -> list(SLN). +maybe_backwards(Xs, Backwards) -> + case Backwards of + false -> + gleam@list:reverse(Xs); + + true -> + Xs + end. + +-spec parse(binary(), boolean()) -> list(list(integer())). +parse(Input, Backwards) -> + gleam@list:map( + gleam@string:split(Input, <<"\n"/utf8>>), + fun(Line) -> + gleam@list:map( + maybe_backwards( + gleam@string:split(Line, <<" "/utf8>>), + Backwards + ), + fun(N_str) -> + _assert_subject = gleam@int:parse(N_str), + {ok, N} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day9/solve"/utf8>>, + function => <<"parse"/utf8>>, + line => 10}) + end, + N + end + ) + end + ). + +-spec is_constant(list(integer())) -> boolean(). +is_constant(Ns) -> + case gleam@list:unique(Ns) of + [_] -> + true; + + _ -> + false + end. + +-spec take_derivative(list(integer())) -> list(integer()). +take_derivative(Ns) -> + _pipe = Ns, + _pipe@1 = gleam@list:window_by_2(_pipe), + gleam@list:map( + _pipe@1, + fun(Tup) -> erlang:element(1, Tup) - erlang:element(2, Tup) end + ). + +-spec extrapolate(list(integer())) -> integer(). +extrapolate(Ns) -> + case {is_constant(Ns), Ns} of + {true, [N | _]} -> + N; + + {false, [N@1 | _]} -> + N@1 + extrapolate(take_derivative(Ns)); + + {_, _} -> + erlang:error(#{gleam_error => panic, + message => <<"list empty when it shouldn't be"/utf8>>, + module => <<"day9/solve"/utf8>>, + function => <<"extrapolate"/utf8>>, + line => 38}) + end. + +-spec part(binary(), boolean()) -> binary(). +part(Input, Backwards) -> + _pipe = Input, + _pipe@1 = parse(_pipe, Backwards), + _pipe@2 = gleam@list:fold( + _pipe@1, + 0, + fun(Acc, Ns) -> extrapolate(Ns) + Acc end + ), + gleam@string:inspect(_pipe@2). + +-spec part1(binary()) -> binary(). +part1(Input) -> + part(Input, false). + +-spec part2(binary()) -> binary(). +part2(Input) -> + part(Input, true). + +-spec main() -> nil. +main() -> + _assert_subject = adglent:get_part(), + {ok, Part} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"day9/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 58}) + end, + _assert_subject@1 = adglent:get_input(<<"9"/utf8>>), + {ok, Input} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"day9/solve"/utf8>>, + function => <<"main"/utf8>>, + line => 59}) + end, + case Part of + first -> + _pipe = part1(Input), + _pipe@1 = adglent:inspect(_pipe), + gleam@io:println(_pipe@1); + + second -> + _pipe@2 = part2(Input), + _pipe@3 = adglent:inspect(_pipe@2), + gleam@io:println(_pipe@3) + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache Binary files differnew file mode 100644 index 0000000..44f142d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache_meta Binary files differnew file mode 100644 index 0000000..cd522ba --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.erl new file mode 100644 index 0000000..8790dec --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@array2d.erl @@ -0,0 +1,82 @@ +-module(utilities@array2d). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([add_posns/2, ortho_neighbors/1, to_2d_array_using/2, to_2d_array/1, to_2d_intarray/1, to_list_of_lists/1, parse_grid_using/2, parse_grid/1]). +-export_type([posn/0]). + +-type posn() :: {posn, integer(), integer()}. + +-spec add_posns(posn(), posn()) -> posn(). +add_posns(P1, P2) -> + case {P1, P2} of + {{posn, R1, C1}, {posn, R2, C2}} -> + {posn, R1 + R2, C1 + C2} + end. + +-spec ortho_neighbors(posn()) -> list(posn()). +ortho_neighbors(P) -> + {posn, R, C} = P, + [{posn, R + 1, C}, {posn, R - 1, C}, {posn, R, C + 1}, {posn, R, C - 1}]. + +-spec to_2d_array_using(list(list(PSV)), fun((PSV) -> {ok, PSY} | {error, nil})) -> gleam@dict:dict(posn(), PSY). +to_2d_array_using(Xss, F) -> + _pipe = (gleam@list:index_map( + Xss, + fun(R, Row) -> gleam@list:index_map(Row, fun(C, Cell) -> case F(Cell) of + {ok, Contents} -> + {ok, {{posn, R, C}, Contents}}; + + {error, nil} -> + {error, nil} + end end) end + )), + _pipe@1 = gleam@list:flatten(_pipe), + _pipe@2 = gleam@result:values(_pipe@1), + gleam@dict:from_list(_pipe@2). + +-spec to_2d_array(list(list(PSR))) -> gleam@dict:dict(posn(), PSR). +to_2d_array(Xss) -> + to_2d_array_using(Xss, fun(X) -> {ok, X} end). + +-spec to_2d_intarray(list(list(binary()))) -> gleam@dict:dict(posn(), integer()). +to_2d_intarray(Xss) -> + _pipe = (gleam@list:index_map( + Xss, + fun(R, Row) -> + gleam@list:index_map( + Row, + fun(C, Cell) -> + _assert_subject = gleam@int:parse(Cell), + {ok, N} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"utilities/array2d"/utf8>>, + function => <<"to_2d_intarray"/utf8>>, + line => 50}) + end, + {{posn, R, C}, N} + end + ) + end + )), + _pipe@1 = gleam@list:flatten(_pipe), + gleam@dict:from_list(_pipe@1). + +-spec to_list_of_lists(binary()) -> list(list(binary())). +to_list_of_lists(Str) -> + _pipe = Str, + _pipe@1 = gleam@string:split(_pipe, <<"\n"/utf8>>), + gleam@list:map(_pipe@1, fun gleam@string:to_graphemes/1). + +-spec parse_grid_using(binary(), fun((binary()) -> {ok, PTI} | {error, nil})) -> gleam@dict:dict(posn(), PTI). +parse_grid_using(Str, F) -> + _pipe = Str, + _pipe@1 = to_list_of_lists(_pipe), + to_2d_array_using(_pipe@1, F). + +-spec parse_grid(binary()) -> gleam@dict:dict(posn(), binary()). +parse_grid(Str) -> + parse_grid_using(Str, fun(X) -> {ok, X} end). diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache Binary files differnew file mode 100644 index 0000000..204b330 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache_meta Binary files differnew file mode 100644 index 0000000..4253e7c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.erl new file mode 100644 index 0000000..376369c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@memo.erl @@ -0,0 +1,70 @@ +-module(utilities@memo). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([create/1, set/3, get/2, memoize/3]). +-export_type([message/2, cache/2]). + +-type message(SNL, SNM) :: shutdown | + {get, SNL, gleam@erlang@process:subject({ok, SNM} | {error, nil})} | + {set, SNL, SNM}. + +-opaque cache(SNN, SNO) :: {cache, + gleam@erlang@process:subject(message(SNN, SNO))}. + +-spec handle_message(message(SNU, SNV), gleam@dict:dict(SNU, SNV)) -> gleam@otp@actor:next(message(SNU, SNV), gleam@dict:dict(SNU, SNV)). +handle_message(Message, Dict) -> + case Message of + shutdown -> + {stop, normal}; + + {get, Key, Client} -> + gleam@erlang@process:send(Client, gleam@dict:get(Dict, Key)), + {continue, Dict, none}; + + {set, Key@1, Value} -> + {continue, gleam@dict:insert(Dict, Key@1, Value), none} + end. + +-spec create(fun((cache(any(), any())) -> SOK)) -> SOK. +create(Fun) -> + _assert_subject = gleam@otp@actor:start( + gleam@dict:new(), + fun handle_message/2 + ), + {ok, Server} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"utilities/memo"/utf8>>, + function => <<"create"/utf8>>, + line => 36}) + end, + Result = Fun({cache, Server}), + gleam@erlang@process:send(Server, shutdown), + Result. + +-spec set(cache(SOL, SOM), SOL, SOM) -> nil. +set(Cache, Key, Value) -> + gleam@erlang@process:send(erlang:element(2, Cache), {set, Key, Value}). + +-spec get(cache(SOP, SOQ), SOP) -> {ok, SOQ} | {error, nil}. +get(Cache, Key) -> + gleam@erlang@process:call( + erlang:element(2, Cache), + fun(C) -> {get, Key, C} end, + 1000 + ). + +-spec memoize(cache(SOV, SOW), SOV, fun(() -> SOW)) -> SOW. +memoize(Cache, Key, Fun) -> + Result = case get(Cache, Key) of + {ok, Value} -> + Value; + + {error, nil} -> + Fun() + end, + set(Cache, Key, Result), + Result. diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache Binary files differnew file mode 100644 index 0000000..f013f33 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache_meta b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache_meta Binary files differnew file mode 100644 index 0000000..84048ca --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.cache_meta diff --git a/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.erl b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.erl new file mode 100644 index 0000000..f3784b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/_gleam_artefacts/utilities@prioqueue.erl @@ -0,0 +1,60 @@ +-module(utilities@prioqueue). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/0, insert/3, pop/1]). +-export_type([ref/0, p_queue/1, priority_queue/1, out_result/1]). + +-type ref() :: any(). + +-type p_queue(BAU) :: any() | {gleam_phantom, BAU}. + +-opaque priority_queue(BAV) :: {priority_queue, + p_queue({BAV, ref()}), + gleam@dict:dict(BAV, ref())}. + +-type out_result(BAW) :: empty | {value, BAW, integer()}. + +-spec new() -> priority_queue(any()). +new() -> + {priority_queue, pqueue2:new(), gleam@dict:new()}. + +-spec insert(priority_queue(BBI), BBI, integer()) -> priority_queue(BBI). +insert(Queue, Value, Priority) -> + Ref = erlang:make_ref(), + Refs = begin + _pipe = erlang:element(3, Queue), + gleam@dict:insert(_pipe, Value, Ref) + end, + {priority_queue, + pqueue2:in({Value, Ref}, Priority, erlang:element(2, Queue)), + Refs}. + +-spec pop(priority_queue(BBL)) -> {ok, {BBL, priority_queue(BBL)}} | + {error, nil}. +pop(Queue) -> + case pqueue2:pout(erlang:element(2, Queue)) of + {{value, {Value, Ref}, _}, Pqueue} -> + _assert_subject = gleam@dict:get(erlang:element(3, Queue), Value), + {ok, Recently_enqueued_ref} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"utilities/prioqueue"/utf8>>, + function => <<"pop"/utf8>>, + line => 54}) + end, + case Recently_enqueued_ref =:= Ref of + true -> + {ok, + {Value, + {priority_queue, Pqueue, erlang:element(3, Queue)}}}; + + false -> + pop({priority_queue, Pqueue, erlang:element(3, Queue)}) + end; + + {empty, _} -> + {error, nil} + end. diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.app b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.app new file mode 100644 index 0000000..043f0b6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.app @@ -0,0 +1,14 @@ +{application, aoc2023, [ + {vsn, "0.1.0"}, + {applications, [adglent, + gleam_community_maths, + gleam_erlang, + gleam_otp, + gleam_stdlib, + pqueue, + simplifile]}, + {description, ""}, + {modules, [day14@day14_test, + day14@solve]}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.beam Binary files differnew file mode 100644 index 0000000..7fe2a91 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023@@main.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023@@main.beam Binary files differnew file mode 100644 index 0000000..9e35237 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023@@main.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023_test.beam Binary files differnew file mode 100644 index 0000000..7fac74c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/aoc2023_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day10@day10_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day10@day10_test.beam Binary files differnew file mode 100644 index 0000000..0fe1fd6 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day10@day10_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day10@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day10@solve.beam Binary files differnew file mode 100644 index 0000000..5028a72 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day10@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day11@day11_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day11@day11_test.beam Binary files differnew file mode 100644 index 0000000..3e5c47d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day11@day11_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day11@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day11@solve.beam Binary files differnew file mode 100644 index 0000000..ac8563e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day11@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day12@day12_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day12@day12_test.beam Binary files differnew file mode 100644 index 0000000..a98331a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day12@day12_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day12@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day12@solve.beam Binary files differnew file mode 100644 index 0000000..87869e4 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day12@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day13@day13_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day13@day13_test.beam Binary files differnew file mode 100644 index 0000000..b194d26 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day13@day13_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day13@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day13@solve.beam Binary files differnew file mode 100644 index 0000000..38974ae --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day13@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day14@day14_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day14@day14_test.beam Binary files differnew file mode 100644 index 0000000..2b4629d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day14@day14_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day14@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day14@solve.beam Binary files differnew file mode 100644 index 0000000..aa76b4f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day14@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day15@day15_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day15@day15_test.beam Binary files differnew file mode 100644 index 0000000..29aba3b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day15@day15_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day15@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day15@solve.beam Binary files differnew file mode 100644 index 0000000..d3a892e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day15@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day16@day16_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day16@day16_test.beam Binary files differnew file mode 100644 index 0000000..785aee1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day16@day16_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day16@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day16@solve.beam Binary files differnew file mode 100644 index 0000000..b85d427 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day16@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day17@day17_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day17@day17_test.beam Binary files differnew file mode 100644 index 0000000..973225d --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day17@day17_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day17@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day17@solve.beam Binary files differnew file mode 100644 index 0000000..770b87b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day17@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day18@day18_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day18@day18_test.beam Binary files differnew file mode 100644 index 0000000..d4668d8 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day18@day18_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day18@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day18@solve.beam Binary files differnew file mode 100644 index 0000000..1559a28 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day18@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day19@day19_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day19@day19_test.beam Binary files differnew file mode 100644 index 0000000..b4b142b --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day19@day19_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day19@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day19@solve.beam Binary files differnew file mode 100644 index 0000000..429a9c3 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day19@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day1@day1_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day1@day1_test.beam Binary files differnew file mode 100644 index 0000000..cc5cc2e --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day1@day1_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day1@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day1@solve.beam Binary files differnew file mode 100644 index 0000000..21582eb --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day1@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day20@day20_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day20@day20_test.beam Binary files differnew file mode 100644 index 0000000..69c5a85 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day20@day20_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day20@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day20@solve.beam Binary files differnew file mode 100644 index 0000000..2d186df --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day20@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day21@day21_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day21@day21_test.beam Binary files differnew file mode 100644 index 0000000..dcd764a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day21@day21_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day21@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day21@solve.beam Binary files differnew file mode 100644 index 0000000..34bfb6f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day21@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day22@day22_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day22@day22_test.beam Binary files differnew file mode 100644 index 0000000..511b695 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day22@day22_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day22@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day22@solve.beam Binary files differnew file mode 100644 index 0000000..dd15c2a --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day22@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day23@day23_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day23@day23_test.beam Binary files differnew file mode 100644 index 0000000..fd46989 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day23@day23_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day23@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day23@solve.beam Binary files differnew file mode 100644 index 0000000..d1c426f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day23@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day2@day2_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day2@day2_test.beam Binary files differnew file mode 100644 index 0000000..96a97fc --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day2@day2_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day2@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day2@solve.beam Binary files differnew file mode 100644 index 0000000..592a360 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day2@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day3@day3_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day3@day3_test.beam Binary files differnew file mode 100644 index 0000000..12d57d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day3@day3_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day3@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day3@solve.beam Binary files differnew file mode 100644 index 0000000..9fa2011 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day3@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day4@day4_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day4@day4_test.beam Binary files differnew file mode 100644 index 0000000..41d9854 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day4@day4_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day4@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day4@solve.beam Binary files differnew file mode 100644 index 0000000..a8d5973 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day4@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day5@day5_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day5@day5_test.beam Binary files differnew file mode 100644 index 0000000..a7e22e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day5@day5_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day5@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day5@solve.beam Binary files differnew file mode 100644 index 0000000..d248e2c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day5@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day6@day6_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day6@day6_test.beam Binary files differnew file mode 100644 index 0000000..11a7360 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day6@day6_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day6@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day6@solve.beam Binary files differnew file mode 100644 index 0000000..ddb5777 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day6@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day7@day7_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day7@day7_test.beam Binary files differnew file mode 100644 index 0000000..c4586b8 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day7@day7_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day7@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day7@solve.beam Binary files differnew file mode 100644 index 0000000..4ae1796 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day7@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day8@day8_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day8@day8_test.beam Binary files differnew file mode 100644 index 0000000..68fa255 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day8@day8_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day8@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day8@solve.beam Binary files differnew file mode 100644 index 0000000..d2d7689 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day8@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day9@day9_test.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day9@day9_test.beam Binary files differnew file mode 100644 index 0000000..f12dde7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day9@day9_test.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/day9@solve.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/day9@solve.beam Binary files differnew file mode 100644 index 0000000..4920ea7 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/day9@solve.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@array2d.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@array2d.beam Binary files differnew file mode 100644 index 0000000..f265230 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@array2d.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@memo.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@memo.beam Binary files differnew file mode 100644 index 0000000..09a3274 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@memo.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@prioqueue.beam b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@prioqueue.beam Binary files differnew file mode 100644 index 0000000..b95d0dd --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/ebin/utilities@prioqueue.beam diff --git a/aoc2023/build/dev/erlang/aoc2023/include/day2@solve_Game.hrl b/aoc2023/build/dev/erlang/aoc2023/include/day2@solve_Game.hrl new file mode 100644 index 0000000..7babf61 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/day2@solve_Game.hrl @@ -0,0 +1 @@ +-record(game, {red :: integer(), blue :: integer(), green :: integer()}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_Almanac.hrl b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_Almanac.hrl new file mode 100644 index 0000000..5c3086c --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_Almanac.hrl @@ -0,0 +1,4 @@ +-record(almanac, { + seeds :: list(integer()), + mappers :: list(list(day5@solve:mapping_range())) +}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_MRange.hrl b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_MRange.hrl new file mode 100644 index 0000000..999313f --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_MRange.hrl @@ -0,0 +1 @@ +-record(m_range, {start :: integer(), 'end' :: integer(), offset :: integer()}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_SRange.hrl b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_SRange.hrl new file mode 100644 index 0000000..56c67cd --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/day5@solve_SRange.hrl @@ -0,0 +1 @@ +-record(s_range, {start :: integer(), 'end' :: integer()}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/utilities@array2d_Posn.hrl b/aoc2023/build/dev/erlang/aoc2023/include/utilities@array2d_Posn.hrl new file mode 100644 index 0000000..94da3d5 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/utilities@array2d_Posn.hrl @@ -0,0 +1 @@ +-record(posn, {r :: integer(), c :: integer()}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/utilities@memo_Cache.hrl b/aoc2023/build/dev/erlang/aoc2023/include/utilities@memo_Cache.hrl new file mode 100644 index 0000000..941b746 --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/utilities@memo_Cache.hrl @@ -0,0 +1,3 @@ +-record(cache, { + server :: gleam@erlang@process:subject(utilities@memo:message(any(), any())) +}). diff --git a/aoc2023/build/dev/erlang/aoc2023/include/utilities@prioqueue_PriorityQueue.hrl b/aoc2023/build/dev/erlang/aoc2023/include/utilities@prioqueue_PriorityQueue.hrl new file mode 100644 index 0000000..0e12dca --- /dev/null +++ b/aoc2023/build/dev/erlang/aoc2023/include/utilities@prioqueue_PriorityQueue.hrl @@ -0,0 +1,4 @@ +-record(priority_queue, { + queue :: utilities@prioqueue:p_queue({any(), utilities@prioqueue:ref()}), + refs :: gleam@dict:dict(any(), utilities@prioqueue:ref()) +}). diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache Binary files differnew file mode 100644 index 0000000..772b42f --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache_meta b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache_meta Binary files differnew file mode 100644 index 0000000..3a247a0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.cache_meta diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.erl new file mode 100644 index 0000000..91045ce --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap.erl @@ -0,0 +1,538 @@ +-module(gap). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([to_styled/1, compare_strings_with_algorithm/3, compare_lists_with_algorithm/3, myers/2, compare_lists/2, compare_strings/2, lcs/2]). +-export_type([score/1]). + +-type score(NLN) :: {score, integer(), gleam@option:option(NLN)}. + +-spec to_styled(gap@comparison:comparison(any())) -> gap@styled_comparison:styled_comparison(). +to_styled(Comparison) -> + _pipe = Comparison, + _pipe@1 = gap@styling:from_comparison(_pipe), + _pipe@2 = gap@styling:highlight( + _pipe@1, + fun gap@styling:first_highlight_default/1, + fun gap@styling:second_highlight_default/1, + fun gap@styling:no_highlight/1 + ), + gap@styling:to_styled_comparison(_pipe@2). + +-spec compare_strings_with_algorithm( + binary(), + binary(), + fun((list(binary()), list(binary())) -> gap@comparison:comparison(binary())) +) -> gap@comparison:comparison(binary()). +compare_strings_with_algorithm(First, Second, Algorithm) -> + Comparison = Algorithm( + gleam@string:to_graphemes(First), + gleam@string:to_graphemes(Second) + ), + case Comparison of + {list_comparison, First@1, Second@1} -> + {string_comparison, First@1, Second@1}; + + {string_comparison, First@2, Second@2} -> + {string_comparison, First@2, Second@2} + end. + +-spec compare_lists_with_algorithm( + list(NMC), + list(NMC), + fun((list(NMC), list(NMC)) -> gap@comparison:comparison(NMC)) +) -> gap@comparison:comparison(NMC). +compare_lists_with_algorithm(First_sequence, Second_sequence, Algorithm) -> + Algorithm(First_sequence, Second_sequence). + +-spec myers(list(NMH), list(NMH)) -> gap@comparison:comparison(NMH). +myers(First_sequence, Second_sequence) -> + Edits = gap@myers:difference(First_sequence, Second_sequence), + _pipe = Edits, + _pipe@1 = gleam@list:reverse(_pipe), + gleam@list:fold( + _pipe@1, + {list_comparison, [], []}, + fun(Comparison, Edit) -> case Comparison of + {list_comparison, First, Second} -> + case Edit of + {eq, Segment} -> + {list_comparison, + [{match, Segment} | First], + [{match, Segment} | Second]}; + + {ins, Segment@1} -> + {list_comparison, + First, + [{no_match, Segment@1} | Second]}; + + {del, Segment@2} -> + {list_comparison, + [{no_match, Segment@2} | First], + Second} + end; + + {string_comparison, _, _} -> + Comparison + end end + ). + +-spec compare_lists(list(NLY), list(NLY)) -> gap@comparison:comparison(NLY). +compare_lists(First_sequence, Second_sequence) -> + myers(First_sequence, Second_sequence). + +-spec compare_strings(binary(), binary()) -> gap@comparison:comparison(binary()). +compare_strings(First, Second) -> + Comparison = compare_lists( + gleam@string:to_graphemes(First), + gleam@string:to_graphemes(Second) + ), + case Comparison of + {list_comparison, First@1, Second@1} -> + {string_comparison, First@1, Second@1}; + + {string_comparison, First@2, Second@2} -> + {string_comparison, First@2, Second@2} + end. + +-spec prepend_and_merge( + list(gap@comparison:match(list(NMP))), + gap@comparison:match(list(NMP)) +) -> list(gap@comparison:match(list(NMP))). +prepend_and_merge(Matches, Match) -> + case {Matches, Match} of + {[], _} -> + [Match]; + + {[{match, First_match} | Rest], {match, _}} -> + [{match, + begin + _pipe = erlang:element(2, Match), + gleam@list:append(_pipe, First_match) + end} | + Rest]; + + {[{no_match, First_match@1} | Rest@1], {no_match, _}} -> + [{no_match, + begin + _pipe@1 = erlang:element(2, Match), + gleam@list:append(_pipe@1, First_match@1) + end} | + Rest@1]; + + {Matches@1, Match@1} -> + [Match@1 | Matches@1] + end. + +-spec append_and_merge( + list(gap@comparison:match(list(NMY))), + gap@comparison:match(list(NMY)) +) -> list(gap@comparison:match(list(NMY))). +append_and_merge(Matches, Match) -> + _pipe@3 = case {begin + _pipe = Matches, + gleam@list:reverse(_pipe) + end, + Match} of + {[], _} -> + [Match]; + + {[{match, First_match} | Rest], {match, _}} -> + [{match, + begin + _pipe@1 = First_match, + gleam@list:append(_pipe@1, erlang:element(2, Match)) + end} | + Rest]; + + {[{no_match, First_match@1} | Rest@1], {no_match, _}} -> + [{no_match, + begin + _pipe@2 = First_match@1, + gleam@list:append(_pipe@2, erlang:element(2, Match)) + end} | + Rest@1]; + + {Matches@1, Match@1} -> + [Match@1 | Matches@1] + end, + gleam@list:reverse(_pipe@3). + +-spec collect_matches( + gleam@dict:dict(NQZ, any()), + list(NNI), + fun((NQZ) -> integer()) +) -> list(gap@comparison:match(list(NNI))). +collect_matches(Tracking, Str, Extract_fun) -> + Matching_indexes = begin + _pipe = gleam@map:keys(Tracking), + _pipe@1 = gleam@list:map(_pipe, Extract_fun), + gleam@set:from_list(_pipe@1) + end, + Matches = begin + _pipe@2 = Str, + gleam@list:index_map( + _pipe@2, + fun(Index, Item) -> + case gleam@set:contains(Matching_indexes, Index) of + true -> + {match, Item}; + + false -> + {no_match, Item} + end + end + ) + end, + _pipe@3 = Matches, + _pipe@4 = gleam@list:chunk(_pipe@3, fun(Match) -> case Match of + {match, _} -> + true; + + {no_match, _} -> + false + end end), + gleam@list:map(_pipe@4, fun(Match_list) -> case Match_list of + [{match, _} | _] -> + {match, + gleam@list:filter_map( + Match_list, + fun(Match@1) -> case Match@1 of + {match, Item@1} -> + {ok, Item@1}; + + {no_match, _} -> + {error, nil} + end end + )}; + + [{no_match, _} | _] -> + {no_match, + gleam@list:filter_map( + Match_list, + fun(Match@2) -> case Match@2 of + {no_match, Item@2} -> + {ok, Item@2}; + + {match, _} -> + {error, nil} + end end + )} + end end). + +-spec back_track( + gleam@dict:dict({integer(), integer()}, score(NNM)), + integer(), + integer(), + list({{integer(), integer()}, NNM}) +) -> list({{integer(), integer()}, NNM}). +back_track(Diff_map, First_index, Second_index, Stack) -> + case (First_index =:= 0) orelse (Second_index =:= 0) of + true -> + This_score = begin + _pipe = gleam@map:get(Diff_map, {First_index, Second_index}), + gleam@result:unwrap(_pipe, {score, 0, none}) + end, + case This_score of + {score, _, {some, Item}} -> + [{{First_index, Second_index}, Item} | Stack]; + + _ -> + case {First_index, Second_index} of + {0, A} when A > 0 -> + back_track( + Diff_map, + First_index, + Second_index - 1, + Stack + ); + + {A@1, 0} when A@1 > 0 -> + back_track( + Diff_map, + First_index - 1, + Second_index, + Stack + ); + + {0, 0} -> + Stack; + + {_, _} -> + back_track( + Diff_map, + First_index - 1, + Second_index, + Stack + ) + end + end; + + false -> + This_score@1 = begin + _pipe@1 = gleam@map:get(Diff_map, {First_index, Second_index}), + gleam@result:unwrap(_pipe@1, {score, 0, none}) + end, + case This_score@1 of + {score, _, {some, Item@1}} -> + back_track( + Diff_map, + First_index - 1, + Second_index - 1, + [{{First_index, Second_index}, Item@1} | Stack] + ); + + {score, _, none} -> + Up = begin + _pipe@2 = gleam@map:get( + Diff_map, + {First_index, Second_index - 1} + ), + gleam@result:unwrap(_pipe@2, {score, 0, none}) + end, + Back = begin + _pipe@3 = gleam@map:get( + Diff_map, + {First_index - 1, Second_index} + ), + gleam@result:unwrap(_pipe@3, {score, 0, none}) + end, + case gleam@int:compare( + erlang:element(2, Up), + erlang:element(2, Back) + ) of + gt -> + back_track( + Diff_map, + First_index, + Second_index - 1, + Stack + ); + + lt -> + back_track( + Diff_map, + First_index - 1, + Second_index, + Stack + ); + + eq -> + case {First_index, Second_index} of + {0, A@2} when A@2 > 0 -> + back_track( + Diff_map, + First_index, + Second_index - 1, + Stack + ); + + {A@3, 0} when A@3 > 0 -> + back_track( + Diff_map, + First_index - 1, + Second_index, + Stack + ); + + {0, 0} -> + Stack; + + {_, _} -> + back_track( + Diff_map, + First_index - 1, + Second_index, + Stack + ) + end + end + end + end. + +-spec build_diff_map( + NNS, + integer(), + NNS, + integer(), + gleam@dict:dict({integer(), integer()}, score(NNS)) +) -> gleam@dict:dict({integer(), integer()}, score(NNS)). +build_diff_map(First_item, First_index, Second_item, Second_index, Diff_map) -> + Prev_score = begin + _pipe = gleam@map:get(Diff_map, {First_index - 1, Second_index - 1}), + gleam@result:unwrap(_pipe, {score, 0, none}) + end, + Derived_score_up = begin + _pipe@1 = Diff_map, + _pipe@2 = gleam@map:get(_pipe@1, {First_index, Second_index - 1}), + gleam@result:unwrap(_pipe@2, {score, 0, none}) + end, + Derived_score_back = begin + _pipe@3 = Diff_map, + _pipe@4 = gleam@map:get(_pipe@3, {First_index - 1, Second_index}), + gleam@result:unwrap(_pipe@4, {score, 0, none}) + end, + Derived_score = gleam@int:max( + erlang:element(2, Derived_score_up), + erlang:element(2, Derived_score_back) + ), + This_score = case First_item =:= Second_item of + true -> + {score, erlang:element(2, Prev_score) + 1, {some, First_item}}; + + false -> + {score, Derived_score, none} + end, + _pipe@5 = Diff_map, + gleam@map:insert(_pipe@5, {First_index, Second_index}, This_score). + +-spec lcs(list(NML), list(NML)) -> gap@comparison:comparison(NML). +lcs(First_sequence, Second_sequence) -> + Leading_matches = begin + _pipe = gleam@list:zip(First_sequence, Second_sequence), + _pipe@1 = gleam@list:take_while( + _pipe, + fun(Pair) -> erlang:element(1, Pair) =:= erlang:element(2, Pair) end + ), + gleam@list:map(_pipe@1, fun gleam@pair:first/1) + end, + Num_leading_matches = gleam@list:length(Leading_matches), + Trailing_matches = begin + _pipe@2 = gleam@list:zip( + gleam@list:reverse(First_sequence), + gleam@list:reverse(Second_sequence) + ), + _pipe@3 = gleam@list:take_while( + _pipe@2, + fun(Pair@1) -> + erlang:element(1, Pair@1) =:= erlang:element(2, Pair@1) + end + ), + _pipe@4 = gleam@list:map(_pipe@3, fun gleam@pair:first/1), + gleam@list:reverse(_pipe@4) + end, + Num_trailing_matches = gleam@list:length(Trailing_matches), + First_sequence_to_diff = begin + _pipe@5 = First_sequence, + _pipe@6 = gleam@list:drop(_pipe@5, Num_leading_matches), + gleam@list:take( + _pipe@6, + (gleam@list:length(First_sequence) - Num_leading_matches) - Num_trailing_matches + ) + end, + Second_sequence_to_diff = begin + _pipe@7 = Second_sequence, + _pipe@8 = gleam@list:drop(_pipe@7, Num_leading_matches), + gleam@list:take( + _pipe@8, + (gleam@list:length(Second_sequence) - Num_leading_matches) - Num_trailing_matches + ) + end, + Diff_map@2 = begin + _pipe@9 = Second_sequence_to_diff, + gleam@list:index_fold( + _pipe@9, + gleam@map:new(), + fun(Diff_map, Item_second, Index_second) -> + _pipe@10 = First_sequence_to_diff, + gleam@list:index_fold( + _pipe@10, + Diff_map, + fun(Diff_map@1, Item_first, Index_first) -> + build_diff_map( + Item_first, + Index_first, + Item_second, + Index_second, + Diff_map@1 + ) + end + ) + end + ) + end, + {First_segments@1, Second_segments@1} = case {First_sequence_to_diff, + Second_sequence_to_diff} of + {[], []} -> + {[], []}; + + {First_matching, []} -> + {[{no_match, First_matching}], []}; + + {[], Second_matching} -> + {[], [{no_match, Second_matching}]}; + + {First_sequence_to_diff@1, Second_sequence_to_diff@1} -> + Tracking = begin + _pipe@11 = back_track( + Diff_map@2, + gleam@list:length(First_sequence_to_diff@1) - 1, + gleam@list:length(Second_sequence_to_diff@1) - 1, + [] + ), + gleam@map:from_list(_pipe@11) + end, + First_segments = collect_matches( + Tracking, + First_sequence_to_diff@1, + fun(Key) -> + {First, _} = Key, + First + end + ), + Second_segments = collect_matches( + Tracking, + Second_sequence_to_diff@1, + fun(Key@1) -> + {_, Second} = Key@1, + Second + end + ), + {First_segments, Second_segments} + end, + {First_segments_with_leading_trailing, + Second_segments_with_leading_trailing} = case {Leading_matches, + Trailing_matches} of + {[], []} -> + {First_segments@1, Second_segments@1}; + + {[], Trailing_matches@1} -> + {begin + _pipe@12 = First_segments@1, + append_and_merge(_pipe@12, {match, Trailing_matches@1}) + end, + begin + _pipe@13 = Second_segments@1, + append_and_merge(_pipe@13, {match, Trailing_matches@1}) + end}; + + {Leading_matches@1, []} -> + {begin + _pipe@14 = First_segments@1, + prepend_and_merge(_pipe@14, {match, Leading_matches@1}) + end, + begin + _pipe@15 = Second_segments@1, + prepend_and_merge(_pipe@15, {match, Leading_matches@1}) + end}; + + {Leading_matches@2, Trailing_matches@2} -> + {begin + _pipe@16 = First_segments@1, + _pipe@17 = prepend_and_merge( + _pipe@16, + {match, Leading_matches@2} + ), + append_and_merge(_pipe@17, {match, Trailing_matches@2}) + end, + begin + _pipe@18 = Second_segments@1, + _pipe@19 = prepend_and_merge( + _pipe@18, + {match, Leading_matches@2} + ), + append_and_merge(_pipe@19, {match, Trailing_matches@2}) + end} + end, + {list_comparison, + First_segments_with_leading_trailing, + Second_segments_with_leading_trailing}. diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache Binary files differnew file mode 100644 index 0000000..90fe99a --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache_meta b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache_meta Binary files differnew file mode 100644 index 0000000..e3f3599 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.cache_meta diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.erl new file mode 100644 index 0000000..74f5db4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@comparison.erl @@ -0,0 +1,15 @@ +-module(gap@comparison). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([comparison/1, match/1]). + +-type comparison(NBT) :: {list_comparison, + list(match(list(NBT))), + list(match(list(NBT)))} | + {string_comparison, + list(match(list(binary()))), + list(match(list(binary())))}. + +-type match(NBU) :: {match, NBU} | {no_match, NBU}. + + diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache Binary files differnew file mode 100644 index 0000000..1d21cfe --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache_meta b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache_meta Binary files differnew file mode 100644 index 0000000..6d51dd1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.cache_meta diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.erl new file mode 100644 index 0000000..1472fc0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@myers.erl @@ -0,0 +1,156 @@ +-module(gap@myers). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([difference/2]). +-export_type([edit/1, path/1, status/1]). + +-type edit(NFW) :: {eq, list(NFW)} | {del, list(NFW)} | {ins, list(NFW)}. + +-type path(NFX) :: {path, + integer(), + integer(), + list(NFX), + list(NFX), + list(edit(NFX))}. + +-type status(NFY) :: {done, list(edit(NFY))} | + {next, list(path(NFY))} | + {cont, path(NFY)}. + +-spec compact_reverse(list(edit(NGI)), list(edit(NGI))) -> list(edit(NGI)). +compact_reverse(Edits, Acc) -> + case {Edits, Acc} of + {[], Acc@1} -> + Acc@1; + + {[{eq, Elem} | Rest], [{eq, Result} | Acc_rest]} -> + compact_reverse( + Rest, + [{eq, gleam@list:flatten([Elem, Result])} | Acc_rest] + ); + + {[{del, Elem@1} | Rest@1], [{del, Result@1} | Acc_rest@1]} -> + compact_reverse( + Rest@1, + [{del, gleam@list:flatten([Elem@1, Result@1])} | Acc_rest@1] + ); + + {[{ins, Elem@2} | Rest@2], [{ins, Result@2} | Acc_rest@2]} -> + compact_reverse( + Rest@2, + [{ins, gleam@list:flatten([Elem@2, Result@2])} | Acc_rest@2] + ); + + {[{eq, Elem@3} | Rest@3], Acc@2} -> + compact_reverse(Rest@3, [{eq, Elem@3} | Acc@2]); + + {[{del, Elem@4} | Rest@4], Acc@3} -> + compact_reverse(Rest@4, [{del, Elem@4} | Acc@3]); + + {[{ins, Elem@5} | Rest@5], Acc@4} -> + compact_reverse(Rest@5, [{ins, Elem@5} | Acc@4]) + end. + +-spec move_right(path(NHB)) -> path(NHB). +move_right(Path) -> + case Path of + {path, X, Y, List1, [Elem | Rest], Edits} -> + {path, X + 1, Y, List1, Rest, [{ins, [Elem]} | Edits]}; + + {path, X@1, Y@1, List1@1, [], Edits@1} -> + {path, X@1 + 1, Y@1, List1@1, [], Edits@1} + end. + +-spec move_down(path(NHE)) -> path(NHE). +move_down(Path) -> + case Path of + {path, X, Y, [Elem | Rest], List2, Edits} -> + {path, X, Y + 1, Rest, List2, [{del, [Elem]} | Edits]}; + + {path, X@1, Y@1, [], List2@1, Edits@1} -> + {path, X@1, Y@1 + 1, [], List2@1, Edits@1} + end. + +-spec proceed_path(integer(), integer(), list(path(NGV))) -> {path(NGV), + list(path(NGV))}. +proceed_path(Diag, Limit, Paths) -> + Neg_limit = - Limit, + case {Diag, Limit, Paths} of + {0, 0, [Path]} -> + {Path, []}; + + {Diag@1, _, [Path@1 | _] = Paths@1} when Diag@1 =:= Neg_limit -> + {move_down(Path@1), Paths@1}; + + {Diag@2, Limit@1, [Path@2 | _] = Paths@2} when Diag@2 =:= Limit@1 -> + {move_right(Path@2), Paths@2}; + + {_, _, [Path1, Path2 | Rest]} -> + case erlang:element(3, Path1) > erlang:element(3, Path2) of + true -> + {move_right(Path1), [Path2 | Rest]}; + + false -> + {move_down(Path2), [Path2 | Rest]} + end + end. + +-spec follow_snake(path(NHH)) -> status(NHH). +follow_snake(Path) -> + case Path of + {path, X, Y, [Elem1 | Rest1], [Elem2 | Rest2], Edits} when Elem1 =:= Elem2 -> + follow_snake( + {path, X + 1, Y + 1, Rest1, Rest2, [{eq, [Elem1]} | Edits]} + ); + + {path, _, _, [], [], Edits@1} -> + {done, Edits@1}; + + _ -> + {cont, Path} + end. + +-spec each_diagonal(integer(), integer(), list(path(NGP)), list(path(NGP))) -> status(NGP). +each_diagonal(Diag, Limit, Paths, Next_paths) -> + case Diag > Limit of + true -> + {next, gleam@list:reverse(Next_paths)}; + + false -> + {Path, Rest} = proceed_path(Diag, Limit, Paths), + case follow_snake(Path) of + {cont, Path@1} -> + each_diagonal(Diag + 2, Limit, Rest, [Path@1 | Next_paths]); + + Other -> + Other + end + end. + +-spec find_script(integer(), integer(), list(path(NGE))) -> list(edit(NGE)). +find_script(Envelope, Max, Paths) -> + case Envelope > Max of + true -> + []; + + false -> + case each_diagonal(- Envelope, Envelope, Paths, []) of + {done, Edits} -> + compact_reverse(Edits, []); + + {next, Paths@1} -> + find_script(Envelope + 1, Max, Paths@1); + + _ -> + erlang:error(#{gleam_error => panic, + message => <<"Didn't expect a Cont here"/utf8>>, + module => <<"gap/myers"/utf8>>, + function => <<"find_script"/utf8>>, + line => 35}) + end + end. + +-spec difference(list(NFZ), list(NFZ)) -> list(edit(NFZ)). +difference(List1, List2) -> + Path = {path, 0, 0, List1, List2, []}, + find_script(0, gleam@list:length(List1) + gleam@list:length(List2), [Path]). diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache Binary files differnew file mode 100644 index 0000000..d03c302 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache_meta b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache_meta Binary files differnew file mode 100644 index 0000000..dc9ffd0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.cache_meta diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.erl new file mode 100644 index 0000000..9a04ad4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styled_comparison.erl @@ -0,0 +1,8 @@ +-module(gap@styled_comparison). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([styled_comparison/0]). + +-type styled_comparison() :: {styled_comparison, binary(), binary()}. + + diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache Binary files differnew file mode 100644 index 0000000..6fdaed1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache_meta b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache_meta Binary files differnew file mode 100644 index 0000000..f580983 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.cache_meta diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.erl new file mode 100644 index 0000000..4a7d2e2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap@styling.erl @@ -0,0 +1,202 @@ +-module(gap@styling). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from_comparison/1, highlight/4, serialize/2, first_highlight_default/1, second_highlight_default/1, no_highlight/1, mk_generic_serializer/2, to_styled_comparison/1]). +-export_type([part/1, highlighters/0, styling/1]). + +-type part(NCF) :: {part, binary(), list(NCF), fun((binary()) -> binary())} | + {all, binary()}. + +-type highlighters() :: {highlighters, + fun((binary()) -> binary()), + fun((binary()) -> binary()), + fun((binary()) -> binary())}. + +-opaque styling(NCG) :: {styling, + gap@comparison:comparison(NCG), + gleam@option:option(fun((part(NCG)) -> binary())), + gleam@option:option(highlighters())}. + +-spec from_comparison(gap@comparison:comparison(NCJ)) -> styling(NCJ). +from_comparison(Comparison) -> + {styling, Comparison, none, none}. + +-spec highlight( + styling(NCM), + fun((binary()) -> binary()), + fun((binary()) -> binary()), + fun((binary()) -> binary()) +) -> styling(NCM). +highlight(Styling, First, Second, Matching) -> + erlang:setelement( + 4, + Styling, + {some, {highlighters, First, Second, Matching}} + ). + +-spec serialize(styling(NCP), fun((part(NCP)) -> binary())) -> styling(NCP). +serialize(Styling, Serializer) -> + erlang:setelement(3, Styling, {some, Serializer}). + +-spec first_highlight_default(binary()) -> binary(). +first_highlight_default(String) -> + case String of + <<" "/utf8>> -> + _pipe = String, + _pipe@1 = gleam_community@ansi:underline(_pipe), + _pipe@2 = gleam_community@ansi:bold(_pipe@1), + gleam_community@ansi:green(_pipe@2); + + _ -> + _pipe@3 = String, + _pipe@4 = gleam_community@ansi:green(_pipe@3), + gleam_community@ansi:bold(_pipe@4) + end. + +-spec second_highlight_default(binary()) -> binary(). +second_highlight_default(String) -> + case String of + <<" "/utf8>> -> + _pipe = String, + _pipe@1 = gleam_community@ansi:underline(_pipe), + _pipe@2 = gleam_community@ansi:bold(_pipe@1), + gleam_community@ansi:red(_pipe@2); + + _ -> + _pipe@3 = String, + _pipe@4 = gleam_community@ansi:red(_pipe@3), + gleam_community@ansi:bold(_pipe@4) + end. + +-spec no_highlight(binary()) -> binary(). +no_highlight(String) -> + String. + +-spec string_serializer(part(binary())) -> binary(). +string_serializer(Part) -> + case Part of + {part, Acc, Sequence, Highlight} -> + <<Acc/binary, + (begin + _pipe = Sequence, + _pipe@1 = gleam@list:map(_pipe, Highlight), + gleam@string:join(_pipe@1, <<""/utf8>>) + end)/binary>>; + + {all, String} -> + String + end. + +-spec mk_generic_serializer(binary(), fun((binary()) -> binary())) -> fun((part(any())) -> binary()). +mk_generic_serializer(Separator, Around) -> + fun(Part) -> case Part of + {part, Acc, Sequence, Highlight} -> + Segment_separator = case Acc of + <<""/utf8>> -> + <<""/utf8>>; + + _ -> + Separator + end, + <<<<Acc/binary, Segment_separator/binary>>/binary, + (begin + _pipe = Sequence, + _pipe@1 = gleam@list:map( + _pipe, + fun gleam@string:inspect/1 + ), + _pipe@2 = gleam@list:map(_pipe@1, Highlight), + gleam@string:join(_pipe@2, Separator) + end)/binary>>; + + {all, String} -> + Around(String) + end end. + +-spec generic_serializer(part(any())) -> binary(). +generic_serializer(Part) -> + (mk_generic_serializer( + <<", "/utf8>>, + fun(All) -> <<<<"["/utf8, All/binary>>/binary, "]"/utf8>> end + ))(Part). + +-spec to_strings( + list(gap@comparison:match(list(NCZ))), + list(gap@comparison:match(list(NCZ))), + fun((part(NCZ)) -> binary()), + fun((binary()) -> binary()), + fun((binary()) -> binary()), + fun((binary()) -> binary()) +) -> gap@styled_comparison:styled_comparison(). +to_strings( + First, + Second, + Serializer, + First_highlight, + Second_highlight, + No_highlight +) -> + First_styled = begin + _pipe = First, + gleam@list:fold(_pipe, <<""/utf8>>, fun(Str, Match) -> case Match of + {match, Item} -> + Serializer({part, Str, Item, No_highlight}); + + {no_match, Item@1} -> + Serializer({part, Str, Item@1, First_highlight}) + end end) + end, + Second_styled = begin + _pipe@1 = Second, + gleam@list:fold( + _pipe@1, + <<""/utf8>>, + fun(Str@1, Match@1) -> case Match@1 of + {match, Item@2} -> + Serializer({part, Str@1, Item@2, No_highlight}); + + {no_match, Item@3} -> + Serializer({part, Str@1, Item@3, Second_highlight}) + end end + ) + end, + {styled_comparison, + Serializer({all, First_styled}), + Serializer({all, Second_styled})}. + +-spec to_styled_comparison(styling(any())) -> gap@styled_comparison:styled_comparison(). +to_styled_comparison(Styling) -> + Highlight = begin + _pipe = erlang:element(4, Styling), + gleam@option:unwrap( + _pipe, + {highlighters, + fun first_highlight_default/1, + fun second_highlight_default/1, + fun no_highlight/1} + ) + end, + case erlang:element(2, Styling) of + {string_comparison, First, Second} -> + to_strings( + First, + Second, + fun string_serializer/1, + erlang:element(2, Highlight), + erlang:element(3, Highlight), + erlang:element(4, Highlight) + ); + + {list_comparison, First@1, Second@1} -> + to_strings( + First@1, + Second@1, + gleam@option:unwrap( + erlang:element(3, Styling), + fun generic_serializer/1 + ), + erlang:element(2, Highlight), + erlang:element(3, Highlight), + erlang:element(4, Highlight) + ) + end. diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap_ffi.mjs b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap_ffi.mjs new file mode 100644 index 0000000..235c80b --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gap_ffi.mjs @@ -0,0 +1,431 @@ +import { + Error, + List, + Ok, + inspect, + toList, + makeError, + isEqual, +} from "./gleam.mjs"; +import * as $option from "../gleam_stdlib/gleam/option.mjs"; + +const HASHCODE_CACHE = new WeakMap(); +const Nil = undefined; + +class MutableMap { + static #hashcode_cache = new WeakMap(); + + static hash(value) { + let existing = this.#hashcode_cache.get(value); + if (existing) { + return existing; + } else if (value instanceof Object) { + let hashcode = inspect(value); + HASHCODE_CACHE.set(value, hashcode); + return hashcode; + } else { + return value.toString(); + } + } + + constructor() { + this.entries = new globalThis.Map(); + } + + get size() { + return this.entries.size; + } + + inspect() { + let entries = [...this.entries.values()] + .map((pair) => inspect(pair)) + .join(", "); + return `map.from_list([${entries}])`; + } + + toList() { + return List.fromArray([...this.entries.values()]); + } + + insert(k, v) { + this.entries.set(MutableMap.hash(k), [k, v]); + return this; + } + + delete(k) { + this.entries.delete(MutableMap.hash(k)); + return this; + } + + get(key) { + let code = MutableMap.hash(key); + if (this.entries.has(code)) { + return new Ok(this.entries.get(code)[1]); + } else { + return new Error(Nil); + } + } +} + +export function new_mutable_map() { + return new MutableMap(); +} + +export function mutable_map_size(map) { + return map.size; +} + +export function mutable_map_to_list(map) { + return map.toList(); +} + +export function mutable_map_remove(k, map) { + return map.delete(k); +} + +export function mutable_map_get(map, key) { + return map.get(key); +} + +export function mutable_map_insert(key, value, map) { + return map.insert(key, value); +} + +// From map.mjs + +export function size(map) { + return mutable_map_size(map); +} + +export function to_list(map) { + return mutable_map_to_list(map); +} + +export function new$() { + return new_mutable_map(); +} + +export function get(from, get) { + return mutable_map_get(from, get); +} + +function do_has_key(key, map) { + return !isEqual(get(map, key), new Error(undefined)); +} + +export function has_key(map, key) { + return do_has_key(key, map); +} + +export function insert(map, key, value) { + return mutable_map_insert(key, value, map); +} + +function insert_pair(map, pair) { + return insert(map, pair[0], pair[1]); +} + +export function update(map, key, fun) { + let _pipe = map; + let _pipe$1 = get(_pipe, key); + let _pipe$2 = $option.from_result(_pipe$1); + let _pipe$3 = fun(_pipe$2); + return ((_capture) => { + return insert(map, key, _capture); + })(_pipe$3); +} + +export function delete$(map, key) { + return mutable_map_remove(key, map); +} + +function fold_list_of_pair(loop$list, loop$initial) { + while (true) { + let list = loop$list; + let initial = loop$initial; + if (list.hasLength(0)) { + return initial; + } else if (list.atLeastLength(1)) { + let x = list.head; + let rest = list.tail; + loop$list = rest; + loop$initial = insert(initial, x[0], x[1]); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 98, + "fold_list_of_pair", + "No case clause matched", + { values: [list] } + ); + } + } +} + +function do_from_list(list) { + return fold_list_of_pair(list, new$()); +} + +export function from_list(list) { + return do_from_list(list); +} + +function do_fold(loop$list, loop$initial, loop$fun) { + while (true) { + let list = loop$list; + let initial = loop$initial; + let fun = loop$fun; + if (list.hasLength(0)) { + return initial; + } else if (list.atLeastLength(1)) { + let k = list.head[0]; + let v = list.head[1]; + let tail = list.tail; + loop$list = tail; + loop$initial = fun(initial, k, v); + loop$fun = fun; + } else { + throw makeError( + "case_no_match", + "gleam/map", + 558, + "do_fold", + "No case clause matched", + { values: [list] } + ); + } + } +} + +export function fold(map, initial, fun) { + let _pipe = map; + let _pipe$1 = to_list(_pipe); + return do_fold(_pipe$1, initial, fun); +} + +function do_map_values(f, map) { + let f$1 = (map, k, v) => { + return insert(map, k, f(k, v)); + }; + let _pipe = map; + return fold(_pipe, new$(), f$1); +} + +export function map_values(map, fun) { + return do_map_values(fun, map); +} + +function do_filter(f, map) { + let insert$1 = (map, k, v) => { + let $ = f(k, v); + if ($) { + return insert(map, k, v); + } else { + return map; + } + }; + let _pipe = map; + return fold(_pipe, new$(), insert$1); +} + +export function filter(map, property) { + return do_filter(property, map); +} + +function do_keys_acc(loop$list, loop$acc) { + while (true) { + let list = loop$list; + let acc = loop$acc; + if (list.hasLength(0)) { + return reverse_and_concat(acc, toList([])); + } else if (list.atLeastLength(1)) { + let x = list.head; + let xs = list.tail; + loop$list = xs; + loop$acc = toList([x[0]], acc); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 276, + "do_keys_acc", + "No case clause matched", + { values: [list] } + ); + } + } +} + +function do_keys(map) { + let list_of_pairs = (() => { + let _pipe = map; + return to_list(_pipe); + })(); + return do_keys_acc(list_of_pairs, toList([])); +} + +export function keys(map) { + return do_keys(map); +} + +function reverse_and_concat(loop$remaining, loop$accumulator) { + while (true) { + let remaining = loop$remaining; + let accumulator = loop$accumulator; + if (remaining.hasLength(0)) { + return accumulator; + } else if (remaining.atLeastLength(1)) { + let item = remaining.head; + let rest = remaining.tail; + loop$remaining = rest; + loop$accumulator = toList([item], accumulator); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 269, + "reverse_and_concat", + "No case clause matched", + { values: [remaining] } + ); + } + } +} + +function do_values_acc(loop$list, loop$acc) { + while (true) { + let list = loop$list; + let acc = loop$acc; + if (list.hasLength(0)) { + return reverse_and_concat(acc, toList([])); + } else if (list.atLeastLength(1)) { + let x = list.head; + let xs = list.tail; + loop$list = xs; + loop$acc = toList([x[1]], acc); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 314, + "do_values_acc", + "No case clause matched", + { values: [list] } + ); + } + } +} + +function do_values(map) { + let list_of_pairs = (() => { + let _pipe = map; + return to_list(_pipe); + })(); + return do_values_acc(list_of_pairs, toList([])); +} + +export function values(map) { + return do_values(map); +} + +function insert_taken(loop$map, loop$desired_keys, loop$acc) { + while (true) { + let map = loop$map; + let desired_keys = loop$desired_keys; + let acc = loop$acc; + let insert$1 = (taken, key) => { + let $ = get(map, key); + if ($.isOk()) { + let value = $[0]; + return insert(taken, key, value); + } else { + return taken; + } + }; + if (desired_keys.hasLength(0)) { + return acc; + } else if (desired_keys.atLeastLength(1)) { + let x = desired_keys.head; + let xs = desired_keys.tail; + loop$map = map; + loop$desired_keys = xs; + loop$acc = insert$1(acc, x); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 411, + "insert_taken", + "No case clause matched", + { values: [desired_keys] } + ); + } + } +} + +function do_take(desired_keys, map) { + return insert_taken(map, desired_keys, new$()); +} + +export function take(map, desired_keys) { + return do_take(desired_keys, map); +} + +function fold_inserts(loop$new_entries, loop$map) { + while (true) { + let new_entries = loop$new_entries; + let map = loop$map; + if (new_entries.hasLength(0)) { + return map; + } else if (new_entries.atLeastLength(1)) { + let x = new_entries.head; + let xs = new_entries.tail; + loop$new_entries = xs; + loop$map = insert_pair(map, x); + } else { + throw makeError( + "case_no_match", + "gleam/map", + 451, + "fold_inserts", + "No case clause matched", + { values: [new_entries] } + ); + } + } +} + +function do_merge(map, new_entries) { + let _pipe = new_entries; + let _pipe$1 = to_list(_pipe); + return fold_inserts(_pipe$1, map); +} + +export function merge(map, new_entries) { + return do_merge(map, new_entries); +} + +export function drop(loop$map, loop$disallowed_keys) { + while (true) { + let map = loop$map; + let disallowed_keys = loop$disallowed_keys; + if (disallowed_keys.hasLength(0)) { + return map; + } else if (disallowed_keys.atLeastLength(1)) { + let x = disallowed_keys.head; + let xs = disallowed_keys.tail; + loop$map = delete$(map, x); + loop$disallowed_keys = xs; + } else { + throw makeError( + "case_no_match", + "gleam/map", + 514, + "drop", + "No case clause matched", + { values: [disallowed_keys] } + ); + } + } +} diff --git a/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap.app b/aoc2023/build/dev/erlang/gap/ebin/gap.app new file mode 100644 index 0000000..ae37254 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap.app @@ -0,0 +1,8 @@ +{application, gap, [ + {vsn, "1.0.1"}, + {applications, [gleam_community_ansi, + gleam_stdlib]}, + {description, "A Gleam library for comparing strings/lists and producing a textual (styled) representation of the differences."}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap.beam b/aoc2023/build/dev/erlang/gap/ebin/gap.beam Binary files differnew file mode 100644 index 0000000..4eaf513 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap.beam diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap@comparison.beam b/aoc2023/build/dev/erlang/gap/ebin/gap@comparison.beam Binary files differnew file mode 100644 index 0000000..44091a1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap@comparison.beam diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap@myers.beam b/aoc2023/build/dev/erlang/gap/ebin/gap@myers.beam Binary files differnew file mode 100644 index 0000000..d118f3d --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap@myers.beam diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap@styled_comparison.beam b/aoc2023/build/dev/erlang/gap/ebin/gap@styled_comparison.beam Binary files differnew file mode 100644 index 0000000..dfce198 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap@styled_comparison.beam diff --git a/aoc2023/build/dev/erlang/gap/ebin/gap@styling.beam b/aoc2023/build/dev/erlang/gap/ebin/gap@styling.beam Binary files differnew file mode 100644 index 0000000..cf975af --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/ebin/gap@styling.beam diff --git a/aoc2023/build/dev/erlang/gap/include/gap@comparison_ListComparison.hrl b/aoc2023/build/dev/erlang/gap/include/gap@comparison_ListComparison.hrl new file mode 100644 index 0000000..5e4b20d --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@comparison_ListComparison.hrl @@ -0,0 +1,4 @@ +-record(list_comparison, { + first :: list(gap@comparison:match(list(any()))), + second :: list(gap@comparison:match(list(any()))) +}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@comparison_Match.hrl b/aoc2023/build/dev/erlang/gap/include/gap@comparison_Match.hrl new file mode 100644 index 0000000..f1225dd --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@comparison_Match.hrl @@ -0,0 +1 @@ +-record(match, {item :: any()}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@comparison_NoMatch.hrl b/aoc2023/build/dev/erlang/gap/include/gap@comparison_NoMatch.hrl new file mode 100644 index 0000000..742783b --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@comparison_NoMatch.hrl @@ -0,0 +1 @@ +-record(no_match, {item :: any()}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@comparison_StringComparison.hrl b/aoc2023/build/dev/erlang/gap/include/gap@comparison_StringComparison.hrl new file mode 100644 index 0000000..c0b1a75 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@comparison_StringComparison.hrl @@ -0,0 +1,4 @@ +-record(string_comparison, { + first :: list(gap@comparison:match(list(binary()))), + second :: list(gap@comparison:match(list(binary()))) +}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@styled_comparison_StyledComparison.hrl b/aoc2023/build/dev/erlang/gap/include/gap@styled_comparison_StyledComparison.hrl new file mode 100644 index 0000000..0e7c64a --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@styled_comparison_StyledComparison.hrl @@ -0,0 +1 @@ +-record(styled_comparison, {first :: binary(), second :: binary()}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@styling_All.hrl b/aoc2023/build/dev/erlang/gap/include/gap@styling_All.hrl new file mode 100644 index 0000000..c11a9a6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@styling_All.hrl @@ -0,0 +1 @@ +-record(all, {all :: binary()}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@styling_Highlighters.hrl b/aoc2023/build/dev/erlang/gap/include/gap@styling_Highlighters.hrl new file mode 100644 index 0000000..6e073b3 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@styling_Highlighters.hrl @@ -0,0 +1,5 @@ +-record(highlighters, { + first :: fun((binary()) -> binary()), + second :: fun((binary()) -> binary()), + matching :: fun((binary()) -> binary()) +}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@styling_Part.hrl b/aoc2023/build/dev/erlang/gap/include/gap@styling_Part.hrl new file mode 100644 index 0000000..db45796 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@styling_Part.hrl @@ -0,0 +1,5 @@ +-record(part, { + acc :: binary(), + part :: list(any()), + highlight :: fun((binary()) -> binary()) +}). diff --git a/aoc2023/build/dev/erlang/gap/include/gap@styling_Styling.hrl b/aoc2023/build/dev/erlang/gap/include/gap@styling_Styling.hrl new file mode 100644 index 0000000..a7341c6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gap/include/gap@styling_Styling.hrl @@ -0,0 +1,5 @@ +-record(styling, { + comparison :: gap@comparison:comparison(any()), + serializer :: gleam@option:option(fun((gap@styling:part(any())) -> binary())), + highlight :: gleam@option:option(gap@styling:highlighters()) +}). diff --git a/aoc2023/build/dev/erlang/gleam.lock b/aoc2023/build/dev/erlang/gleam.lock new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam.lock diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache Binary files differnew file mode 100644 index 0000000..1f67bd7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache_meta b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache_meta Binary files differnew file mode 100644 index 0000000..a01f4e8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.erl b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.erl new file mode 100644 index 0000000..1698e1e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/_gleam_artefacts/gleam_community@ansi.erl @@ -0,0 +1,263 @@ +-module(gleam_community@ansi). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([reset/1, bold/1, dim/1, italic/1, underline/1, inverse/1, hidden/1, strikethrough/1, black/1, red/1, green/1, yellow/1, blue/1, magenta/1, cyan/1, white/1, bright_black/1, grey/1, gray/1, bright_red/1, bright_green/1, bright_yellow/1, bright_blue/1, bright_magenta/1, bright_cyan/1, bright_white/1, hex/2, pink/1, colour/2, color/2, bg_black/1, bg_red/1, bg_green/1, bg_yellow/1, bg_blue/1, bg_magenta/1, bg_cyan/1, bg_white/1, bg_bright_black/1, bg_bright_red/1, bg_bright_green/1, bg_bright_yellow/1, bg_bright_blue/1, bg_bright_magenta/1, bg_bright_cyan/1, bg_bright_white/1, bg_hex/2, bg_pink/1, bg_colour/2, bg_color/2]). +-export_type([code/0]). + +-type code() :: {code, binary(), binary(), binary()}. + +-spec run(binary(), code()) -> binary(). +run(Text, Code) -> + <<<<(erlang:element(2, Code))/binary, + (gleam@string:replace( + Text, + erlang:element(4, Code), + erlang:element(2, Code) + ))/binary>>/binary, + (erlang:element(3, Code))/binary>>. + +-spec code(list(integer()), integer()) -> code(). +code(Open, Close) -> + Close_str = gleam@int:to_string(Close), + Open_strs = gleam@list:map(Open, fun gleam@int:to_string/1), + {code, + <<<<<<""/utf8, "["/utf8>>/binary, + (gleam@string:join(Open_strs, <<";"/utf8>>))/binary>>/binary, + "m"/utf8>>, + <<<<<<""/utf8, "["/utf8>>/binary, Close_str/binary>>/binary, "m"/utf8>>, + <<<<<<""/utf8, "["/utf8>>/binary, Close_str/binary>>/binary, "m"/utf8>>}. + +-spec reset(binary()) -> binary(). +reset(Text) -> + run(Text, code([0], 0)). + +-spec bold(binary()) -> binary(). +bold(Text) -> + run(Text, code([1], 22)). + +-spec dim(binary()) -> binary(). +dim(Text) -> + run(Text, code([2], 22)). + +-spec italic(binary()) -> binary(). +italic(Text) -> + run(Text, code([3], 23)). + +-spec underline(binary()) -> binary(). +underline(Text) -> + run(Text, code([4], 24)). + +-spec inverse(binary()) -> binary(). +inverse(Text) -> + run(Text, code([7], 27)). + +-spec hidden(binary()) -> binary(). +hidden(Text) -> + run(Text, code([8], 28)). + +-spec strikethrough(binary()) -> binary(). +strikethrough(Text) -> + run(Text, code([9], 29)). + +-spec black(binary()) -> binary(). +black(Text) -> + run(Text, code([30], 39)). + +-spec red(binary()) -> binary(). +red(Text) -> + run(Text, code([31], 39)). + +-spec green(binary()) -> binary(). +green(Text) -> + run(Text, code([32], 39)). + +-spec yellow(binary()) -> binary(). +yellow(Text) -> + run(Text, code([33], 39)). + +-spec blue(binary()) -> binary(). +blue(Text) -> + run(Text, code([34], 39)). + +-spec magenta(binary()) -> binary(). +magenta(Text) -> + run(Text, code([35], 39)). + +-spec cyan(binary()) -> binary(). +cyan(Text) -> + run(Text, code([36], 39)). + +-spec white(binary()) -> binary(). +white(Text) -> + run(Text, code([37], 39)). + +-spec bright_black(binary()) -> binary(). +bright_black(Text) -> + run(Text, code([90], 39)). + +-spec grey(binary()) -> binary(). +grey(Text) -> + bright_black(Text). + +-spec gray(binary()) -> binary(). +gray(Text) -> + bright_black(Text). + +-spec bright_red(binary()) -> binary(). +bright_red(Text) -> + run(Text, code([91], 39)). + +-spec bright_green(binary()) -> binary(). +bright_green(Text) -> + run(Text, code([92], 39)). + +-spec bright_yellow(binary()) -> binary(). +bright_yellow(Text) -> + run(Text, code([93], 39)). + +-spec bright_blue(binary()) -> binary(). +bright_blue(Text) -> + run(Text, code([94], 39)). + +-spec bright_magenta(binary()) -> binary(). +bright_magenta(Text) -> + run(Text, code([95], 39)). + +-spec bright_cyan(binary()) -> binary(). +bright_cyan(Text) -> + run(Text, code([96], 39)). + +-spec bright_white(binary()) -> binary(). +bright_white(Text) -> + run(Text, code([97], 39)). + +-spec hex(binary(), integer()) -> binary(). +hex(Text, Colour) -> + Colour@1 = gleam@int:clamp(Colour, 16#0, 16#ffffff), + run( + Text, + code( + [38, + 2, + begin + _pipe = erlang:'bsr'(Colour@1, 16), + erlang:'band'(_pipe, 16#ff) + end, + begin + _pipe@1 = erlang:'bsr'(Colour@1, 8), + erlang:'band'(_pipe@1, 16#ff) + end, + erlang:'band'(Colour@1, 16#ff)], + 39 + ) + ). + +-spec pink(binary()) -> binary(). +pink(Text) -> + hex(Text, 16#ffaff3). + +-spec colour(binary(), gleam_community@colour:colour()) -> binary(). +colour(Text, Colour) -> + Hex_colour = gleam_community@colour:to_rgb_hex(Colour), + hex(Text, Hex_colour). + +-spec color(binary(), gleam_community@colour:colour()) -> binary(). +color(Text, Color) -> + colour(Text, Color). + +-spec bg_black(binary()) -> binary(). +bg_black(Text) -> + run(Text, code([40], 49)). + +-spec bg_red(binary()) -> binary(). +bg_red(Text) -> + run(Text, code([41], 49)). + +-spec bg_green(binary()) -> binary(). +bg_green(Text) -> + run(Text, code([42], 49)). + +-spec bg_yellow(binary()) -> binary(). +bg_yellow(Text) -> + run(Text, code([43], 49)). + +-spec bg_blue(binary()) -> binary(). +bg_blue(Text) -> + run(Text, code([44], 49)). + +-spec bg_magenta(binary()) -> binary(). +bg_magenta(Text) -> + run(Text, code([45], 49)). + +-spec bg_cyan(binary()) -> binary(). +bg_cyan(Text) -> + run(Text, code([46], 49)). + +-spec bg_white(binary()) -> binary(). +bg_white(Text) -> + run(Text, code([47], 49)). + +-spec bg_bright_black(binary()) -> binary(). +bg_bright_black(Text) -> + run(Text, code([100], 49)). + +-spec bg_bright_red(binary()) -> binary(). +bg_bright_red(Text) -> + run(Text, code([101], 49)). + +-spec bg_bright_green(binary()) -> binary(). +bg_bright_green(Text) -> + run(Text, code([102], 49)). + +-spec bg_bright_yellow(binary()) -> binary(). +bg_bright_yellow(Text) -> + run(Text, code([103], 49)). + +-spec bg_bright_blue(binary()) -> binary(). +bg_bright_blue(Text) -> + run(Text, code([104], 49)). + +-spec bg_bright_magenta(binary()) -> binary(). +bg_bright_magenta(Text) -> + run(Text, code([105], 49)). + +-spec bg_bright_cyan(binary()) -> binary(). +bg_bright_cyan(Text) -> + run(Text, code([106], 49)). + +-spec bg_bright_white(binary()) -> binary(). +bg_bright_white(Text) -> + run(Text, code([107], 49)). + +-spec bg_hex(binary(), integer()) -> binary(). +bg_hex(Text, Colour) -> + run( + Text, + code( + [48, + 2, + begin + _pipe = erlang:'bsr'(Colour, 16), + erlang:'band'(_pipe, 16#ff) + end, + begin + _pipe@1 = erlang:'bsr'(Colour, 8), + erlang:'band'(_pipe@1, 16#ff) + end, + erlang:'band'(Colour, 16#ff)], + 49 + ) + ). + +-spec bg_pink(binary()) -> binary(). +bg_pink(Text) -> + bg_hex(Text, 16#ffaff3). + +-spec bg_colour(binary(), gleam_community@colour:colour()) -> binary(). +bg_colour(Text, Colour) -> + Hex_colour = gleam_community@colour:to_rgb_hex(Colour), + bg_hex(Text, Hex_colour). + +-spec bg_color(binary(), gleam_community@colour:colour()) -> binary(). +bg_color(Text, Colour) -> + bg_colour(Text, Colour). diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community@ansi.beam b/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community@ansi.beam Binary files differnew file mode 100644 index 0000000..e94b760 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community@ansi.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community_ansi.app b/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community_ansi.app new file mode 100644 index 0000000..90e4d4a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_ansi/ebin/gleam_community_ansi.app @@ -0,0 +1,8 @@ +{application, gleam_community_ansi, [ + {vsn, "1.2.0"}, + {applications, [gleam_community_colour, + gleam_stdlib]}, + {description, "ANSI colours, formatting, and control codes"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache Binary files differnew file mode 100644 index 0000000..c12620f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache_meta b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache_meta Binary files differnew file mode 100644 index 0000000..3584f7e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.erl b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.erl new file mode 100644 index 0000000..2bb8422 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour.erl @@ -0,0 +1,513 @@ +-module(gleam_community@colour). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from_rgb255/3, from_rgb/3, from_rgba/4, from_hsla/4, from_hsl/3, from_rgb_hex/1, from_rgb_hex_string/1, from_rgba_hex/1, from_rgba_hex_string/1, to_rgba/1, to_hsla/1, to_css_rgba_string/1, to_rgba_hex/1, to_rgba_hex_string/1, to_rgb_hex/1, to_rgb_hex_string/1]). +-export_type([colour/0]). + +-opaque colour() :: {rgba, float(), float(), float(), float()} | + {hsla, float(), float(), float(), float()}. + +-spec valid_colour_value(float()) -> {ok, float()} | {error, nil}. +valid_colour_value(C) -> + case (C > 1.0) orelse (C < +0.0) of + true -> + {error, nil}; + + false -> + {ok, C} + end. + +-spec hue_to_rgb(float(), float(), float()) -> float(). +hue_to_rgb(Hue, M1, M2) -> + H = case Hue of + _ when Hue < +0.0 -> + Hue + 1.0; + + _ when Hue > 1.0 -> + Hue - 1.0; + + _ -> + Hue + end, + H_t_6 = H * 6.0, + H_t_2 = H * 2.0, + H_t_3 = H * 3.0, + case H of + _ when H_t_6 < 1.0 -> + M1 + (((M2 - M1) * H) * 6.0); + + _ when H_t_2 < 1.0 -> + M2; + + _ when H_t_3 < 2.0 -> + M1 + (((M2 - M1) * ((2.0 / 3.0) - H)) * 6.0); + + _ -> + M1 + end. + +-spec hex_string_to_int(binary()) -> {ok, integer()} | {error, nil}. +hex_string_to_int(Hex_string) -> + Hex = case Hex_string of + <<"#"/utf8, Hex_number/binary>> -> + Hex_number; + + <<"0x"/utf8, Hex_number@1/binary>> -> + Hex_number@1; + + _ -> + Hex_string + end, + _pipe = Hex, + _pipe@1 = gleam@string:lowercase(_pipe), + _pipe@2 = gleam@string:to_graphemes(_pipe@1), + _pipe@3 = gleam@list:reverse(_pipe@2), + gleam@list:index_fold( + _pipe@3, + {ok, 0}, + fun(Total, Char, Index) -> case Total of + {error, nil} -> + {error, nil}; + + {ok, V} -> + gleam@result:then(case Char of + <<"a"/utf8>> -> + {ok, 10}; + + <<"b"/utf8>> -> + {ok, 11}; + + <<"c"/utf8>> -> + {ok, 12}; + + <<"d"/utf8>> -> + {ok, 13}; + + <<"e"/utf8>> -> + {ok, 14}; + + <<"f"/utf8>> -> + {ok, 15}; + + _ -> + gleam@int:parse(Char) + end, fun(Num) -> + gleam@result:then( + gleam@int:power(16, gleam@int:to_float(Index)), + fun(Base) -> + {ok, + V + gleam@float:round( + gleam@int:to_float(Num) * Base + )} + end + ) + end) + end end + ). + +-spec hsla_to_rgba(float(), float(), float(), float()) -> {float(), + float(), + float(), + float()}. +hsla_to_rgba(H, S, L, A) -> + M2 = case L =< 0.5 of + true -> + L * (S + 1.0); + + false -> + (L + S) - (L * S) + end, + M1 = (L * 2.0) - M2, + R = hue_to_rgb(H + (1.0 / 3.0), M1, M2), + G = hue_to_rgb(H, M1, M2), + B = hue_to_rgb(H - (1.0 / 3.0), M1, M2), + {R, G, B, A}. + +-spec rgba_to_hsla(float(), float(), float(), float()) -> {float(), + float(), + float(), + float()}. +rgba_to_hsla(R, G, B, A) -> + Min_colour = gleam@float:min(R, gleam@float:min(G, B)), + Max_colour = gleam@float:max(R, gleam@float:max(G, B)), + H1 = case true of + _ when Max_colour =:= R -> + gleam@float:divide(G - B, Max_colour - Min_colour); + + _ when Max_colour =:= G -> + _pipe = gleam@float:divide(B - R, Max_colour - Min_colour), + gleam@result:then(_pipe, fun(D) -> {ok, 2.0 + D} end); + + _ -> + _pipe@1 = gleam@float:divide(R - G, Max_colour - Min_colour), + gleam@result:then(_pipe@1, fun(D@1) -> {ok, 4.0 + D@1} end) + end, + H2 = case H1 of + {ok, V} -> + {ok, V * (1.0 / 6.0)}; + + _ -> + H1 + end, + H3 = case H2 of + {ok, V@1} when V@1 < +0.0 -> + V@1 + 1.0; + + {ok, V@2} -> + V@2; + + _ -> + +0.0 + end, + L = (Min_colour + Max_colour) / 2.0, + S = case true of + _ when Min_colour =:= Max_colour -> + +0.0; + + _ when L < 0.5 -> + case (Max_colour + Min_colour) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> (Max_colour - Min_colour) / Gleam@denominator + end; + + _ -> + case ((2.0 - Max_colour) - Min_colour) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> (Max_colour - Min_colour) / Gleam@denominator@1 + end + end, + {H3, S, L, A}. + +-spec from_rgb255(integer(), integer(), integer()) -> {ok, colour()} | + {error, nil}. +from_rgb255(Red, Green, Blue) -> + gleam@result:then( + begin + _pipe = Red, + _pipe@1 = gleam@int:to_float(_pipe), + _pipe@2 = gleam@float:divide(_pipe@1, 255.0), + gleam@result:then(_pipe@2, fun valid_colour_value/1) + end, + fun(R) -> + gleam@result:then( + begin + _pipe@3 = Green, + _pipe@4 = gleam@int:to_float(_pipe@3), + _pipe@5 = gleam@float:divide(_pipe@4, 255.0), + gleam@result:then(_pipe@5, fun valid_colour_value/1) + end, + fun(G) -> + gleam@result:then( + begin + _pipe@6 = Blue, + _pipe@7 = gleam@int:to_float(_pipe@6), + _pipe@8 = gleam@float:divide(_pipe@7, 255.0), + gleam@result:then(_pipe@8, fun valid_colour_value/1) + end, + fun(B) -> {ok, {rgba, R, G, B, 1.0}} end + ) + end + ) + end + ). + +-spec from_rgb(float(), float(), float()) -> {ok, colour()} | {error, nil}. +from_rgb(Red, Green, Blue) -> + gleam@result:then( + valid_colour_value(Red), + fun(R) -> + gleam@result:then( + valid_colour_value(Green), + fun(G) -> + gleam@result:then( + valid_colour_value(Blue), + fun(B) -> {ok, {rgba, R, G, B, 1.0}} end + ) + end + ) + end + ). + +-spec from_rgba(float(), float(), float(), float()) -> {ok, colour()} | + {error, nil}. +from_rgba(Red, Green, Blue, Alpha) -> + gleam@result:then( + valid_colour_value(Red), + fun(R) -> + gleam@result:then( + valid_colour_value(Green), + fun(G) -> + gleam@result:then( + valid_colour_value(Blue), + fun(B) -> + gleam@result:then( + valid_colour_value(Alpha), + fun(A) -> {ok, {rgba, R, G, B, A}} end + ) + end + ) + end + ) + end + ). + +-spec from_hsla(float(), float(), float(), float()) -> {ok, colour()} | + {error, nil}. +from_hsla(Hue, Saturation, Lightness, Alpha) -> + gleam@result:then( + valid_colour_value(Hue), + fun(H) -> + gleam@result:then( + valid_colour_value(Saturation), + fun(S) -> + gleam@result:then( + valid_colour_value(Lightness), + fun(L) -> + gleam@result:then( + valid_colour_value(Alpha), + fun(A) -> {ok, {hsla, H, S, L, A}} end + ) + end + ) + end + ) + end + ). + +-spec from_hsl(float(), float(), float()) -> {ok, colour()} | {error, nil}. +from_hsl(Hue, Saturation, Lightness) -> + from_hsla(Hue, Saturation, Lightness, 1.0). + +-spec from_rgb_hex(integer()) -> {ok, colour()} | {error, nil}. +from_rgb_hex(Hex) -> + case (Hex > 16#ffffff) orelse (Hex < 0) of + true -> + {error, nil}; + + false -> + R = begin + _pipe = erlang:'bsr'(Hex, 16), + erlang:'band'(_pipe, 16#ff) + end, + G = begin + _pipe@1 = erlang:'bsr'(Hex, 8), + erlang:'band'(_pipe@1, 16#ff) + end, + B = erlang:'band'(Hex, 16#ff), + from_rgb255(R, G, B) + end. + +-spec from_rgb_hex_string(binary()) -> {ok, colour()} | {error, nil}. +from_rgb_hex_string(Hex_string) -> + gleam@result:then( + hex_string_to_int(Hex_string), + fun(Hex_int) -> from_rgb_hex(Hex_int) end + ). + +-spec from_rgba_hex(integer()) -> {ok, colour()} | {error, nil}. +from_rgba_hex(Hex) -> + case (Hex > 16#ffffffff) orelse (Hex < 0) of + true -> + {error, nil}; + + false -> + _assert_subject = begin + _pipe = erlang:'bsr'(Hex, 24), + _pipe@1 = erlang:'band'(_pipe, 16#ff), + _pipe@2 = gleam@int:to_float(_pipe@1), + gleam@float:divide(_pipe@2, 255.0) + end, + {ok, R} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/colour"/utf8>>, + function => <<"from_rgba_hex"/utf8>>, + line => 588}) + end, + _assert_subject@1 = begin + _pipe@3 = erlang:'bsr'(Hex, 16), + _pipe@4 = erlang:'band'(_pipe@3, 16#ff), + _pipe@5 = gleam@int:to_float(_pipe@4), + gleam@float:divide(_pipe@5, 255.0) + end, + {ok, G} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/colour"/utf8>>, + function => <<"from_rgba_hex"/utf8>>, + line => 594}) + end, + _assert_subject@2 = begin + _pipe@6 = erlang:'bsr'(Hex, 8), + _pipe@7 = erlang:'band'(_pipe@6, 16#ff), + _pipe@8 = gleam@int:to_float(_pipe@7), + gleam@float:divide(_pipe@8, 255.0) + end, + {ok, B} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"gleam_community/colour"/utf8>>, + function => <<"from_rgba_hex"/utf8>>, + line => 600}) + end, + _assert_subject@3 = begin + _pipe@9 = erlang:'band'(Hex, 16#ff), + _pipe@10 = gleam@int:to_float(_pipe@9), + gleam@float:divide(_pipe@10, 255.0) + end, + {ok, A} = case _assert_subject@3 of + {ok, _} -> _assert_subject@3; + _assert_fail@3 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@3, + module => <<"gleam_community/colour"/utf8>>, + function => <<"from_rgba_hex"/utf8>>, + line => 606}) + end, + from_rgba(R, G, B, A) + end. + +-spec from_rgba_hex_string(binary()) -> {ok, colour()} | {error, nil}. +from_rgba_hex_string(Hex_string) -> + gleam@result:then( + hex_string_to_int(Hex_string), + fun(Hex_int) -> from_rgba_hex(Hex_int) end + ). + +-spec to_rgba(colour()) -> {float(), float(), float(), float()}. +to_rgba(Colour) -> + case Colour of + {rgba, R, G, B, A} -> + {R, G, B, A}; + + {hsla, H, S, L, A@1} -> + hsla_to_rgba(H, S, L, A@1) + end. + +-spec to_hsla(colour()) -> {float(), float(), float(), float()}. +to_hsla(Colour) -> + case Colour of + {hsla, H, S, L, A} -> + {H, S, L, A}; + + {rgba, R, G, B, A@1} -> + rgba_to_hsla(R, G, B, A@1) + end. + +-spec to_css_rgba_string(colour()) -> binary(). +to_css_rgba_string(Colour) -> + {R, G, B, A} = to_rgba(Colour), + Percent = fun(X) -> + _assert_subject = begin + _pipe = X, + _pipe@1 = gleam@float:multiply(_pipe, 10000.0), + _pipe@2 = gleam@float:round(_pipe@1), + _pipe@3 = gleam@int:to_float(_pipe@2), + gleam@float:divide(_pipe@3, 100.0) + end, + {ok, P} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/colour"/utf8>>, + function => <<"to_css_rgba_string"/utf8>>, + line => 704}) + end, + P + end, + Round_to = fun(X@1) -> + _assert_subject@1 = begin + _pipe@4 = X@1, + _pipe@5 = gleam@float:multiply(_pipe@4, 1000.0), + _pipe@6 = gleam@float:round(_pipe@5), + _pipe@7 = gleam@int:to_float(_pipe@6), + gleam@float:divide(_pipe@7, 1000.0) + end, + {ok, R@1} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/colour"/utf8>>, + function => <<"to_css_rgba_string"/utf8>>, + line => 716}) + end, + R@1 + end, + gleam@string:join( + [<<"rgba("/utf8>>, + <<(gleam@float:to_string(Percent(R)))/binary, "%,"/utf8>>, + <<(gleam@float:to_string(Percent(G)))/binary, "%,"/utf8>>, + <<(gleam@float:to_string(Percent(B)))/binary, "%,"/utf8>>, + gleam@float:to_string(Round_to(A)), + <<")"/utf8>>], + <<""/utf8>> + ). + +-spec to_rgba_hex(colour()) -> integer(). +to_rgba_hex(Colour) -> + {R, G, B, A} = to_rgba(Colour), + Red = begin + _pipe = R * 255.0, + _pipe@1 = gleam@float:round(_pipe), + erlang:'bsl'(_pipe@1, 24) + end, + Green = begin + _pipe@2 = G * 255.0, + _pipe@3 = gleam@float:round(_pipe@2), + erlang:'bsl'(_pipe@3, 16) + end, + Blue = begin + _pipe@4 = B * 255.0, + _pipe@5 = gleam@float:round(_pipe@4), + erlang:'bsl'(_pipe@5, 8) + end, + Alpha = begin + _pipe@6 = A * 255.0, + gleam@float:round(_pipe@6) + end, + ((Red + Green) + Blue) + Alpha. + +-spec to_rgba_hex_string(colour()) -> binary(). +to_rgba_hex_string(Colour) -> + _pipe = to_rgba_hex(Colour), + gleam@int:to_base16(_pipe). + +-spec to_rgb_hex(colour()) -> integer(). +to_rgb_hex(Colour) -> + {R, G, B, _} = to_rgba(Colour), + Red = begin + _pipe = R * 255.0, + _pipe@1 = gleam@float:round(_pipe), + erlang:'bsl'(_pipe@1, 16) + end, + Green = begin + _pipe@2 = G * 255.0, + _pipe@3 = gleam@float:round(_pipe@2), + erlang:'bsl'(_pipe@3, 8) + end, + Blue = begin + _pipe@4 = B * 255.0, + gleam@float:round(_pipe@4) + end, + (Red + Green) + Blue. + +-spec to_rgb_hex_string(colour()) -> binary(). +to_rgb_hex_string(Colour) -> + _pipe = to_rgb_hex(Colour), + gleam@int:to_base16(_pipe). diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache Binary files differnew file mode 100644 index 0000000..5c98611 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache_meta b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache_meta Binary files differnew file mode 100644 index 0000000..0c78df4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.erl b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.erl new file mode 100644 index 0000000..4370842 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/_gleam_artefacts/gleam_community@colour@accessibility.erl @@ -0,0 +1,75 @@ +-module(gleam_community@colour@accessibility). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([luminance/1, contrast_ratio/2, maximum_contrast/2]). + +-spec intensity(float()) -> float(). +intensity(Colour_value) -> + case true of + _ when Colour_value =< 0.03928 -> + Colour_value / 12.92; + + _ -> + _assert_subject = gleam@float:power( + (Colour_value + 0.055) / 1.055, + 2.4 + ), + {ok, I} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/colour/accessibility"/utf8>>, + function => <<"intensity"/utf8>>, + line => 62}) + end, + I + end. + +-spec luminance(gleam_community@colour:colour()) -> float(). +luminance(Colour) -> + {R, G, B, _} = gleam_community@colour:to_rgba(Colour), + R_intensity = intensity(R), + G_intensity = intensity(G), + B_intensity = intensity(B), + ((0.2126 * R_intensity) + (0.7152 * G_intensity)) + (0.0722 * B_intensity). + +-spec contrast_ratio( + gleam_community@colour:colour(), + gleam_community@colour:colour() +) -> float(). +contrast_ratio(Colour_a, Colour_b) -> + Luminance_a = luminance(Colour_a) + 0.05, + Luminance_b = luminance(Colour_b) + 0.05, + case Luminance_a > Luminance_b of + true -> + case Luminance_b of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> Luminance_a / Gleam@denominator + end; + + false -> + case Luminance_a of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> Luminance_b / Gleam@denominator@1 + end + end. + +-spec maximum_contrast( + gleam_community@colour:colour(), + list(gleam_community@colour:colour()) +) -> {ok, gleam_community@colour:colour()} | {error, nil}. +maximum_contrast(Base, Colours) -> + _pipe = Colours, + _pipe@1 = gleam@list:sort( + _pipe, + fun(Colour_a, Colour_b) -> + Contrast_a = contrast_ratio(Base, Colour_a), + Contrast_b = contrast_ratio(Base, Colour_b), + gleam@float:compare(Contrast_b, Contrast_a) + end + ), + gleam@list:first(_pipe@1). diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour.beam b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour.beam Binary files differnew file mode 100644 index 0000000..008c06a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour@accessibility.beam b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour@accessibility.beam Binary files differnew file mode 100644 index 0000000..15e491b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community@colour@accessibility.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community_colour.app b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community_colour.app new file mode 100644 index 0000000..51800d3 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/ebin/gleam_community_colour.app @@ -0,0 +1,7 @@ +{application, gleam_community_colour, [ + {vsn, "1.2.0"}, + {applications, [gleam_stdlib]}, + {description, "Colour types, conversions, and other utilities"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Hsla.hrl b/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Hsla.hrl new file mode 100644 index 0000000..06116df --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Hsla.hrl @@ -0,0 +1 @@ +-record(hsla, {h :: float(), s :: float(), l :: float(), a :: float()}). diff --git a/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Rgba.hrl b/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Rgba.hrl new file mode 100644 index 0000000..fff139e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_colour/include/gleam_community@colour_Rgba.hrl @@ -0,0 +1 @@ +-record(rgba, {r :: float(), g :: float(), b :: float(), a :: float()}). diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache Binary files differnew file mode 100644 index 0000000..b683c40 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache_meta Binary files differnew file mode 100644 index 0000000..23d4726 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.erl new file mode 100644 index 0000000..b45f48e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@arithmetics.erl @@ -0,0 +1,172 @@ +-module(gleam_community@maths@arithmetics). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([gcd/2, lcm/2, divisors/1, proper_divisors/1, float_sum/1, int_sum/1, float_product/1, int_product/1, float_cumulative_sum/1, int_cumulative_sum/1, float_cumumlative_product/1, int_cumulative_product/1]). + +-spec do_gcd(integer(), integer()) -> integer(). +do_gcd(X, Y) -> + case X =:= 0 of + true -> + Y; + + false -> + _assert_subject = gleam@int:modulo(Y, X), + {ok, Z} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/arithmetics"/utf8>>, + function => <<"do_gcd"/utf8>>, + line => 93}) + end, + do_gcd(Z, X) + end. + +-spec gcd(integer(), integer()) -> integer(). +gcd(X, Y) -> + Absx = gleam_community@maths@piecewise:int_absolute_value(X), + Absy = gleam_community@maths@piecewise:int_absolute_value(Y), + do_gcd(Absx, Absy). + +-spec lcm(integer(), integer()) -> integer(). +lcm(X, Y) -> + Absx = gleam_community@maths@piecewise:int_absolute_value(X), + Absy = gleam_community@maths@piecewise:int_absolute_value(Y), + case do_gcd(Absx, Absy) of + 0 -> 0; + Gleam@denominator -> Absx * Absy div Gleam@denominator + end. + +-spec find_divisors(integer()) -> list(integer()). +find_divisors(N) -> + Nabs = gleam_community@maths@piecewise:float_absolute_value( + gleam_community@maths@conversion:int_to_float(N) + ), + _assert_subject = gleam_community@maths@elementary:square_root(Nabs), + {ok, Sqrt_result} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/arithmetics"/utf8>>, + function => <<"find_divisors"/utf8>>, + line => 176}) + end, + Max = gleam_community@maths@conversion:float_to_int(Sqrt_result) + 1, + _pipe = gleam@list:range(2, Max), + _pipe@1 = gleam@list:fold(_pipe, [1, N], fun(Acc, I) -> case (case I of + 0 -> 0; + Gleam@denominator -> N rem Gleam@denominator + end) =:= 0 of + true -> + [I, case I of + 0 -> 0; + Gleam@denominator@1 -> N div Gleam@denominator@1 + end | Acc]; + + false -> + Acc + end end), + _pipe@2 = gleam@list:unique(_pipe@1), + gleam@list:sort(_pipe@2, fun gleam@int:compare/2). + +-spec divisors(integer()) -> list(integer()). +divisors(N) -> + find_divisors(N). + +-spec proper_divisors(integer()) -> list(integer()). +proper_divisors(N) -> + Divisors = find_divisors(N), + _pipe = Divisors, + gleam@list:take(_pipe, gleam@list:length(Divisors) - 1). + +-spec float_sum(list(float())) -> float(). +float_sum(Arr) -> + case Arr of + [] -> + +0.0; + + _ -> + _pipe = Arr, + gleam@list:fold(_pipe, +0.0, fun(Acc, A) -> A + Acc end) + end. + +-spec int_sum(list(integer())) -> integer(). +int_sum(Arr) -> + case Arr of + [] -> + 0; + + _ -> + _pipe = Arr, + gleam@list:fold(_pipe, 0, fun(Acc, A) -> A + Acc end) + end. + +-spec float_product(list(float())) -> float(). +float_product(Arr) -> + case Arr of + [] -> + 1.0; + + _ -> + _pipe = Arr, + gleam@list:fold(_pipe, 1.0, fun(Acc, A) -> A * Acc end) + end. + +-spec int_product(list(integer())) -> integer(). +int_product(Arr) -> + case Arr of + [] -> + 1; + + _ -> + _pipe = Arr, + gleam@list:fold(_pipe, 1, fun(Acc, A) -> A * Acc end) + end. + +-spec float_cumulative_sum(list(float())) -> list(float()). +float_cumulative_sum(Arr) -> + case Arr of + [] -> + []; + + _ -> + _pipe = Arr, + gleam@list:scan(_pipe, +0.0, fun(Acc, A) -> A + Acc end) + end. + +-spec int_cumulative_sum(list(integer())) -> list(integer()). +int_cumulative_sum(Arr) -> + case Arr of + [] -> + []; + + _ -> + _pipe = Arr, + gleam@list:scan(_pipe, 0, fun(Acc, A) -> A + Acc end) + end. + +-spec float_cumumlative_product(list(float())) -> list(float()). +float_cumumlative_product(Arr) -> + case Arr of + [] -> + []; + + _ -> + _pipe = Arr, + gleam@list:scan(_pipe, 1.0, fun(Acc, A) -> A * Acc end) + end. + +-spec int_cumulative_product(list(integer())) -> list(integer()). +int_cumulative_product(Arr) -> + case Arr of + [] -> + []; + + _ -> + _pipe = Arr, + gleam@list:scan(_pipe, 1, fun(Acc, A) -> A * Acc end) + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache Binary files differnew file mode 100644 index 0000000..e95a3b0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache_meta Binary files differnew file mode 100644 index 0000000..f8262ee --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.erl new file mode 100644 index 0000000..00130c0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@combinatorics.erl @@ -0,0 +1,218 @@ +-module(gleam_community@maths@combinatorics). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([combination/2, factorial/1, permutation/2, list_combination/2, list_permutation/1, cartesian_product/2]). + +-spec combination(integer(), integer()) -> {ok, integer()} | {error, binary()}. +combination(N, K) -> + case N < 0 of + true -> + _pipe = <<"Invalid input argument: n < 0. Valid input is n > 0."/utf8>>, + {error, _pipe}; + + false -> + case (K < 0) orelse (K > N) of + true -> + _pipe@1 = 0, + {ok, _pipe@1}; + + false -> + case (K =:= 0) orelse (K =:= N) of + true -> + _pipe@2 = 1, + {ok, _pipe@2}; + + false -> + Min = case K < (N - K) of + true -> + K; + + false -> + N - K + end, + _pipe@3 = gleam@list:range(1, Min), + _pipe@4 = gleam@list:fold( + _pipe@3, + 1, + fun(Acc, X) -> case X of + 0 -> 0; + Gleam@denominator -> Acc * ((N + 1) - X) + div Gleam@denominator + end end + ), + {ok, _pipe@4} + end + end + end. + +-spec factorial(integer()) -> {ok, integer()} | {error, binary()}. +factorial(N) -> + case N < 0 of + true -> + _pipe = <<"Invalid input argument: n < 0. Valid input is n > 0."/utf8>>, + {error, _pipe}; + + false -> + case N of + 0 -> + _pipe@1 = 1, + {ok, _pipe@1}; + + 1 -> + _pipe@2 = 1, + {ok, _pipe@2}; + + _ -> + _pipe@3 = gleam@list:range(1, N), + _pipe@4 = gleam@list:fold( + _pipe@3, + 1, + fun(Acc, X) -> Acc * X end + ), + {ok, _pipe@4} + end + end. + +-spec permutation(integer(), integer()) -> {ok, integer()} | {error, binary()}. +permutation(N, K) -> + case N < 0 of + true -> + _pipe = <<"Invalid input argument: n < 0. Valid input is n > 0."/utf8>>, + {error, _pipe}; + + false -> + case (K < 0) orelse (K > N) of + true -> + _pipe@1 = 0, + {ok, _pipe@1}; + + false -> + case K =:= N of + true -> + _pipe@2 = 1, + {ok, _pipe@2}; + + false -> + _assert_subject = factorial(N), + {ok, V1} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/combinatorics"/utf8>>, + function => <<"permutation"/utf8>>, + line => 241}) + end, + _assert_subject@1 = factorial(N - K), + {ok, V2} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/combinatorics"/utf8>>, + function => <<"permutation"/utf8>>, + line => 242}) + end, + _pipe@3 = case V2 of + 0 -> 0; + Gleam@denominator -> V1 div Gleam@denominator + end, + {ok, _pipe@3} + end + end + end. + +-spec do_list_combination(list(JGD), integer(), list(JGD)) -> list(list(JGD)). +do_list_combination(Arr, K, Prefix) -> + case K of + 0 -> + [gleam@list:reverse(Prefix)]; + + _ -> + case Arr of + [] -> + []; + + [X | Xs] -> + With_x = do_list_combination(Xs, K - 1, [X | Prefix]), + Without_x = do_list_combination(Xs, K, Prefix), + gleam@list:append(With_x, Without_x) + end + end. + +-spec list_combination(list(JFX), integer()) -> {ok, list(list(JFX))} | + {error, binary()}. +list_combination(Arr, K) -> + case K < 0 of + true -> + _pipe = <<"Invalid input argument: k < 0. Valid input is k > 0."/utf8>>, + {error, _pipe}; + + false -> + case K > gleam@list:length(Arr) of + true -> + _pipe@1 = <<"Invalid input argument: k > length(arr). Valid input is 0 < k <= length(arr)."/utf8>>, + {error, _pipe@1}; + + false -> + _pipe@2 = do_list_combination(Arr, K, []), + {ok, _pipe@2} + end + end. + +-spec list_permutation(list(JGI)) -> list(list(JGI)). +list_permutation(Arr) -> + case Arr of + [] -> + [[]]; + + _ -> + gleam@list:flat_map( + Arr, + fun(X) -> + _assert_subject = gleam@list:pop(Arr, fun(Y) -> X =:= Y end), + {ok, {_, Remaining}} = case _assert_subject of + {ok, {_, _}} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/combinatorics"/utf8>>, + function => <<"list_permutation"/utf8>>, + line => 373}) + end, + gleam@list:map( + list_permutation(Remaining), + fun(Perm) -> [X | Perm] end + ) + end + ) + end. + +-spec cartesian_product(list(JGM), list(JGM)) -> list({JGM, JGM}). +cartesian_product(Xarr, Yarr) -> + Xset = begin + _pipe = Xarr, + gleam@set:from_list(_pipe) + end, + Yset = begin + _pipe@1 = Yarr, + gleam@set:from_list(_pipe@1) + end, + _pipe@2 = Xset, + _pipe@3 = gleam@set:fold( + _pipe@2, + gleam@set:new(), + fun(Accumulator0, Member0) -> + gleam@set:fold( + Yset, + Accumulator0, + fun(Accumulator1, Member1) -> + gleam@set:insert(Accumulator1, {Member0, Member1}) + end + ) + end + ), + gleam@set:to_list(_pipe@3). diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache Binary files differnew file mode 100644 index 0000000..6b3ed43 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache_meta Binary files differnew file mode 100644 index 0000000..374a6fb --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.erl new file mode 100644 index 0000000..1e44006 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@conversion.erl @@ -0,0 +1,24 @@ +-module(gleam_community@maths@conversion). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([int_to_float/1, float_to_int/1, degrees_to_radians/1, radians_to_degrees/1]). + +-spec int_to_float(integer()) -> float(). +int_to_float(X) -> + gleam@int:to_float(X). + +-spec float_to_int(float()) -> integer(). +float_to_int(X) -> + erlang:trunc(X). + +-spec degrees_to_radians(float()) -> float(). +degrees_to_radians(X) -> + (X * math:pi()) / 180.0. + +-spec radians_to_degrees(float()) -> float(). +radians_to_degrees(X) -> + case math:pi() of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> X * 180.0 / Gleam@denominator + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache Binary files differnew file mode 100644 index 0000000..5dbff0c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache_meta Binary files differnew file mode 100644 index 0000000..8a3590f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.erl new file mode 100644 index 0000000..422021e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@elementary.erl @@ -0,0 +1,286 @@ +-module(gleam_community@maths@elementary). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([acos/1, acosh/1, asin/1, asinh/1, atan/1, atan2/2, atanh/1, cos/1, cosh/1, sin/1, sinh/1, tan/1, tanh/1, exponential/1, natural_logarithm/1, logarithm_2/1, logarithm_10/1, logarithm/2, power/2, square_root/1, cube_root/1, nth_root/2, pi/0, tau/0, e/0]). + +-spec acos(float()) -> {ok, float()} | {error, binary()}. +acos(X) -> + case (X >= -1.0) andalso (X =< 1.0) of + true -> + _pipe = math:acos(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x >= -1 or x <= 1. Valid input is -1. <= x <= 1."/utf8>>, + {error, _pipe@1} + end. + +-spec acosh(float()) -> {ok, float()} | {error, binary()}. +acosh(X) -> + case X >= 1.0 of + true -> + _pipe = math:acosh(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x < 1. Valid input is x >= 1."/utf8>>, + {error, _pipe@1} + end. + +-spec asin(float()) -> {ok, float()} | {error, binary()}. +asin(X) -> + case (X >= -1.0) andalso (X =< 1.0) of + true -> + _pipe = math:asin(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x >= -1 or x <= 1. Valid input is -1. <= x <= 1."/utf8>>, + {error, _pipe@1} + end. + +-spec asinh(float()) -> float(). +asinh(X) -> + math:asinh(X). + +-spec atan(float()) -> float(). +atan(X) -> + math:atan(X). + +-spec atan2(float(), float()) -> float(). +atan2(Y, X) -> + math:atan2(Y, X). + +-spec atanh(float()) -> {ok, float()} | {error, binary()}. +atanh(X) -> + case (X > -1.0) andalso (X < 1.0) of + true -> + _pipe = math:atanh(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x > -1 or x < 1. Valid input is -1. < x < 1."/utf8>>, + {error, _pipe@1} + end. + +-spec cos(float()) -> float(). +cos(X) -> + math:cos(X). + +-spec cosh(float()) -> float(). +cosh(X) -> + math:cosh(X). + +-spec sin(float()) -> float(). +sin(X) -> + math:sin(X). + +-spec sinh(float()) -> float(). +sinh(X) -> + math:sinh(X). + +-spec tan(float()) -> float(). +tan(X) -> + math:tan(X). + +-spec tanh(float()) -> float(). +tanh(X) -> + math:tanh(X). + +-spec exponential(float()) -> float(). +exponential(X) -> + math:exp(X). + +-spec natural_logarithm(float()) -> {ok, float()} | {error, binary()}. +natural_logarithm(X) -> + case X > +0.0 of + true -> + _pipe = math:log(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x <= 0. Valid input is x > 0."/utf8>>, + {error, _pipe@1} + end. + +-spec logarithm_2(float()) -> {ok, float()} | {error, binary()}. +logarithm_2(X) -> + case X > +0.0 of + true -> + _pipe = math:log2(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x <= 0. Valid input is x > 0."/utf8>>, + {error, _pipe@1} + end. + +-spec logarithm_10(float()) -> {ok, float()} | {error, binary()}. +logarithm_10(X) -> + case X > +0.0 of + true -> + _pipe = math:log10(X), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: x <= 0. Valid input is x > 0."/utf8>>, + {error, _pipe@1} + end. + +-spec logarithm(float(), gleam@option:option(float())) -> {ok, float()} | + {error, binary()}. +logarithm(X, Base) -> + case X > +0.0 of + true -> + case Base of + {some, A} -> + case (A > +0.0) andalso (A /= 1.0) of + true -> + _assert_subject = logarithm_10(X), + {ok, Numerator} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/elementary"/utf8>>, + function => <<"logarithm"/utf8>>, + line => 820}) + end, + _assert_subject@1 = logarithm_10(A), + {ok, Denominator} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/elementary"/utf8>>, + function => <<"logarithm"/utf8>>, + line => 821}) + end, + _pipe = case Denominator of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> Numerator / Gleam@denominator + end, + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invalid input argument: base <= 0 or base == 1. Valid input is base > 0 and base != 1."/utf8>>, + {error, _pipe@1} + end; + + _ -> + _pipe@2 = <<"Invalid input argument: base <= 0 or base == 1. Valid input is base > 0 and base != 1."/utf8>>, + {error, _pipe@2} + end; + + _ -> + _pipe@3 = <<"Invalid input argument: x <= 0. Valid input is x > 0."/utf8>>, + {error, _pipe@3} + end. + +-spec power(float(), float()) -> {ok, float()} | {error, binary()}. +power(X, Y) -> + Fractional = (math:ceil(Y) - Y) > +0.0, + case ((X < +0.0) andalso Fractional) orelse ((X =:= +0.0) andalso (Y < +0.0)) of + true -> + _pipe = <<"Invalid input argument: x < 0 and y is fractional or x = 0 and y < 0."/utf8>>, + {error, _pipe}; + + false -> + _pipe@1 = math:pow(X, Y), + {ok, _pipe@1} + end. + +-spec square_root(float()) -> {ok, float()} | {error, binary()}. +square_root(X) -> + case X < +0.0 of + true -> + _pipe = <<"Invalid input argument: x < 0."/utf8>>, + {error, _pipe}; + + false -> + _assert_subject = power(X, 1.0 / 2.0), + {ok, Result} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/elementary"/utf8>>, + function => <<"square_root"/utf8>>, + line => 1066}) + end, + _pipe@1 = Result, + {ok, _pipe@1} + end. + +-spec cube_root(float()) -> {ok, float()} | {error, binary()}. +cube_root(X) -> + case X < +0.0 of + true -> + _pipe = <<"Invalid input argument: x < 0."/utf8>>, + {error, _pipe}; + + false -> + _assert_subject = power(X, 1.0 / 3.0), + {ok, Result} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/elementary"/utf8>>, + function => <<"cube_root"/utf8>>, + line => 1118}) + end, + _pipe@1 = Result, + {ok, _pipe@1} + end. + +-spec nth_root(float(), integer()) -> {ok, float()} | {error, binary()}. +nth_root(X, N) -> + case X < +0.0 of + true -> + _pipe = <<"Invalid input argument: x < 0. Valid input is x > 0"/utf8>>, + {error, _pipe}; + + false -> + case N >= 1 of + true -> + _assert_subject = power(X, case gleam@int:to_float(N) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> 1.0 / Gleam@denominator + end), + {ok, Result} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/elementary"/utf8>>, + function => <<"nth_root"/utf8>>, + line => 1175}) + end, + _pipe@1 = Result, + {ok, _pipe@1}; + + false -> + _pipe@2 = <<"Invalid input argument: n < 1. Valid input is n >= 2."/utf8>>, + {error, _pipe@2} + end + end. + +-spec pi() -> float(). +pi() -> + math:pi(). + +-spec tau() -> float(). +tau() -> + 2.0 * pi(). + +-spec e() -> float(). +e() -> + exponential(1.0). diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache Binary files differnew file mode 100644 index 0000000..6dc087d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache_meta Binary files differnew file mode 100644 index 0000000..ad6a7f1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.erl new file mode 100644 index 0000000..3483014 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@metrics.erl @@ -0,0 +1,281 @@ +-module(gleam_community@maths@metrics). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([norm/2, minkowski_distance/3, manhatten_distance/2, euclidean_distance/2, mean/1, median/1, variance/2, standard_deviation/2]). + +-spec norm(list(float()), float()) -> float(). +norm(Arr, P) -> + case Arr of + [] -> + +0.0; + + _ -> + Agg = begin + _pipe = Arr, + gleam@list:fold( + _pipe, + +0.0, + fun(Acc, A) -> + _assert_subject = gleam_community@maths@elementary:power( + gleam_community@maths@piecewise:float_absolute_value( + A + ), + P + ), + {ok, Result} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"norm"/utf8>>, + line => 101}) + end, + Result + Acc + end + ) + end, + _assert_subject@1 = gleam_community@maths@elementary:power( + Agg, + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> 1.0 / Gleam@denominator + end + ), + {ok, Result@1} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"norm"/utf8>>, + line => 106}) + end, + Result@1 + end. + +-spec minkowski_distance(list(float()), list(float()), float()) -> {ok, float()} | + {error, binary()}. +minkowski_distance(Xarr, Yarr, P) -> + Xlen = gleam@list:length(Xarr), + Ylen = gleam@list:length(Yarr), + case Xlen =:= Ylen of + false -> + _pipe = <<"Invalid input argument: length(xarr) != length(yarr). Valid input is when length(xarr) == length(yarr)."/utf8>>, + {error, _pipe}; + + true -> + case P < 1.0 of + true -> + _pipe@1 = <<"Invalid input argument: p < 1. Valid input is p >= 1."/utf8>>, + {error, _pipe@1}; + + false -> + _pipe@2 = gleam@list:zip(Xarr, Yarr), + _pipe@3 = gleam@list:map( + _pipe@2, + fun(Tuple) -> + gleam@pair:first(Tuple) - gleam@pair:second(Tuple) + end + ), + _pipe@4 = norm(_pipe@3, P), + {ok, _pipe@4} + end + end. + +-spec manhatten_distance(list(float()), list(float())) -> {ok, float()} | + {error, binary()}. +manhatten_distance(Xarr, Yarr) -> + minkowski_distance(Xarr, Yarr, 1.0). + +-spec euclidean_distance(list(float()), list(float())) -> {ok, float()} | + {error, binary()}. +euclidean_distance(Xarr, Yarr) -> + minkowski_distance(Xarr, Yarr, 2.0). + +-spec mean(list(float())) -> {ok, float()} | {error, binary()}. +mean(Arr) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _pipe@1 = Arr, + _pipe@2 = gleam_community@maths@arithmetics:float_sum(_pipe@1), + _pipe@3 = (fun(A) -> + case gleam_community@maths@conversion:int_to_float( + gleam@list:length(Arr) + ) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> A / Gleam@denominator + end + end)(_pipe@2), + {ok, _pipe@3} + end. + +-spec median(list(float())) -> {ok, float()} | {error, binary()}. +median(Arr) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + Count = gleam@list:length(Arr), + Mid = gleam@list:length(Arr) div 2, + Sorted = gleam@list:sort(Arr, fun gleam@float:compare/2), + case gleam_community@maths@predicates:is_odd(Count) of + true -> + _assert_subject = gleam@list:at(Sorted, Mid), + {ok, Val0} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"median"/utf8>>, + line => 402}) + end, + _pipe@1 = Val0, + {ok, _pipe@1}; + + false -> + _assert_subject@1 = gleam@list:at(Sorted, Mid - 1), + {ok, Val0@1} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"median"/utf8>>, + line => 409}) + end, + _assert_subject@2 = gleam@list:at(Sorted, Mid), + {ok, Val1} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"median"/utf8>>, + line => 410}) + end, + _pipe@2 = [Val0@1, Val1], + mean(_pipe@2) + end + end. + +-spec variance(list(float()), integer()) -> {ok, float()} | {error, binary()}. +variance(Arr, Ddof) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + case Ddof < 0 of + true -> + _pipe@1 = <<"Invalid input argument: ddof < 0. Valid input is ddof >= 0."/utf8>>, + {error, _pipe@1}; + + false -> + _assert_subject = mean(Arr), + {ok, Mean} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"variance"/utf8>>, + line => 475}) + end, + _pipe@2 = Arr, + _pipe@3 = gleam@list:map( + _pipe@2, + fun(A) -> + _assert_subject@1 = gleam_community@maths@elementary:power( + A - Mean, + 2.0 + ), + {ok, Result} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"variance"/utf8>>, + line => 478}) + end, + Result + end + ), + _pipe@4 = gleam_community@maths@arithmetics:float_sum( + _pipe@3 + ), + _pipe@5 = (fun(A@1) -> + case (gleam_community@maths@conversion:int_to_float( + gleam@list:length(Arr) + ) + - gleam_community@maths@conversion:int_to_float(Ddof)) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> A@1 / Gleam@denominator + end + end)(_pipe@4), + {ok, _pipe@5} + end + end. + +-spec standard_deviation(list(float()), integer()) -> {ok, float()} | + {error, binary()}. +standard_deviation(Arr, Ddof) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + case Ddof < 0 of + true -> + _pipe@1 = <<"Invalid input argument: ddof < 0. Valid input is ddof >= 0."/utf8>>, + {error, _pipe@1}; + + false -> + _assert_subject = variance(Arr, Ddof), + {ok, Variance} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"standard_deviation"/utf8>>, + line => 551}) + end, + _assert_subject@1 = gleam_community@maths@elementary:square_root( + Variance + ), + {ok, Stdev} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/metrics"/utf8>>, + function => <<"standard_deviation"/utf8>>, + line => 554}) + end, + _pipe@2 = Stdev, + {ok, _pipe@2} + end + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache Binary files differnew file mode 100644 index 0000000..d65054e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache_meta Binary files differnew file mode 100644 index 0000000..21c97d4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.erl new file mode 100644 index 0000000..c724271 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@piecewise.erl @@ -0,0 +1,563 @@ +-module(gleam_community@maths@piecewise). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([float_absolute_value/1, int_absolute_value/1, float_absolute_difference/2, int_absolute_difference/2, float_sign/1, round/3, ceiling/2, floor/2, truncate/2, int_sign/1, float_flip_sign/1, float_copy_sign/2, int_flip_sign/1, int_copy_sign/2, minimum/3, maximum/3, minmax/3, list_minimum/2, list_maximum/2, arg_minimum/2, arg_maximum/2, extrema/2]). +-export_type([rounding_mode/0]). + +-type rounding_mode() :: round_nearest | + round_ties_away | + round_ties_up | + round_to_zero | + round_down | + round_up. + +-spec truncate_float(float()) -> float(). +truncate_float(X) -> + erlang:trunc(X). + +-spec round_to_zero(float(), float()) -> float(). +round_to_zero(P, X) -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> truncate_float(X * P) / Gleam@denominator + end. + +-spec round_down(float(), float()) -> float(). +round_down(P, X) -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> math:floor(X * P) / Gleam@denominator + end. + +-spec round_up(float(), float()) -> float(). +round_up(P, X) -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> math:ceil(X * P) / Gleam@denominator + end. + +-spec float_absolute_value(float()) -> float(). +float_absolute_value(X) -> + case X > +0.0 of + true -> + X; + + false -> + -1.0 * X + end. + +-spec int_absolute_value(integer()) -> integer(). +int_absolute_value(X) -> + case X > 0 of + true -> + X; + + false -> + -1 * X + end. + +-spec float_absolute_difference(float(), float()) -> float(). +float_absolute_difference(A, B) -> + _pipe = A - B, + float_absolute_value(_pipe). + +-spec int_absolute_difference(integer(), integer()) -> integer(). +int_absolute_difference(A, B) -> + _pipe = A - B, + int_absolute_value(_pipe). + +-spec do_float_sign(float()) -> float(). +do_float_sign(X) -> + case X < +0.0 of + true -> + -1.0; + + false -> + case X =:= +0.0 of + true -> + +0.0; + + false -> + 1.0 + end + end. + +-spec float_sign(float()) -> float(). +float_sign(X) -> + do_float_sign(X). + +-spec round_to_nearest(float(), float()) -> float(). +round_to_nearest(P, X) -> + Xabs = float_absolute_value(X) * P, + Xabs_truncated = truncate_float(Xabs), + Remainder = Xabs - Xabs_truncated, + case Remainder of + _ when Remainder > 0.5 -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> float_sign(X) * truncate_float(Xabs + 1.0) + / Gleam@denominator + end; + + _ when Remainder =:= 0.5 -> + _assert_subject = gleam@int:modulo( + gleam_community@maths@conversion:float_to_int(Xabs), + 2 + ), + {ok, Is_even} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"round_to_nearest"/utf8>>, + line => 423}) + end, + case Is_even =:= 0 of + true -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> float_sign(X) * Xabs_truncated / Gleam@denominator@1 + end; + + false -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@2 -> float_sign(X) * truncate_float( + Xabs + 1.0 + ) + / Gleam@denominator@2 + end + end; + + _ -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@3 -> float_sign(X) * Xabs_truncated / Gleam@denominator@3 + end + end. + +-spec round_ties_away(float(), float()) -> float(). +round_ties_away(P, X) -> + Xabs = float_absolute_value(X) * P, + Remainder = Xabs - truncate_float(Xabs), + case Remainder of + _ when Remainder >= 0.5 -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> float_sign(X) * truncate_float(Xabs + 1.0) + / Gleam@denominator + end; + + _ -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> float_sign(X) * truncate_float(Xabs) / Gleam@denominator@1 + end + end. + +-spec round_ties_up(float(), float()) -> float(). +round_ties_up(P, X) -> + Xabs = float_absolute_value(X) * P, + Xabs_truncated = truncate_float(Xabs), + Remainder = Xabs - Xabs_truncated, + case Remainder of + _ when (Remainder >= 0.5) andalso (X >= +0.0) -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> float_sign(X) * truncate_float(Xabs + 1.0) + / Gleam@denominator + end; + + _ -> + case P of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> float_sign(X) * Xabs_truncated / Gleam@denominator@1 + end + end. + +-spec do_round(float(), float(), gleam@option:option(rounding_mode())) -> {ok, + float()} | + {error, binary()}. +do_round(P, X, Mode) -> + case Mode of + {some, round_nearest} -> + _pipe = round_to_nearest(P, X), + {ok, _pipe}; + + {some, round_ties_away} -> + _pipe@1 = round_ties_away(P, X), + {ok, _pipe@1}; + + {some, round_ties_up} -> + _pipe@2 = round_ties_up(P, X), + {ok, _pipe@2}; + + {some, round_to_zero} -> + _pipe@3 = round_to_zero(P, X), + {ok, _pipe@3}; + + {some, round_down} -> + _pipe@4 = round_down(P, X), + {ok, _pipe@4}; + + {some, round_up} -> + _pipe@5 = round_up(P, X), + {ok, _pipe@5}; + + none -> + _pipe@6 = round_to_nearest(P, X), + {ok, _pipe@6} + end. + +-spec round( + float(), + gleam@option:option(integer()), + gleam@option:option(rounding_mode()) +) -> {ok, float()} | {error, binary()}. +round(X, Digits, Mode) -> + case Digits of + {some, A} -> + _assert_subject = gleam_community@maths@elementary:power( + 10.0, + gleam_community@maths@conversion:int_to_float(A) + ), + {ok, P} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"round"/utf8>>, + line => 366}) + end, + do_round(P, X, Mode); + + none -> + do_round(1.0, X, Mode) + end. + +-spec ceiling(float(), gleam@option:option(integer())) -> {ok, float()} | + {error, binary()}. +ceiling(X, Digits) -> + round(X, Digits, {some, round_up}). + +-spec floor(float(), gleam@option:option(integer())) -> {ok, float()} | + {error, binary()}. +floor(X, Digits) -> + round(X, Digits, {some, round_down}). + +-spec truncate(float(), gleam@option:option(integer())) -> {ok, float()} | + {error, binary()}. +truncate(X, Digits) -> + round(X, Digits, {some, round_to_zero}). + +-spec do_int_sign(integer()) -> integer(). +do_int_sign(X) -> + case X < 0 of + true -> + -1; + + false -> + case X =:= 0 of + true -> + 0; + + false -> + 1 + end + end. + +-spec int_sign(integer()) -> integer(). +int_sign(X) -> + do_int_sign(X). + +-spec float_flip_sign(float()) -> float(). +float_flip_sign(X) -> + -1.0 * X. + +-spec float_copy_sign(float(), float()) -> float(). +float_copy_sign(X, Y) -> + case float_sign(X) =:= float_sign(Y) of + true -> + X; + + false -> + float_flip_sign(X) + end. + +-spec int_flip_sign(integer()) -> integer(). +int_flip_sign(X) -> + -1 * X. + +-spec int_copy_sign(integer(), integer()) -> integer(). +int_copy_sign(X, Y) -> + case int_sign(X) =:= int_sign(Y) of + true -> + X; + + false -> + int_flip_sign(X) + end. + +-spec minimum(IUU, IUU, fun((IUU, IUU) -> gleam@order:order())) -> IUU. +minimum(X, Y, Compare) -> + case Compare(X, Y) of + lt -> + X; + + eq -> + X; + + gt -> + Y + end. + +-spec maximum(IUV, IUV, fun((IUV, IUV) -> gleam@order:order())) -> IUV. +maximum(X, Y, Compare) -> + case Compare(X, Y) of + lt -> + Y; + + eq -> + Y; + + gt -> + X + end. + +-spec minmax(IUW, IUW, fun((IUW, IUW) -> gleam@order:order())) -> {IUW, IUW}. +minmax(X, Y, Compare) -> + {minimum(X, Y, Compare), maximum(X, Y, Compare)}. + +-spec list_minimum(list(IUX), fun((IUX, IUX) -> gleam@order:order())) -> {ok, + IUX} | + {error, binary()}. +list_minimum(Arr, Compare) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _assert_subject = gleam@list:at(Arr, 0), + {ok, Val0} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"list_minimum"/utf8>>, + line => 945}) + end, + _pipe@1 = Arr, + _pipe@2 = gleam@list:fold( + _pipe@1, + Val0, + fun(Acc, Element) -> case Compare(Element, Acc) of + lt -> + Element; + + _ -> + Acc + end end + ), + {ok, _pipe@2} + end. + +-spec list_maximum(list(IVB), fun((IVB, IVB) -> gleam@order:order())) -> {ok, + IVB} | + {error, binary()}. +list_maximum(Arr, Compare) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _assert_subject = gleam@list:at(Arr, 0), + {ok, Val0} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"list_maximum"/utf8>>, + line => 1004}) + end, + _pipe@1 = Arr, + _pipe@2 = gleam@list:fold( + _pipe@1, + Val0, + fun(Acc, Element) -> case Compare(Acc, Element) of + lt -> + Element; + + _ -> + Acc + end end + ), + {ok, _pipe@2} + end. + +-spec arg_minimum(list(IVF), fun((IVF, IVF) -> gleam@order:order())) -> {ok, + list(integer())} | + {error, binary()}. +arg_minimum(Arr, Compare) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _assert_subject = begin + _pipe@1 = Arr, + list_minimum(_pipe@1, Compare) + end, + {ok, Min} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"arg_minimum"/utf8>>, + line => 1069}) + end, + _pipe@2 = Arr, + _pipe@3 = gleam@list:index_map( + _pipe@2, + fun(Index, Element) -> case Compare(Element, Min) of + eq -> + Index; + + _ -> + -1 + end end + ), + _pipe@4 = gleam@list:filter(_pipe@3, fun(Index@1) -> case Index@1 of + -1 -> + false; + + _ -> + true + end end), + {ok, _pipe@4} + end. + +-spec arg_maximum(list(IVK), fun((IVK, IVK) -> gleam@order:order())) -> {ok, + list(integer())} | + {error, binary()}. +arg_maximum(Arr, Compare) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _assert_subject = begin + _pipe@1 = Arr, + list_maximum(_pipe@1, Compare) + end, + {ok, Max} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"arg_maximum"/utf8>>, + line => 1139}) + end, + _pipe@2 = Arr, + _pipe@3 = gleam@list:index_map( + _pipe@2, + fun(Index, Element) -> case Compare(Element, Max) of + eq -> + Index; + + _ -> + -1 + end end + ), + _pipe@4 = gleam@list:filter(_pipe@3, fun(Index@1) -> case Index@1 of + -1 -> + false; + + _ -> + true + end end), + {ok, _pipe@4} + end. + +-spec extrema(list(IVP), fun((IVP, IVP) -> gleam@order:order())) -> {ok, + {IVP, IVP}} | + {error, binary()}. +extrema(Arr, Compare) -> + case Arr of + [] -> + _pipe = <<"Invalid input argument: The list is empty."/utf8>>, + {error, _pipe}; + + _ -> + _assert_subject = gleam@list:at(Arr, 0), + {ok, Val_max} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"extrema"/utf8>>, + line => 1209}) + end, + _assert_subject@1 = gleam@list:at(Arr, 0), + {ok, Val_min} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/piecewise"/utf8>>, + function => <<"extrema"/utf8>>, + line => 1210}) + end, + _pipe@1 = Arr, + _pipe@2 = gleam@list:fold( + _pipe@1, + {Val_min, Val_max}, + fun(Acc, Element) -> + First = gleam@pair:first(Acc), + Second = gleam@pair:second(Acc), + case {Compare(Element, First), Compare(Second, Element)} of + {lt, lt} -> + {Element, Element}; + + {lt, _} -> + {Element, Second}; + + {_, lt} -> + {First, Element}; + + {_, _} -> + {First, Second} + end + end + ), + {ok, _pipe@2} + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache Binary files differnew file mode 100644 index 0000000..0ef2e9b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache_meta Binary files differnew file mode 100644 index 0000000..549041c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.erl new file mode 100644 index 0000000..42484d5 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@predicates.erl @@ -0,0 +1,118 @@ +-module(gleam_community@maths@predicates). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([is_close/4, all_close/4, is_fractional/1, is_power/2, is_perfect/1, is_even/1, is_odd/1]). + +-spec float_absolute_value(float()) -> float(). +float_absolute_value(X) -> + case X > +0.0 of + true -> + X; + + false -> + -1.0 * X + end. + +-spec float_absolute_difference(float(), float()) -> float(). +float_absolute_difference(A, B) -> + _pipe = A - B, + float_absolute_value(_pipe). + +-spec is_close(float(), float(), float(), float()) -> boolean(). +is_close(A, B, Rtol, Atol) -> + X = float_absolute_difference(A, B), + Y = Atol + (Rtol * float_absolute_value(B)), + case X =< Y of + true -> + true; + + false -> + false + end. + +-spec all_close(list(float()), list(float()), float(), float()) -> {ok, + list(boolean())} | + {error, binary()}. +all_close(Xarr, Yarr, Rtol, Atol) -> + Xlen = gleam@list:length(Xarr), + Ylen = gleam@list:length(Yarr), + case Xlen =:= Ylen of + false -> + _pipe = <<"Invalid input argument: length(xarr) != length(yarr). Valid input is when length(xarr) == length(yarr)."/utf8>>, + {error, _pipe}; + + true -> + _pipe@1 = gleam@list:zip(Xarr, Yarr), + _pipe@2 = gleam@list:map( + _pipe@1, + fun(Z) -> + is_close( + gleam@pair:first(Z), + gleam@pair:second(Z), + Rtol, + Atol + ) + end + ), + {ok, _pipe@2} + end. + +-spec is_fractional(float()) -> boolean(). +is_fractional(X) -> + (math:ceil(X) - X) > +0.0. + +-spec is_power(integer(), integer()) -> boolean(). +is_power(X, Y) -> + _assert_subject = gleam_community@maths@elementary:logarithm( + gleam@int:to_float(X), + {some, gleam@int:to_float(Y)} + ), + {ok, Value} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/predicates"/utf8>>, + function => <<"is_power"/utf8>>, + line => 241}) + end, + _assert_subject@1 = gleam_community@maths@piecewise:truncate( + Value, + {some, 0} + ), + {ok, Truncated} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/predicates"/utf8>>, + function => <<"is_power"/utf8>>, + line => 243}) + end, + Rem = Value - Truncated, + Rem =:= +0.0. + +-spec do_sum(list(integer())) -> integer(). +do_sum(Arr) -> + case Arr of + [] -> + 0; + + _ -> + _pipe = Arr, + gleam@list:fold(_pipe, 0, fun(Acc, A) -> A + Acc end) + end. + +-spec is_perfect(integer()) -> boolean(). +is_perfect(N) -> + do_sum(gleam_community@maths@arithmetics:proper_divisors(N)) =:= N. + +-spec is_even(integer()) -> boolean(). +is_even(X) -> + (X rem 2) =:= 0. + +-spec is_odd(integer()) -> boolean(). +is_odd(X) -> + (X rem 2) /= 0. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache Binary files differnew file mode 100644 index 0000000..e06c185 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache_meta Binary files differnew file mode 100644 index 0000000..3a025a2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.erl new file mode 100644 index 0000000..72de13c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@sequences.erl @@ -0,0 +1,202 @@ +-module(gleam_community@maths@sequences). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([arange/3, linear_space/4, logarithmic_space/5, geometric_space/4]). + +-spec arange(float(), float(), float()) -> list(float()). +arange(Start, Stop, Step) -> + case ((Start >= Stop) andalso (Step > +0.0)) orelse ((Start =< Stop) andalso (Step + < +0.0)) of + true -> + []; + + false -> + Direction = case Start =< Stop of + true -> + 1.0; + + false -> + -1.0 + end, + Step_abs = gleam_community@maths@piecewise:float_absolute_value( + Step + ), + Num = case Step_abs of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> gleam_community@maths@piecewise:float_absolute_value( + Start - Stop + ) + / Gleam@denominator + end, + _pipe = gleam@list:range( + 0, + gleam_community@maths@conversion:float_to_int(Num) - 1 + ), + gleam@list:map( + _pipe, + fun(I) -> + Start + ((gleam_community@maths@conversion:int_to_float(I) * Step_abs) + * Direction) + end + ) + end. + +-spec linear_space(float(), float(), integer(), boolean()) -> {ok, + list(float())} | + {error, binary()}. +linear_space(Start, Stop, Num, Endpoint) -> + Direction = case Start =< Stop of + true -> + 1.0; + + false -> + -1.0 + end, + case Num > 0 of + true -> + case Endpoint of + true -> + Increment = case gleam_community@maths@conversion:int_to_float( + Num - 1 + ) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> gleam_community@maths@piecewise:float_absolute_value( + Start - Stop + ) + / Gleam@denominator + end, + _pipe = gleam@list:range(0, Num - 1), + _pipe@1 = gleam@list:map( + _pipe, + fun(I) -> + Start + ((gleam_community@maths@conversion:int_to_float( + I + ) + * Increment) + * Direction) + end + ), + {ok, _pipe@1}; + + false -> + Increment@1 = case gleam_community@maths@conversion:int_to_float( + Num + ) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> gleam_community@maths@piecewise:float_absolute_value( + Start - Stop + ) + / Gleam@denominator@1 + end, + _pipe@2 = gleam@list:range(0, Num - 1), + _pipe@3 = gleam@list:map( + _pipe@2, + fun(I@1) -> + Start + ((gleam_community@maths@conversion:int_to_float( + I@1 + ) + * Increment@1) + * Direction) + end + ), + {ok, _pipe@3} + end; + + false -> + _pipe@4 = <<"Invalid input: num < 0. Valid input is num > 0."/utf8>>, + {error, _pipe@4} + end. + +-spec logarithmic_space(float(), float(), integer(), boolean(), float()) -> {ok, + list(float())} | + {error, binary()}. +logarithmic_space(Start, Stop, Num, Endpoint, Base) -> + case Num > 0 of + true -> + _assert_subject = linear_space(Start, Stop, Num, Endpoint), + {ok, Linspace} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/sequences"/utf8>>, + function => <<"logarithmic_space"/utf8>>, + line => 221}) + end, + _pipe = Linspace, + _pipe@1 = gleam@list:map( + _pipe, + fun(I) -> + _assert_subject@1 = gleam_community@maths@elementary:power( + Base, + I + ), + {ok, Result} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/sequences"/utf8>>, + function => <<"logarithmic_space"/utf8>>, + line => 224}) + end, + Result + end + ), + {ok, _pipe@1}; + + false -> + _pipe@2 = <<"Invalid input: num < 0. Valid input is num > 0."/utf8>>, + {error, _pipe@2} + end. + +-spec geometric_space(float(), float(), integer(), boolean()) -> {ok, + list(float())} | + {error, binary()}. +geometric_space(Start, Stop, Num, Endpoint) -> + case (Start =:= +0.0) orelse (Stop =:= +0.0) of + true -> + _pipe = <<""/utf8>>, + {error, _pipe}; + + false -> + case Num > 0 of + true -> + _assert_subject = gleam_community@maths@elementary:logarithm_10( + Start + ), + {ok, Log_start} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/sequences"/utf8>>, + function => <<"geometric_space"/utf8>>, + line => 293}) + end, + _assert_subject@1 = gleam_community@maths@elementary:logarithm_10( + Stop + ), + {ok, Log_stop} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/sequences"/utf8>>, + function => <<"geometric_space"/utf8>>, + line => 294}) + end, + logarithmic_space(Log_start, Log_stop, Num, Endpoint, 10.0); + + false -> + _pipe@1 = <<"Invalid input: num < 0. Valid input is num > 0."/utf8>>, + {error, _pipe@1} + end + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache Binary files differnew file mode 100644 index 0000000..0fdbab2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache_meta b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache_meta Binary files differnew file mode 100644 index 0000000..3c21994 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.erl b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.erl new file mode 100644 index 0000000..b1e9214 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/gleam_community@maths@special.erl @@ -0,0 +1,163 @@ +-module(gleam_community@maths@special). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([erf/1, incomplete_gamma/2, gamma/1, beta/2]). + +-spec erf(float()) -> float(). +erf(X) -> + _assert_subject = [0.254829592, + -0.284496736, + 1.421413741, + -1.453152027, + 1.061405429], + [A1, A2, A3, A4, A5] = case _assert_subject of + [_, _, _, _, _] -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/special"/utf8>>, + function => <<"erf"/utf8>>, + line => 79}) + end, + P = 0.3275911, + Sign = gleam_community@maths@piecewise:float_sign(X), + X@1 = gleam_community@maths@piecewise:float_absolute_value(X), + T = case (1.0 + (P * X@1)) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> 1.0 / Gleam@denominator + end, + Y = 1.0 - ((((((((((A5 * T) + A4) * T) + A3) * T) + A2) * T) + A1) * T) * gleam_community@maths@elementary:exponential( + (-1.0 * X@1) * X@1 + )), + Sign * Y. + +-spec incomplete_gamma_sum(float(), float(), float(), float(), float()) -> float(). +incomplete_gamma_sum(A, X, T, S, N) -> + case T of + +0.0 -> + S; + + _ -> + Ns = S + T, + Nt = T * (case (A + N) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> X / Gleam@denominator + end), + incomplete_gamma_sum(A, X, Nt, Ns, N + 1.0) + end. + +-spec incomplete_gamma(float(), float()) -> {ok, float()} | {error, binary()}. +incomplete_gamma(A, X) -> + case (A > +0.0) andalso (X >= +0.0) of + true -> + _assert_subject = gleam_community@maths@elementary:power(X, A), + {ok, V} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/special"/utf8>>, + function => <<"incomplete_gamma"/utf8>>, + line => 173}) + end, + _pipe = (V * gleam_community@maths@elementary:exponential(-1.0 * X)) + * incomplete_gamma_sum(A, X, case A of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> 1.0 / Gleam@denominator + end, +0.0, 1.0), + {ok, _pipe}; + + false -> + _pipe@1 = <<"Invlaid input argument: a <= 0 or x < 0. Valid input is a > 0 and x >= 0."/utf8>>, + {error, _pipe@1} + end. + +-spec gamma_lanczos(float()) -> float(). +gamma_lanczos(X) -> + case X < 0.5 of + true -> + case (gleam_community@maths@elementary:sin( + gleam_community@maths@elementary:pi() * X + ) + * gamma_lanczos(1.0 - X)) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> gleam_community@maths@elementary:pi() / Gleam@denominator + end; + + false -> + Z = X - 1.0, + X@1 = gleam@list:index_fold( + [0.99999999999980993, + 676.5203681218851, + -1259.1392167224028, + 771.32342877765313, + -176.61502916214059, + 12.507343278686905, + -0.13857109526572012, + 0.0000099843695780195716, + 0.00000015056327351493116], + +0.0, + fun(Acc, V, Index) -> case Index > 0 of + true -> + Acc + (case (Z + gleam_community@maths@conversion:int_to_float( + Index + )) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator@1 -> V / Gleam@denominator@1 + end); + + false -> + V + end end + ), + T = (Z + 7.0) + 0.5, + _assert_subject = gleam_community@maths@elementary:power( + 2.0 * gleam_community@maths@elementary:pi(), + 0.5 + ), + {ok, V1} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam_community/maths/special"/utf8>>, + function => <<"gamma_lanczos"/utf8>>, + line => 146}) + end, + _assert_subject@1 = gleam_community@maths@elementary:power( + T, + Z + 0.5 + ), + {ok, V2} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"gleam_community/maths/special"/utf8>>, + function => <<"gamma_lanczos"/utf8>>, + line => 147}) + end, + ((V1 * V2) * gleam_community@maths@elementary:exponential(-1.0 * T)) + * X@1 + end. + +-spec gamma(float()) -> float(). +gamma(X) -> + gamma_lanczos(X). + +-spec beta(float(), float()) -> float(). +beta(X, Y) -> + case gamma(X + Y) of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> gamma(X) * gamma(Y) / Gleam@denominator + end. diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/maths.mjs b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/maths.mjs new file mode 100644 index 0000000..5c5ab31 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/_gleam_artefacts/maths.mjs @@ -0,0 +1,95 @@ +export function sin(float) { + return Math.sin(float) +} + +export function pi() { + return Math.PI +} + +export function acos(float) { + return Math.acos(float) +} + +export function acosh(float) { + return Math.acosh(float) +} + +export function asin(float) { + return Math.asin(float) +} + +export function asinh(float) { + return Math.asinh(float) +} + +export function atan(float) { + return Math.atan(float) +} + +export function tan(float) { + return Math.tan(float) +} + +export function atan2(floaty, floatx) { + return Math.atan2(floaty, floatx) +} + +export function atanh(float) { + return Math.atanh(float) +} + +export function cos(float) { + return Math.cos(float) +} + +export function cosh(float) { + return Math.cosh(float) +} + +export function exponential(float) { + return Math.exp(float) +} + +export function ceiling(float) { + return Math.ceil(float) +} + +export function floor(float) { + return Math.floor(float) +} + +export function power(base, exponent) { + return Math.pow(base, exponent) +} + +export function logarithm(float) { + return Math.log(float) +} + +export function logarithm_10(float) { + return Math.log10(float) +} + +export function logarithm_2(float) { + return Math.log2(float) +} + +export function sinh(float) { + return Math.sinh(float) +} + +export function tanh(float) { + return Math.tanh(float) +} + +export function sign(float) { + return Math.sign(float) +} + +export function truncate(float) { + return Math.trunc(float) +} + +export function to_int(float) { + return Math.trunc(float) +} diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@arithmetics.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@arithmetics.beam Binary files differnew file mode 100644 index 0000000..7bdc600 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@arithmetics.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@combinatorics.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@combinatorics.beam Binary files differnew file mode 100644 index 0000000..f9cdc85 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@combinatorics.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@conversion.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@conversion.beam Binary files differnew file mode 100644 index 0000000..bc6d41e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@conversion.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@elementary.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@elementary.beam Binary files differnew file mode 100644 index 0000000..9850c86 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@elementary.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@metrics.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@metrics.beam Binary files differnew file mode 100644 index 0000000..513efde --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@metrics.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@piecewise.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@piecewise.beam Binary files differnew file mode 100644 index 0000000..652b871 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@piecewise.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@predicates.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@predicates.beam Binary files differnew file mode 100644 index 0000000..c6fa350 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@predicates.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@sequences.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@sequences.beam Binary files differnew file mode 100644 index 0000000..1039c56 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@sequences.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@special.beam b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@special.beam Binary files differnew file mode 100644 index 0000000..21b9149 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community@maths@special.beam diff --git a/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community_maths.app b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community_maths.app new file mode 100644 index 0000000..b24eaf7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_community_maths/ebin/gleam_community_maths.app @@ -0,0 +1,7 @@ +{application, gleam_community_maths, [ + {vsn, "1.0.1"}, + {applications, [gleam_stdlib]}, + {description, "A basic maths library"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache Binary files differnew file mode 100644 index 0000000..a136f2b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache_meta Binary files differnew file mode 100644 index 0000000..12933b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.erl new file mode 100644 index 0000000..c689364 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang.erl @@ -0,0 +1,90 @@ +-module(gleam@erlang). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([format/1, term_to_binary/1, get_line/1, system_time/1, erlang_timestamp/0, rescue/1, binary_to_term/1, unsafe_binary_to_term/1, start_arguments/0, ensure_all_started/1, make_reference/0, priv_directory/1]). +-export_type([safe/0, get_line_error/0, time_unit/0, crash/0, ensure_all_started_error/0, reference_/0]). + +-type safe() :: safe. + +-type get_line_error() :: eof | no_data. + +-type time_unit() :: second | millisecond | microsecond | nanosecond. + +-type crash() :: {exited, gleam@dynamic:dynamic_()} | + {thrown, gleam@dynamic:dynamic_()} | + {errored, gleam@dynamic:dynamic_()}. + +-type ensure_all_started_error() :: {unknown_application, + gleam@erlang@atom:atom_()} | + {application_failed_to_start, + gleam@erlang@atom:atom_(), + gleam@dynamic:dynamic_()}. + +-type reference_() :: any(). + +-spec format(any()) -> binary(). +format(Term) -> + unicode:characters_to_binary(io_lib:format(<<"~p"/utf8>>, [Term])). + +-spec term_to_binary(any()) -> bitstring(). +term_to_binary(A) -> + erlang:term_to_binary(A). + +-spec get_line(binary()) -> {ok, binary()} | {error, get_line_error()}. +get_line(Prompt) -> + gleam_erlang_ffi:get_line(Prompt). + +-spec system_time(time_unit()) -> integer(). +system_time(A) -> + os:system_time(A). + +-spec erlang_timestamp() -> {integer(), integer(), integer()}. +erlang_timestamp() -> + os:timestamp(). + +-spec rescue(fun(() -> GWM)) -> {ok, GWM} | {error, crash()}. +rescue(A) -> + gleam_erlang_ffi:rescue(A). + +-spec binary_to_term(bitstring()) -> {ok, gleam@dynamic:dynamic_()} | + {error, nil}. +binary_to_term(Binary) -> + case gleam_erlang_ffi:rescue( + fun() -> erlang:binary_to_term(Binary, [safe]) end + ) of + {ok, Term} -> + {ok, Term}; + + {error, _} -> + {error, nil} + end. + +-spec unsafe_binary_to_term(bitstring()) -> {ok, gleam@dynamic:dynamic_()} | + {error, nil}. +unsafe_binary_to_term(Binary) -> + case gleam_erlang_ffi:rescue(fun() -> erlang:binary_to_term(Binary, []) end) of + {ok, Term} -> + {ok, Term}; + + {error, _} -> + {error, nil} + end. + +-spec start_arguments() -> list(binary()). +start_arguments() -> + _pipe = init:get_plain_arguments(), + gleam@list:map(_pipe, fun unicode:characters_to_binary/1). + +-spec ensure_all_started(gleam@erlang@atom:atom_()) -> {ok, + list(gleam@erlang@atom:atom_())} | + {error, ensure_all_started_error()}. +ensure_all_started(Application) -> + gleam_erlang_ffi:ensure_all_started(Application). + +-spec make_reference() -> reference_(). +make_reference() -> + erlang:make_ref(). + +-spec priv_directory(binary()) -> {ok, binary()} | {error, nil}. +priv_directory(Name) -> + gleam_erlang_ffi:priv_directory(Name). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache Binary files differnew file mode 100644 index 0000000..83a03cd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_meta Binary files differnew file mode 100644 index 0000000..be33011 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.erl new file mode 100644 index 0000000..f35c631 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@atom.erl @@ -0,0 +1,26 @@ +-module(gleam@erlang@atom). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from_string/1, create_from_string/1, to_string/1, from_dynamic/1]). +-export_type([atom_/0, from_string_error/0]). + +-type atom_() :: any(). + +-type from_string_error() :: atom_not_loaded. + +-spec from_string(binary()) -> {ok, atom_()} | {error, from_string_error()}. +from_string(A) -> + gleam_erlang_ffi:atom_from_string(A). + +-spec create_from_string(binary()) -> atom_(). +create_from_string(A) -> + erlang:binary_to_atom(A). + +-spec to_string(atom_()) -> binary(). +to_string(A) -> + erlang:atom_to_binary(A). + +-spec from_dynamic(gleam@dynamic:dynamic_()) -> {ok, atom_()} | + {error, list(gleam@dynamic:decode_error())}. +from_dynamic(From) -> + gleam_erlang_ffi:atom_from_dynamic(From). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache Binary files differnew file mode 100644 index 0000000..b4053cc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_meta Binary files differnew file mode 100644 index 0000000..82cfdb5 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.erl new file mode 100644 index 0000000..dc1670d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@charlist.erl @@ -0,0 +1,15 @@ +-module(gleam@erlang@charlist). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([to_string/1, from_string/1]). +-export_type([charlist/0]). + +-type charlist() :: any(). + +-spec to_string(charlist()) -> binary(). +to_string(A) -> + unicode:characters_to_binary(A). + +-spec from_string(binary()) -> charlist(). +from_string(A) -> + unicode:characters_to_list(A). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache Binary files differnew file mode 100644 index 0000000..b447be6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache_meta Binary files differnew file mode 100644 index 0000000..1cb342b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.erl new file mode 100644 index 0000000..396b31a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@file.erl @@ -0,0 +1,190 @@ +-module(gleam@erlang@file). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([file_info/1, link_info/1, is_directory/1, is_regular/1, file_exists/1, link_exists/1, make_directory/1, list_directory/1, delete_directory/1, recursive_delete/1, read/1, read_bits/1, write/2, write_bits/2, append/2, append_bits/2, delete/1]). +-export_type([reason/0, file_type/0, access/0, file_info/0]). + +-type reason() :: eacces | + eagain | + ebadf | + ebadmsg | + ebusy | + edeadlk | + edeadlock | + edquot | + eexist | + efault | + efbig | + eftype | + eintr | + einval | + eio | + eisdir | + eloop | + emfile | + emlink | + emultihop | + enametoolong | + enfile | + enobufs | + enodev | + enolck | + enolink | + enoent | + enomem | + enospc | + enosr | + enostr | + enosys | + enotblk | + enotdir | + enotsup | + enxio | + eopnotsupp | + eoverflow | + eperm | + epipe | + erange | + erofs | + espipe | + esrch | + estale | + etxtbsy | + exdev | + not_utf8. + +-type file_type() :: device | directory | other | regular | symlink. + +-type access() :: no_access | read | read_write | write. + +-type file_info() :: {file_info, + integer(), + file_type(), + access(), + integer(), + integer(), + integer(), + integer(), + integer(), + integer(), + integer(), + integer(), + integer(), + integer()}. + +-spec file_info(binary()) -> {ok, file_info()} | {error, reason()}. +file_info(A) -> + gleam_erlang_ffi:file_info(A). + +-spec link_info(binary()) -> {ok, file_info()} | {error, reason()}. +link_info(A) -> + gleam_erlang_ffi:link_info(A). + +-spec is_directory(binary()) -> {ok, boolean()} | {error, reason()}. +is_directory(Path) -> + gleam@result:map( + gleam_erlang_ffi:file_info(Path), + fun(_use0) -> + {file_info, _, File_type, _, _, _, _, _, _, _, _, _, _, _} = _use0, + File_type =:= directory + end + ). + +-spec is_regular(binary()) -> {ok, boolean()} | {error, reason()}. +is_regular(Path) -> + gleam@result:map( + gleam_erlang_ffi:file_info(Path), + fun(_use0) -> + {file_info, _, File_type, _, _, _, _, _, _, _, _, _, _, _} = _use0, + File_type =:= regular + end + ). + +-spec file_exists(binary()) -> {ok, boolean()} | {error, reason()}. +file_exists(Path) -> + Result = begin + _pipe = Path, + _pipe@1 = gleam_erlang_ffi:file_info(_pipe), + gleam@result:replace(_pipe@1, true) + end, + case Result of + {error, enoent} -> + {ok, false}; + + _ -> + Result + end. + +-spec link_exists(binary()) -> {ok, boolean()} | {error, reason()}. +link_exists(Path) -> + Result = begin + _pipe = Path, + _pipe@1 = gleam_erlang_ffi:link_info(_pipe), + gleam@result:replace(_pipe@1, true) + end, + case Result of + {error, enoent} -> + {ok, false}; + + _ -> + Result + end. + +-spec make_directory(binary()) -> {ok, nil} | {error, reason()}. +make_directory(A) -> + gleam_erlang_ffi:make_directory(A). + +-spec list_directory(binary()) -> {ok, list(binary())} | {error, reason()}. +list_directory(A) -> + gleam_erlang_ffi:list_directory(A). + +-spec delete_directory(binary()) -> {ok, nil} | {error, reason()}. +delete_directory(A) -> + gleam_erlang_ffi:delete_directory(A). + +-spec recursive_delete(binary()) -> {ok, nil} | {error, reason()}. +recursive_delete(A) -> + gleam_erlang_ffi:recursive_delete(A). + +-spec read(binary()) -> {ok, binary()} | {error, reason()}. +read(Path) -> + _pipe = Path, + _pipe@1 = gleam_erlang_ffi:read_file(_pipe), + gleam@result:then( + _pipe@1, + fun(Content) -> case gleam@bit_array:to_string(Content) of + {ok, String} -> + {ok, String}; + + {error, nil} -> + {error, not_utf8} + end end + ). + +-spec read_bits(binary()) -> {ok, bitstring()} | {error, reason()}. +read_bits(Path) -> + gleam_erlang_ffi:read_file(Path). + +-spec write(binary(), binary()) -> {ok, nil} | {error, reason()}. +write(Contents, Path) -> + _pipe = Contents, + _pipe@1 = gleam_stdlib:identity(_pipe), + gleam_erlang_ffi:write_file(_pipe@1, Path). + +-spec write_bits(bitstring(), binary()) -> {ok, nil} | {error, reason()}. +write_bits(Contents, Path) -> + gleam_erlang_ffi:write_file(Contents, Path). + +-spec append(binary(), binary()) -> {ok, nil} | {error, reason()}. +append(Contents, Path) -> + _pipe = Contents, + _pipe@1 = gleam_stdlib:identity(_pipe), + gleam_erlang_ffi:append_file(_pipe@1, Path). + +-spec append_bits(bitstring(), binary()) -> {ok, nil} | {error, reason()}. +append_bits(Contents, Path) -> + gleam_erlang_ffi:append_file(Contents, Path). + +-spec delete(binary()) -> {ok, nil} | {error, reason()}. +delete(A) -> + gleam_erlang_ffi:delete_file(A). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache Binary files differnew file mode 100644 index 0000000..acd84e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_meta Binary files differnew file mode 100644 index 0000000..085886a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.erl new file mode 100644 index 0000000..e421e84 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@node.erl @@ -0,0 +1,33 @@ +-module(gleam@erlang@node). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([self/0, visible/0, connect/1, send/3, to_atom/1]). +-export_type([node_/0, do_not_leak/0, connect_error/0]). + +-type node_() :: any(). + +-type do_not_leak() :: any(). + +-type connect_error() :: failed_to_connect | local_node_is_not_alive. + +-spec self() -> node_(). +self() -> + erlang:node(). + +-spec visible() -> list(node_()). +visible() -> + erlang:nodes(). + +-spec connect(gleam@erlang@atom:atom_()) -> {ok, node_()} | + {error, connect_error()}. +connect(Node) -> + gleam_erlang_ffi:connect_node(Node). + +-spec send(node_(), gleam@erlang@atom:atom_(), any()) -> nil. +send(Node, Name, Message) -> + erlang:send({Name, Node}, Message), + nil. + +-spec to_atom(node_()) -> gleam@erlang@atom:atom_(). +to_atom(Node) -> + gleam_erlang_ffi:identity(Node). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache Binary files differnew file mode 100644 index 0000000..c7698fa --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache_meta Binary files differnew file mode 100644 index 0000000..1d5fa83 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.erl new file mode 100644 index 0000000..27bc111 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@os.erl @@ -0,0 +1,27 @@ +-module(gleam@erlang@os). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([get_all_env/0, get_env/1, set_env/2, unset_env/1, family/0]). +-export_type([os_family/0]). + +-type os_family() :: windows_nt | linux | darwin | free_bsd | {other, binary()}. + +-spec get_all_env() -> gleam@dict:dict(binary(), binary()). +get_all_env() -> + gleam_erlang_ffi:get_all_env(). + +-spec get_env(binary()) -> {ok, binary()} | {error, nil}. +get_env(Name) -> + gleam_erlang_ffi:get_env(Name). + +-spec set_env(binary(), binary()) -> nil. +set_env(Name, Value) -> + gleam_erlang_ffi:set_env(Name, Value). + +-spec unset_env(binary()) -> nil. +unset_env(Name) -> + gleam_erlang_ffi:unset_env(Name). + +-spec family() -> os_family(). +family() -> + gleam_erlang_ffi:os_family(). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache Binary files differnew file mode 100644 index 0000000..bb95436 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_meta b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_meta Binary files differnew file mode 100644 index 0000000..ad9209c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.erl new file mode 100644 index 0000000..f8562ef --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam@erlang@process.erl @@ -0,0 +1,374 @@ +-module(gleam@erlang@process). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([self/0, start/2, new_subject/0, subject_owner/1, send/2, new_selector/0, select/2, select_forever/1, map_selector/2, merge_selector/2, flush_messages/0, selecting_trapped_exits/2, selecting/3, 'receive'/2, selecting_record2/3, selecting_record3/3, selecting_record4/3, selecting_record5/3, selecting_record6/3, selecting_record7/3, selecting_record8/3, selecting_anything/2, sleep/1, sleep_forever/0, is_alive/1, monitor_process/1, selecting_process_down/3, demonitor_process/1, try_call/3, call/3, link/1, unlink/1, send_after/3, cancel_timer/1, kill/1, send_exit/1, send_abnormal_exit/2, trap_exits/1, register/2, unregister/1, named/1]). +-export_type([pid_/0, subject/1, do_not_leak/0, selector/1, exit_message/0, exit_reason/0, anything_selector_tag/0, process_monitor_flag/0, process_monitor/0, process_down/0, call_error/1, timer/0, cancelled/0, kill_flag/0]). + +-type pid_() :: any(). + +-opaque subject(GYI) :: {subject, pid_(), gleam@erlang:reference_()} | + {gleam_phantom, GYI}. + +-type do_not_leak() :: any(). + +-type selector(GYJ) :: any() | {gleam_phantom, GYJ}. + +-type exit_message() :: {exit_message, pid_(), exit_reason()}. + +-type exit_reason() :: normal | killed | {abnormal, binary()}. + +-type anything_selector_tag() :: anything. + +-type process_monitor_flag() :: process. + +-opaque process_monitor() :: {process_monitor, gleam@erlang:reference_()}. + +-type process_down() :: {process_down, pid_(), gleam@dynamic:dynamic_()}. + +-type call_error(GYK) :: {callee_down, gleam@dynamic:dynamic_()} | + call_timeout | + {gleam_phantom, GYK}. + +-type timer() :: any(). + +-type cancelled() :: timer_not_found | {cancelled, integer()}. + +-type kill_flag() :: kill. + +-spec self() -> pid_(). +self() -> + erlang:self(). + +-spec start(fun(() -> any()), boolean()) -> pid_(). +start(Implementation, Link) -> + case Link of + true -> + erlang:spawn_link(Implementation); + + false -> + erlang:spawn(Implementation) + end. + +-spec new_subject() -> subject(any()). +new_subject() -> + {subject, erlang:self(), erlang:make_ref()}. + +-spec subject_owner(subject(any())) -> pid_(). +subject_owner(Subject) -> + erlang:element(2, Subject). + +-spec send(subject(GYT), GYT) -> nil. +send(Subject, Message) -> + erlang:send( + erlang:element(2, Subject), + {erlang:element(3, Subject), Message} + ), + nil. + +-spec new_selector() -> selector(any()). +new_selector() -> + gleam_erlang_ffi:new_selector(). + +-spec select(selector(GZB), integer()) -> {ok, GZB} | {error, nil}. +select(From, Within) -> + gleam_erlang_ffi:select(From, Within). + +-spec select_forever(selector(GZF)) -> GZF. +select_forever(From) -> + gleam_erlang_ffi:select(From). + +-spec map_selector(selector(GZH), fun((GZH) -> GZJ)) -> selector(GZJ). +map_selector(A, B) -> + gleam_erlang_ffi:map_selector(A, B). + +-spec merge_selector(selector(GZL), selector(GZL)) -> selector(GZL). +merge_selector(A, B) -> + gleam_erlang_ffi:merge_selector(A, B). + +-spec flush_messages() -> nil. +flush_messages() -> + gleam_erlang_ffi:flush_messages(). + +-spec selecting_trapped_exits(selector(GZP), fun((exit_message()) -> GZP)) -> selector(GZP). +selecting_trapped_exits(Selector, Handler) -> + Tag = erlang:binary_to_atom(<<"EXIT"/utf8>>), + Handler@1 = fun(Message) -> + Reason = erlang:element(3, Message), + Normal = gleam@dynamic:from(normal), + Killed = gleam@dynamic:from(killed), + Reason@2 = case gleam@dynamic:string(Reason) of + _ when Reason =:= Normal -> + normal; + + _ when Reason =:= Killed -> + killed; + + {ok, Reason@1} -> + {abnormal, Reason@1}; + + {error, _} -> + {abnormal, gleam@string:inspect(Reason)} + end, + Handler({exit_message, erlang:element(2, Message), Reason@2}) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 3}, Handler@1). + +-spec selecting(selector(GZS), subject(GZU), fun((GZU) -> GZS)) -> selector(GZS). +selecting(Selector, Subject, Transform) -> + Handler = fun(Message) -> Transform(erlang:element(2, Message)) end, + gleam_erlang_ffi:insert_selector_handler( + Selector, + {erlang:element(3, Subject), 2}, + Handler + ). + +-spec 'receive'(subject(GYV), integer()) -> {ok, GYV} | {error, nil}. +'receive'(Subject, Milliseconds) -> + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = selecting(_pipe, Subject, fun(X) -> X end), + gleam_erlang_ffi:select(_pipe@1, Milliseconds). + +-spec selecting_record2( + selector(GZX), + any(), + fun((gleam@dynamic:dynamic_()) -> GZX) +) -> selector(GZX). +selecting_record2(Selector, Tag, Transform) -> + Handler = fun(Message) -> Transform(erlang:element(2, Message)) end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 2}, Handler). + +-spec selecting_record3( + selector(HAB), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAB) +) -> selector(HAB). +selecting_record3(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform(erlang:element(2, Message), erlang:element(3, Message)) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 3}, Handler). + +-spec selecting_record4( + selector(HAF), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAF) +) -> selector(HAF). +selecting_record4(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform( + erlang:element(2, Message), + erlang:element(3, Message), + erlang:element(4, Message) + ) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 4}, Handler). + +-spec selecting_record5( + selector(HAJ), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAJ) +) -> selector(HAJ). +selecting_record5(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform( + erlang:element(2, Message), + erlang:element(3, Message), + erlang:element(4, Message), + erlang:element(5, Message) + ) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 5}, Handler). + +-spec selecting_record6( + selector(HAN), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAN) +) -> selector(HAN). +selecting_record6(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform( + erlang:element(2, Message), + erlang:element(3, Message), + erlang:element(4, Message), + erlang:element(5, Message), + erlang:element(6, Message) + ) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 6}, Handler). + +-spec selecting_record7( + selector(HAR), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAR) +) -> selector(HAR). +selecting_record7(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform( + erlang:element(2, Message), + erlang:element(3, Message), + erlang:element(4, Message), + erlang:element(5, Message), + erlang:element(6, Message), + erlang:element(7, Message) + ) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 7}, Handler). + +-spec selecting_record8( + selector(HAV), + any(), + fun((gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_(), gleam@dynamic:dynamic_()) -> HAV) +) -> selector(HAV). +selecting_record8(Selector, Tag, Transform) -> + Handler = fun(Message) -> + Transform( + erlang:element(2, Message), + erlang:element(3, Message), + erlang:element(4, Message), + erlang:element(5, Message), + erlang:element(6, Message), + erlang:element(7, Message), + erlang:element(8, Message) + ) + end, + gleam_erlang_ffi:insert_selector_handler(Selector, {Tag, 8}, Handler). + +-spec selecting_anything(selector(HAZ), fun((gleam@dynamic:dynamic_()) -> HAZ)) -> selector(HAZ). +selecting_anything(Selector, Handler) -> + gleam_erlang_ffi:insert_selector_handler(Selector, anything, Handler). + +-spec sleep(integer()) -> nil. +sleep(A) -> + gleam_erlang_ffi:sleep(A). + +-spec sleep_forever() -> nil. +sleep_forever() -> + gleam_erlang_ffi:sleep_forever(). + +-spec is_alive(pid_()) -> boolean(). +is_alive(A) -> + erlang:is_process_alive(A). + +-spec monitor_process(pid_()) -> process_monitor(). +monitor_process(Pid) -> + _pipe = process, + _pipe@1 = erlang:monitor(_pipe, Pid), + {process_monitor, _pipe@1}. + +-spec selecting_process_down( + selector(HBH), + process_monitor(), + fun((process_down()) -> HBH) +) -> selector(HBH). +selecting_process_down(Selector, Monitor, Mapping) -> + gleam_erlang_ffi:insert_selector_handler( + Selector, + erlang:element(2, Monitor), + Mapping + ). + +-spec demonitor_process(process_monitor()) -> nil. +demonitor_process(Monitor) -> + gleam_erlang_ffi:demonitor(Monitor). + +-spec try_call(subject(HBK), fun((subject(HBM)) -> HBK), integer()) -> {ok, HBM} | + {error, call_error(HBM)}. +try_call(Subject, Make_request, Timeout) -> + Reply_subject = new_subject(), + Monitor = monitor_process(subject_owner(Subject)), + send(Subject, Make_request(Reply_subject)), + Result = begin + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = selecting( + _pipe, + Reply_subject, + fun(Field@0) -> {ok, Field@0} end + ), + _pipe@2 = selecting_process_down( + _pipe@1, + Monitor, + fun(Down) -> {error, {callee_down, erlang:element(3, Down)}} end + ), + gleam_erlang_ffi:select(_pipe@2, Timeout) + end, + gleam_erlang_ffi:demonitor(Monitor), + case Result of + {error, nil} -> + {error, call_timeout}; + + {ok, Res} -> + Res + end. + +-spec call(subject(HBR), fun((subject(HBT)) -> HBR), integer()) -> HBT. +call(Subject, Make_request, Timeout) -> + _assert_subject = try_call(Subject, Make_request, Timeout), + {ok, Resp} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam/erlang/process"/utf8>>, + function => <<"call"/utf8>>, + line => 593}) + end, + Resp. + +-spec link(pid_()) -> boolean(). +link(Pid) -> + gleam_erlang_ffi:link(Pid). + +-spec unlink(pid_()) -> nil. +unlink(Pid) -> + erlang:unlink(Pid), + nil. + +-spec send_after(subject(HBW), integer(), HBW) -> timer(). +send_after(Subject, Delay, Message) -> + erlang:send_after( + Delay, + erlang:element(2, Subject), + {erlang:element(3, Subject), Message} + ). + +-spec cancel_timer(timer()) -> cancelled(). +cancel_timer(Timer) -> + case gleam@dynamic:int(erlang:cancel_timer(Timer)) of + {ok, I} -> + {cancelled, I}; + + {error, _} -> + timer_not_found + end. + +-spec kill(pid_()) -> nil. +kill(Pid) -> + erlang:exit(Pid, kill), + nil. + +-spec send_exit(pid_()) -> nil. +send_exit(Pid) -> + erlang:exit(Pid, normal), + nil. + +-spec send_abnormal_exit(pid_(), binary()) -> nil. +send_abnormal_exit(Pid, Reason) -> + erlang:exit(Pid, {abnormal, Reason}), + nil. + +-spec trap_exits(boolean()) -> nil. +trap_exits(A) -> + gleam_erlang_ffi:trap_exits(A). + +-spec register(pid_(), gleam@erlang@atom:atom_()) -> {ok, nil} | {error, nil}. +register(Pid, Name) -> + gleam_erlang_ffi:register_process(Pid, Name). + +-spec unregister(gleam@erlang@atom:atom_()) -> {ok, nil} | {error, nil}. +unregister(Name) -> + gleam_erlang_ffi:unregister_process(Name). + +-spec named(gleam@erlang@atom:atom_()) -> {ok, pid_()} | {error, nil}. +named(Name) -> + gleam_erlang_ffi:process_named(Name). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl new file mode 100644 index 0000000..872126f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl @@ -0,0 +1,263 @@ +-module(gleam_erlang_ffi). +-export([ + atom_from_dynamic/1, rescue/1, atom_from_string/1, get_line/1, + ensure_all_started/1, sleep/1, os_family/0, sleep_forever/0, read_file/1, + append_file/2, write_file/2, delete_file/1, get_all_env/0, get_env/1, + set_env/2, unset_env/1, delete_directory/1, recursive_delete/1, + list_directory/1, demonitor/1, make_directory/1, new_selector/0, link/1, + insert_selector_handler/3, select/1, select/2, trap_exits/1, map_selector/2, + merge_selector/2, flush_messages/0, file_info/1, link_info/1, + priv_directory/1, connect_node/1, register_process/2, unregister_process/1, + process_named/1, identity/1 +]). + +-define(is_posix_error(Error), + Error =:= eacces orelse Error =:= eagain orelse Error =:= ebadf orelse + Error =:= ebadmsg orelse Error =:= ebusy orelse Error =:= edeadlk orelse + Error =:= edeadlock orelse Error =:= edquot orelse Error =:= eexist orelse + Error =:= efault orelse Error =:= efbig orelse Error =:= eftype orelse + Error =:= eintr orelse Error =:= einval orelse Error =:= eio orelse + Error =:= eisdir orelse Error =:= eloop orelse Error =:= emfile orelse + Error =:= emlink orelse Error =:= emultihop orelse Error =:= enametoolong orelse + Error =:= enfile orelse Error =:= enobufs orelse Error =:= enodev orelse + Error =:= enolck orelse Error =:= enolink orelse Error =:= enoent orelse + Error =:= enomem orelse Error =:= enospc orelse Error =:= enosr orelse + Error =:= enostr orelse Error =:= enosys orelse Error =:= enotblk orelse + Error =:= enotdir orelse Error =:= enotsup orelse Error =:= enxio orelse + Error =:= eopnotsupp orelse Error =:= eoverflow orelse Error =:= eperm orelse + Error =:= epipe orelse Error =:= erange orelse Error =:= erofs orelse + Error =:= espipe orelse Error =:= esrch orelse Error =:= estale orelse + Error =:= etxtbsy orelse Error =:= exdev +). + +-spec atom_from_string(binary()) -> {ok, atom()} | {error, atom_not_loaded}. +atom_from_string(S) -> + try {ok, binary_to_existing_atom(S)} + catch error:badarg -> {error, atom_not_loaded} + end. + +atom_from_dynamic(Data) when is_atom(Data) -> + {ok, Data}; +atom_from_dynamic(Data) -> + {error, [{decode_error, <<"Atom">>, gleam@dynamic:classify(Data), []}]}. + +-spec get_line(io:prompt()) -> {ok, unicode:unicode_binary()} | {error, eof | no_data}. +get_line(Prompt) -> + case io:get_line(Prompt) of + eof -> {error, eof}; + {error, _} -> {error, no_data}; + Data when is_binary(Data) -> {ok, Data}; + Data when is_list(Data) -> {ok, unicode:characters_to_binary(Data)} + end. + +rescue(F) -> + try {ok, F()} + catch + throw:X -> {error, {thrown, X}}; + error:X -> {error, {errored, X}}; + exit:X -> {error, {exited, X}} + end. + +ensure_all_started(Application) -> + case application:ensure_all_started(Application) of + {ok, _} = Ok -> Ok; + + {error, {ProblemApp, {"no such file or directory", _}}} -> + {error, {unknown_application, ProblemApp}} + end. + +sleep(Microseconds) -> + timer:sleep(Microseconds), + nil. + +sleep_forever() -> + timer:sleep(infinity), + nil. + +file_info_result(Result) -> + case Result of + {ok, {file_info, Size, Type, Access, Atime, Mtime, Ctime, Mode, Links, MajorDevice, MinorDevice, Inode, Uid, Gid}} when Access =:= none -> + {ok, {file_info, Size, Type, no_access, Atime, Mtime, Ctime, Mode, Links, MajorDevice, MinorDevice, Inode, Uid, Gid}}; + {ok, _} -> + Result; + {error, Reason} when ?is_posix_error(Reason) -> + Result + end. + +file_info(Filename) -> + file_info_result(file:read_file_info(Filename, [{time, posix}])). + +link_info(Filename) -> + file_info_result(file:read_link_info(Filename, [{time, posix}])). + +posix_result(Result) -> + case Result of + ok -> {ok, nil}; + {ok, Value} -> {ok, Value}; + {error, Reason} when ?is_posix_error(Reason) -> {error, Reason} + end. + +read_file(Filename) -> + posix_result(file:read_file(Filename)). + +write_file(Contents, Filename) -> + posix_result(file:write_file(Filename, Contents)). + +append_file(Contents, Filename) -> + posix_result(file:write_file(Filename, Contents, [append])). + +delete_file(Filename) -> + posix_result(file:delete(Filename)). + +make_directory(Dir) -> + posix_result(file:make_dir(Dir)). + +list_directory(Dir) -> + case file:list_dir(Dir) of + {ok, Filenames} -> + {ok, [list_to_binary(Filename) || Filename <- Filenames]}; + {error, Reason} when ?is_posix_error(Reason) -> + {error, Reason} + end. + +delete_directory(Dir) -> + posix_result(file:del_dir(Dir)). + +recursive_delete(Dir) -> + posix_result(file:del_dir_r(Dir)). + +get_all_env() -> + BinVars = lists:map(fun(VarString) -> + [VarName, VarVal] = string:split(VarString, "="), + {list_to_binary(VarName), list_to_binary(VarVal)} + end, os:getenv()), + maps:from_list(BinVars). + +get_env(Name) -> + case os:getenv(binary_to_list(Name)) of + false -> {error, nil}; + Value -> {ok, list_to_binary(Value)} + end. + +set_env(Name, Value) -> + os:putenv(binary_to_list(Name), binary_to_list(Value)), + nil. + +unset_env(Name) -> + os:unsetenv(binary_to_list(Name)), + nil. + +os_family() -> + case os:type() of + {win32, nt} -> + windows_nt; + {unix, linux} -> + linux; + {unix, darwin} -> + darwin; + {unix, freebsd} -> + free_bsd; + {_, Other} -> + {other, atom_to_binary(Other, utf8)} + end. + +new_selector() -> + {selector, #{}}. + +map_selector({selector, Handlers}, Fn) -> + MappedHandlers = maps:map(fun(_Tag, Handler) -> + fun(Message) -> Fn(Handler(Message)) end + end, Handlers), + {selector, MappedHandlers}. + +merge_selector({selector, HandlersA}, {selector, HandlersB}) -> + {selector, maps:merge(HandlersA, HandlersB)}. + +insert_selector_handler({selector, Handlers}, Tag, Fn) -> + {selector, Handlers#{Tag => Fn}}. + +select(Selector) -> + {ok, Message} = select(Selector, infinity), + Message. + +select({selector, Handlers}, Timeout) -> + AnythingHandler = maps:get(anything, Handlers, undefined), + receive + % Monitored process down messages. + % This is special cased so we can selectively receive based on the + % reference as well as the record tag. + {'DOWN', Ref, process, Pid, Reason} when is_map_key(Ref, Handlers) -> + Fn = maps:get(Ref, Handlers), + {ok, Fn({process_down, Pid, Reason})}; + + Msg when is_map_key({element(1, Msg), tuple_size(Msg)}, Handlers) -> + Fn = maps:get({element(1, Msg), tuple_size(Msg)}, Handlers), + {ok, Fn(Msg)}; + + Msg when AnythingHandler =/= undefined -> + {ok, AnythingHandler(Msg)} + after Timeout -> + {error, nil} + end. + +demonitor({_, Reference}) -> + erlang:demonitor(Reference, [flush]). + +link(Pid) -> + try + erlang:link(Pid) + catch + error:_ -> false + end. + +trap_exits(ShouldTrap) -> + erlang:process_flag(trap_exit, ShouldTrap), + nil. + +flush_messages() -> + receive _Message -> flush_messages() + after 0 -> nil + end. + +priv_directory(Name) -> + try erlang:binary_to_existing_atom(Name) of + Atom -> + case code:priv_dir(Atom) of + {error, _} -> {error, nil}; + Path -> {ok, unicode:characters_to_binary(Path)} + end + catch + error:badarg -> {error, nil} + end. + +connect_node(Node) -> + case net_kernel:connect_node(Node) of + true -> {ok, Node}; + false -> {error, failed_to_connect}; + ignored -> {error, local_node_is_not_alive} + end. + +register_process(Pid, Name) -> + try + true = erlang:register(Name, Pid), + {ok, nil} + catch + error:badarg -> {error, nil} + end. + +unregister_process(Name) -> + try + true = erlang:unregister(Name), + {ok, nil} + catch + error:badarg -> {error, nil} + end. + +process_named(Name) -> + case erlang:whereis(Name) of + Pid when is_pid(Pid) -> {ok, Pid}; + _ -> {error, nil} + end. + +identity(X) -> + X. diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang.beam Binary files differnew file mode 100644 index 0000000..9f714eb --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@atom.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@atom.beam Binary files differnew file mode 100644 index 0000000..a85b4fa --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@atom.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@charlist.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@charlist.beam Binary files differnew file mode 100644 index 0000000..6d78db3 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@charlist.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@file.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@file.beam Binary files differnew file mode 100644 index 0000000..7990b72 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@file.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@node.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@node.beam Binary files differnew file mode 100644 index 0000000..d8ebb84 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@node.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@os.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@os.beam Binary files differnew file mode 100644 index 0000000..40d121a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@os.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@process.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@process.beam Binary files differnew file mode 100644 index 0000000..8a73d73 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam@erlang@process.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang.app b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang.app new file mode 100644 index 0000000..79950ab --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang.app @@ -0,0 +1,7 @@ +{application, gleam_erlang, [ + {vsn, "0.23.1"}, + {applications, [gleam_stdlib]}, + {description, "A Gleam library for working with Erlang"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang_ffi.beam b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang_ffi.beam Binary files differnew file mode 100644 index 0000000..965c70b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/ebin/gleam_erlang_ffi.beam diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@file_FileInfo.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@file_FileInfo.hrl new file mode 100644 index 0000000..b38d11e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@file_FileInfo.hrl @@ -0,0 +1,15 @@ +-record(file_info, { + size :: integer(), + file_type :: gleam@erlang@file:file_type(), + access :: gleam@erlang@file:access(), + atime :: integer(), + mtime :: integer(), + ctime :: integer(), + mode :: integer(), + links :: integer(), + major_device :: integer(), + minor_device :: integer(), + inode :: integer(), + user_id :: integer(), + group_id :: integer() +}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Abnormal.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Abnormal.hrl new file mode 100644 index 0000000..4cd0452 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Abnormal.hrl @@ -0,0 +1 @@ +-record(abnormal, {reason :: binary()}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_CalleeDown.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_CalleeDown.hrl new file mode 100644 index 0000000..5dd5047 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_CalleeDown.hrl @@ -0,0 +1 @@ +-record(callee_down, {reason :: gleam@dynamic:dynamic_()}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Cancelled.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Cancelled.hrl new file mode 100644 index 0000000..b82b49f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Cancelled.hrl @@ -0,0 +1 @@ +-record(cancelled, {time_remaining :: integer()}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ExitMessage.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ExitMessage.hrl new file mode 100644 index 0000000..c476308 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ExitMessage.hrl @@ -0,0 +1,4 @@ +-record(exit_message, { + pid :: gleam@erlang@process:pid_(), + reason :: gleam@erlang@process:exit_reason() +}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessDown.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessDown.hrl new file mode 100644 index 0000000..df0b6b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessDown.hrl @@ -0,0 +1,4 @@ +-record(process_down, { + pid :: gleam@erlang@process:pid_(), + reason :: gleam@dynamic:dynamic_() +}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessMonitor.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessMonitor.hrl new file mode 100644 index 0000000..ce552e2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_ProcessMonitor.hrl @@ -0,0 +1 @@ +-record(process_monitor, {tag :: gleam@erlang:reference_()}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Subject.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Subject.hrl new file mode 100644 index 0000000..abc46b2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang@process_Subject.hrl @@ -0,0 +1,4 @@ +-record(subject, { + owner :: gleam@erlang@process:pid_(), + tag :: gleam@erlang:reference_() +}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_ApplicationFailedToStart.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_ApplicationFailedToStart.hrl new file mode 100644 index 0000000..52c9896 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_ApplicationFailedToStart.hrl @@ -0,0 +1,4 @@ +-record(application_failed_to_start, { + name :: gleam@erlang@atom:atom_(), + reason :: gleam@dynamic:dynamic_() +}). diff --git a/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_UnknownApplication.hrl b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_UnknownApplication.hrl new file mode 100644 index 0000000..fde3c61 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_erlang/include/gleam@erlang_UnknownApplication.hrl @@ -0,0 +1 @@ +-record(unknown_application, {name :: gleam@erlang@atom:atom_()}). diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache Binary files differnew file mode 100644 index 0000000..5bba9de --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache_meta b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache_meta Binary files differnew file mode 100644 index 0000000..dc85da7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.erl new file mode 100644 index 0000000..ebc8768 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http.erl @@ -0,0 +1,626 @@ +-module(gleam@http). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([parse_method/1, method_to_string/1, scheme_to_string/1, scheme_from_string/1, parse_content_disposition/1, parse_multipart_body/2, method_from_dynamic/1, parse_multipart_headers/2]). +-export_type([method/0, scheme/0, multipart_headers/0, multipart_body/0, content_disposition/0]). + +-type method() :: get | + post | + head | + put | + delete | + trace | + connect | + options | + patch | + {other, binary()}. + +-type scheme() :: http | https. + +-type multipart_headers() :: {multipart_headers, + list({binary(), binary()}), + bitstring()} | + {more_required_for_headers, + fun((bitstring()) -> {ok, multipart_headers()} | {error, nil})}. + +-type multipart_body() :: {multipart_body, bitstring(), boolean(), bitstring()} | + {more_required_for_body, + bitstring(), + fun((bitstring()) -> {ok, multipart_body()} | {error, nil})}. + +-type content_disposition() :: {content_disposition, + binary(), + list({binary(), binary()})}. + +-spec parse_method(binary()) -> {ok, method()} | {error, nil}. +parse_method(S) -> + case gleam@string:lowercase(S) of + <<"connect"/utf8>> -> + {ok, connect}; + + <<"delete"/utf8>> -> + {ok, delete}; + + <<"get"/utf8>> -> + {ok, get}; + + <<"head"/utf8>> -> + {ok, head}; + + <<"options"/utf8>> -> + {ok, options}; + + <<"patch"/utf8>> -> + {ok, patch}; + + <<"post"/utf8>> -> + {ok, post}; + + <<"put"/utf8>> -> + {ok, put}; + + <<"trace"/utf8>> -> + {ok, trace}; + + _ -> + {error, nil} + end. + +-spec method_to_string(method()) -> binary(). +method_to_string(Method) -> + case Method of + connect -> + <<"connect"/utf8>>; + + delete -> + <<"delete"/utf8>>; + + get -> + <<"get"/utf8>>; + + head -> + <<"head"/utf8>>; + + options -> + <<"options"/utf8>>; + + patch -> + <<"patch"/utf8>>; + + post -> + <<"post"/utf8>>; + + put -> + <<"put"/utf8>>; + + trace -> + <<"trace"/utf8>>; + + {other, S} -> + S + end. + +-spec scheme_to_string(scheme()) -> binary(). +scheme_to_string(Scheme) -> + case Scheme of + http -> + <<"http"/utf8>>; + + https -> + <<"https"/utf8>> + end. + +-spec scheme_from_string(binary()) -> {ok, scheme()} | {error, nil}. +scheme_from_string(Scheme) -> + case gleam@string:lowercase(Scheme) of + <<"http"/utf8>> -> + {ok, http}; + + <<"https"/utf8>> -> + {ok, https}; + + _ -> + {error, nil} + end. + +-spec skip_whitespace(bitstring()) -> bitstring(). +skip_whitespace(Data) -> + case Data of + <<32, Data@1/binary>> -> + skip_whitespace(Data@1); + + <<9, Data@1/binary>> -> + skip_whitespace(Data@1); + + _ -> + Data + end. + +-spec more_please_headers( + fun((bitstring()) -> {ok, multipart_headers()} | {error, nil}), + bitstring() +) -> {ok, multipart_headers()} | {error, nil}. +more_please_headers(Continuation, Existing) -> + {ok, + {more_required_for_headers, + fun(More) -> + gleam@bool:guard( + More =:= <<>>, + {error, nil}, + fun() -> + Continuation(<<Existing/bitstring, More/bitstring>>) + end + ) + end}}. + +-spec parse_rfc_2045_parameter_quoted_value(binary(), binary(), binary()) -> {ok, + {{binary(), binary()}, binary()}} | + {error, nil}. +parse_rfc_2045_parameter_quoted_value(Header, Name, Value) -> + case gleam@string:pop_grapheme(Header) of + {error, nil} -> + {error, nil}; + + {ok, {<<"\""/utf8>>, Rest}} -> + {ok, {{Name, Value}, Rest}}; + + {ok, {<<"\\"/utf8>>, Rest@1}} -> + gleam@result:'try'( + gleam@string:pop_grapheme(Rest@1), + fun(_use0) -> + {Grapheme, Rest@2} = _use0, + parse_rfc_2045_parameter_quoted_value( + Rest@2, + Name, + <<Value/binary, Grapheme/binary>> + ) + end + ); + + {ok, {Grapheme@1, Rest@3}} -> + parse_rfc_2045_parameter_quoted_value( + Rest@3, + Name, + <<Value/binary, Grapheme@1/binary>> + ) + end. + +-spec parse_rfc_2045_parameter_unquoted_value(binary(), binary(), binary()) -> {{binary(), + binary()}, + binary()}. +parse_rfc_2045_parameter_unquoted_value(Header, Name, Value) -> + case gleam@string:pop_grapheme(Header) of + {error, nil} -> + {{Name, Value}, Header}; + + {ok, {<<";"/utf8>>, Rest}} -> + {{Name, Value}, Rest}; + + {ok, {<<" "/utf8>>, Rest}} -> + {{Name, Value}, Rest}; + + {ok, {<<"\t"/utf8>>, Rest}} -> + {{Name, Value}, Rest}; + + {ok, {Grapheme, Rest@1}} -> + parse_rfc_2045_parameter_unquoted_value( + Rest@1, + Name, + <<Value/binary, Grapheme/binary>> + ) + end. + +-spec parse_rfc_2045_parameter_value(binary(), binary()) -> {ok, + {{binary(), binary()}, binary()}} | + {error, nil}. +parse_rfc_2045_parameter_value(Header, Name) -> + case gleam@string:pop_grapheme(Header) of + {error, nil} -> + {error, nil}; + + {ok, {<<"\""/utf8>>, Rest}} -> + parse_rfc_2045_parameter_quoted_value(Rest, Name, <<""/utf8>>); + + {ok, {Grapheme, Rest@1}} -> + {ok, + parse_rfc_2045_parameter_unquoted_value(Rest@1, Name, Grapheme)} + end. + +-spec parse_rfc_2045_parameter(binary(), binary()) -> {ok, + {{binary(), binary()}, binary()}} | + {error, nil}. +parse_rfc_2045_parameter(Header, Name) -> + gleam@result:'try'( + gleam@string:pop_grapheme(Header), + fun(_use0) -> + {Grapheme, Rest} = _use0, + case Grapheme of + <<"="/utf8>> -> + parse_rfc_2045_parameter_value(Rest, Name); + + _ -> + parse_rfc_2045_parameter( + Rest, + <<Name/binary, + (gleam@string:lowercase(Grapheme))/binary>> + ) + end + end + ). + +-spec parse_rfc_2045_parameters(binary(), list({binary(), binary()})) -> {ok, + list({binary(), binary()})} | + {error, nil}. +parse_rfc_2045_parameters(Header, Parameters) -> + case gleam@string:pop_grapheme(Header) of + {error, nil} -> + {ok, gleam@list:reverse(Parameters)}; + + {ok, {<<";"/utf8>>, Rest}} -> + parse_rfc_2045_parameters(Rest, Parameters); + + {ok, {<<" "/utf8>>, Rest}} -> + parse_rfc_2045_parameters(Rest, Parameters); + + {ok, {<<"\t"/utf8>>, Rest}} -> + parse_rfc_2045_parameters(Rest, Parameters); + + {ok, {Grapheme, Rest@1}} -> + Acc = gleam@string:lowercase(Grapheme), + gleam@result:'try'( + parse_rfc_2045_parameter(Rest@1, Acc), + fun(_use0) -> + {Parameter, Rest@2} = _use0, + parse_rfc_2045_parameters(Rest@2, [Parameter | Parameters]) + end + ) + end. + +-spec parse_content_disposition_type(binary(), binary()) -> {ok, + content_disposition()} | + {error, nil}. +parse_content_disposition_type(Header, Name) -> + case gleam@string:pop_grapheme(Header) of + {error, nil} -> + {ok, {content_disposition, Name, []}}; + + {ok, {<<" "/utf8>>, Rest}} -> + Result = parse_rfc_2045_parameters(Rest, []), + gleam@result:map( + Result, + fun(Parameters) -> {content_disposition, Name, Parameters} end + ); + + {ok, {<<"\t"/utf8>>, Rest}} -> + Result = parse_rfc_2045_parameters(Rest, []), + gleam@result:map( + Result, + fun(Parameters) -> {content_disposition, Name, Parameters} end + ); + + {ok, {<<";"/utf8>>, Rest}} -> + Result = parse_rfc_2045_parameters(Rest, []), + gleam@result:map( + Result, + fun(Parameters) -> {content_disposition, Name, Parameters} end + ); + + {ok, {Grapheme, Rest@1}} -> + parse_content_disposition_type( + Rest@1, + <<Name/binary, (gleam@string:lowercase(Grapheme))/binary>> + ) + end. + +-spec parse_content_disposition(binary()) -> {ok, content_disposition()} | + {error, nil}. +parse_content_disposition(Header) -> + parse_content_disposition_type(Header, <<""/utf8>>). + +-spec more_please_body( + fun((bitstring()) -> {ok, multipart_body()} | {error, nil}), + bitstring(), + bitstring() +) -> {ok, multipart_body()} | {error, nil}. +more_please_body(Continuation, Chunk, Existing) -> + _pipe = fun(More) -> + gleam@bool:guard( + More =:= <<>>, + {error, nil}, + fun() -> Continuation(<<Existing/bitstring, More/bitstring>>) end + ) + end, + _pipe@1 = {more_required_for_body, Chunk, _pipe}, + {ok, _pipe@1}. + +-spec parse_body_loop(bitstring(), bitstring(), bitstring()) -> {ok, + multipart_body()} | + {error, nil}. +parse_body_loop(Data, Boundary, Body) -> + Dsize = erlang:byte_size(Data), + Bsize = erlang:byte_size(Boundary), + Required = 6 + Bsize, + case Data of + _ when Dsize < Required -> + more_please_body( + fun(_capture) -> parse_body_loop(_capture, Boundary, <<>>) end, + Body, + Data + ); + + <<13, 10, Data@1/binary>> -> + Desired = <<45, 45, Boundary/bitstring>>, + Size = erlang:byte_size(Desired), + Dsize@1 = erlang:byte_size(Data@1), + Prefix = gleam_stdlib:bit_array_slice(Data@1, 0, Size), + Rest = gleam_stdlib:bit_array_slice(Data@1, Size, Dsize@1 - Size), + case {Prefix =:= {ok, Desired}, Rest} of + {true, {ok, <<13, 10, _/binary>>}} -> + {ok, {multipart_body, Body, false, Data@1}}; + + {true, {ok, <<45, 45, Data@2/binary>>}} -> + {ok, {multipart_body, Body, true, Data@2}}; + + {false, _} -> + parse_body_loop( + Data@1, + Boundary, + <<Body/bitstring, 13, 10>> + ); + + {_, _} -> + {error, nil} + end; + + <<Char, Data@3/binary>> -> + parse_body_loop(Data@3, Boundary, <<Body/bitstring, Char>>) + end. + +-spec parse_body_with_bit_array(bitstring(), bitstring()) -> {ok, + multipart_body()} | + {error, nil}. +parse_body_with_bit_array(Data, Boundary) -> + Bsize = erlang:byte_size(Boundary), + Prefix = gleam_stdlib:bit_array_slice(Data, 0, 2 + Bsize), + case Prefix =:= {ok, <<45, 45, Boundary/bitstring>>} of + true -> + {ok, {multipart_body, <<>>, false, Data}}; + + false -> + parse_body_loop(Data, Boundary, <<>>) + end. + +-spec parse_multipart_body(bitstring(), binary()) -> {ok, multipart_body()} | + {error, nil}. +parse_multipart_body(Data, Boundary) -> + _pipe = Boundary, + _pipe@1 = gleam_stdlib:identity(_pipe), + parse_body_with_bit_array(Data, _pipe@1). + +-spec method_from_dynamic(gleam@dynamic:dynamic_()) -> {ok, method()} | + {error, list(gleam@dynamic:decode_error())}. +method_from_dynamic(Value) -> + case gleam_http_native:decode_method(Value) of + {ok, Method} -> + {ok, Method}; + + {error, _} -> + {error, + [{decode_error, + <<"HTTP method"/utf8>>, + gleam@dynamic:classify(Value), + []}]} + end. + +-spec parse_header_value( + bitstring(), + list({binary(), binary()}), + bitstring(), + bitstring() +) -> {ok, multipart_headers()} | {error, nil}. +parse_header_value(Data, Headers, Name, Value) -> + Size = erlang:byte_size(Data), + case Data of + _ when Size < 4 -> + _pipe@2 = fun(Data@1) -> _pipe = Data@1, + _pipe@1 = skip_whitespace(_pipe), + parse_header_value(_pipe@1, Headers, Name, Value) end, + more_please_headers(_pipe@2, Data); + + <<13, 10, 13, 10, Data@2/binary>> -> + gleam@result:'try'( + gleam@bit_array:to_string(Name), + fun(Name@1) -> + gleam@result:map( + gleam@bit_array:to_string(Value), + fun(Value@1) -> + Headers@1 = gleam@list:reverse( + [{gleam@string:lowercase(Name@1), Value@1} | + Headers] + ), + {multipart_headers, Headers@1, Data@2} + end + ) + end + ); + + <<13, 10, 32, Data@3/binary>> -> + parse_header_value(Data@3, Headers, Name, Value); + + <<13, 10, 9, Data@3/binary>> -> + parse_header_value(Data@3, Headers, Name, Value); + + <<13, 10, Data@4/binary>> -> + gleam@result:'try'( + gleam@bit_array:to_string(Name), + fun(Name@2) -> + gleam@result:'try'( + gleam@bit_array:to_string(Value), + fun(Value@2) -> + Headers@2 = [{gleam@string:lowercase(Name@2), + Value@2} | + Headers], + parse_header_name(Data@4, Headers@2, <<>>) + end + ) + end + ); + + <<Char, Rest/binary>> -> + Value@3 = <<Value/bitstring, Char>>, + parse_header_value(Rest, Headers, Name, Value@3); + + _ -> + {error, nil} + end. + +-spec parse_header_name(bitstring(), list({binary(), binary()}), bitstring()) -> {ok, + multipart_headers()} | + {error, nil}. +parse_header_name(Data, Headers, Name) -> + case skip_whitespace(Data) of + <<58, Data@1/binary>> -> + _pipe = Data@1, + _pipe@1 = skip_whitespace(_pipe), + parse_header_value(_pipe@1, Headers, Name, <<>>); + + <<Char, Data@2/binary>> -> + parse_header_name(Data@2, Headers, <<Name/bitstring, Char>>); + + <<>> -> + more_please_headers( + fun(_capture) -> parse_header_name(_capture, Headers, Name) end, + Data + ) + end. + +-spec do_parse_headers(bitstring()) -> {ok, multipart_headers()} | {error, nil}. +do_parse_headers(Data) -> + case Data of + <<13, 10, 13, 10, Data@1/binary>> -> + {ok, {multipart_headers, [], Data@1}}; + + <<13, 10, Data@2/binary>> -> + parse_header_name(Data@2, [], <<>>); + + <<13>> -> + more_please_headers(fun do_parse_headers/1, Data); + + <<>> -> + more_please_headers(fun do_parse_headers/1, Data); + + _ -> + {error, nil} + end. + +-spec parse_headers_after_prelude(bitstring(), bitstring()) -> {ok, + multipart_headers()} | + {error, nil}. +parse_headers_after_prelude(Data, Boundary) -> + Dsize = erlang:byte_size(Data), + Bsize = erlang:byte_size(Boundary), + Required_size = Bsize + 4, + gleam@bool:guard( + Dsize < Required_size, + more_please_headers( + fun(_capture) -> parse_headers_after_prelude(_capture, Boundary) end, + Data + ), + fun() -> + gleam@result:'try'( + gleam_stdlib:bit_array_slice(Data, 0, Required_size - 2), + fun(Prefix) -> + gleam@result:'try'( + gleam_stdlib:bit_array_slice(Data, 2 + Bsize, 2), + fun(Second) -> + Desired = <<45, 45, Boundary/bitstring>>, + gleam@bool:guard( + Prefix /= Desired, + {error, nil}, + fun() -> case Second =:= <<45, 45>> of + true -> + Rest_size = Dsize - Required_size, + gleam@result:map( + gleam_stdlib:bit_array_slice( + Data, + Required_size, + Rest_size + ), + fun(Data@1) -> + {multipart_headers, + [], + Data@1} + end + ); + + false -> + Start = Required_size - 2, + Rest_size@1 = (Dsize - Required_size) + + 2, + gleam@result:'try'( + gleam_stdlib:bit_array_slice( + Data, + Start, + Rest_size@1 + ), + fun(Data@2) -> + do_parse_headers(Data@2) + end + ) + end end + ) + end + ) + end + ) + end + ). + +-spec skip_preamble(bitstring(), bitstring()) -> {ok, multipart_headers()} | + {error, nil}. +skip_preamble(Data, Boundary) -> + Data_size = erlang:byte_size(Data), + Boundary_size = erlang:byte_size(Boundary), + Required = Boundary_size + 4, + case Data of + _ when Data_size < Required -> + more_please_headers( + fun(_capture) -> skip_preamble(_capture, Boundary) end, + Data + ); + + <<13, 10, 45, 45, Data@1/binary>> -> + case gleam_stdlib:bit_array_slice(Data@1, 0, Boundary_size) of + {ok, Prefix} when Prefix =:= Boundary -> + Start = Boundary_size, + Length = erlang:byte_size(Data@1) - Boundary_size, + gleam@result:'try'( + gleam_stdlib:bit_array_slice(Data@1, Start, Length), + fun(Rest) -> do_parse_headers(Rest) end + ); + + {ok, _} -> + skip_preamble(Data@1, Boundary); + + {error, _} -> + {error, nil} + end; + + <<_, Data@2/binary>> -> + skip_preamble(Data@2, Boundary) + end. + +-spec parse_multipart_headers(bitstring(), binary()) -> {ok, + multipart_headers()} | + {error, nil}. +parse_multipart_headers(Data, Boundary) -> + Boundary@1 = gleam_stdlib:identity(Boundary), + Prefix = <<45, 45, Boundary@1/bitstring>>, + case gleam_stdlib:bit_array_slice(Data, 0, erlang:byte_size(Prefix)) =:= {ok, + Prefix} of + true -> + parse_headers_after_prelude(Data, Boundary@1); + + false -> + skip_preamble(Data, Boundary@1) + end. diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache Binary files differnew file mode 100644 index 0000000..db0066c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache_meta b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache_meta Binary files differnew file mode 100644 index 0000000..1f65dce --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.erl new file mode 100644 index 0000000..46ee47f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@cookie.erl @@ -0,0 +1,153 @@ +-module(gleam@http@cookie). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([defaults/1, parse/1, set_header/3]). +-export_type([same_site_policy/0, attributes/0]). + +-type same_site_policy() :: lax | strict | none. + +-type attributes() :: {attributes, + gleam@option:option(integer()), + gleam@option:option(binary()), + gleam@option:option(binary()), + boolean(), + boolean(), + gleam@option:option(same_site_policy())}. + +-spec same_site_to_string(same_site_policy()) -> binary(). +same_site_to_string(Policy) -> + case Policy of + lax -> + <<"Lax"/utf8>>; + + strict -> + <<"Strict"/utf8>>; + + none -> + <<"None"/utf8>> + end. + +-spec defaults(gleam@http:scheme()) -> attributes(). +defaults(Scheme) -> + {attributes, + none, + none, + {some, <<"/"/utf8>>}, + Scheme =:= https, + true, + {some, lax}}. + +-spec check_token(binary()) -> {ok, nil} | {error, nil}. +check_token(Token) -> + case gleam@string:pop_grapheme(Token) of + {error, nil} -> + {ok, nil}; + + {ok, {<<" "/utf8>>, _}} -> + {error, nil}; + + {ok, {<<"\t"/utf8>>, _}} -> + {error, nil}; + + {ok, {<<"\r"/utf8>>, _}} -> + {error, nil}; + + {ok, {<<"\n"/utf8>>, _}} -> + {error, nil}; + + {ok, {<<"\f"/utf8>>, _}} -> + {error, nil}; + + {ok, {_, Rest}} -> + check_token(Rest) + end. + +-spec parse(binary()) -> list({binary(), binary()}). +parse(Cookie_string) -> + _assert_subject = gleam@regex:from_string(<<"[,;]"/utf8>>), + {ok, Re} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam/http/cookie"/utf8>>, + function => <<"parse"/utf8>>, + line => 101}) + end, + _pipe = gleam@regex:split(Re, Cookie_string), + gleam@list:filter_map( + _pipe, + fun(Pair) -> + case gleam@string:split_once(gleam@string:trim(Pair), <<"="/utf8>>) of + {ok, {<<""/utf8>>, _}} -> + {error, nil}; + + {ok, {Key, Value}} -> + Key@1 = gleam@string:trim(Key), + Value@1 = gleam@string:trim(Value), + gleam@result:then( + check_token(Key@1), + fun(_) -> + gleam@result:then( + check_token(Value@1), + fun(_) -> {ok, {Key@1, Value@1}} end + ) + end + ); + + {error, nil} -> + {error, nil} + end + end + ). + +-spec cookie_attributes_to_list(attributes()) -> list(list(binary())). +cookie_attributes_to_list(Attributes) -> + {attributes, Max_age, Domain, Path, Secure, Http_only, Same_site} = Attributes, + _pipe = [case Max_age of + {some, 0} -> + {some, [<<"Expires=Thu, 01 Jan 1970 00:00:00 GMT"/utf8>>]}; + + _ -> + none + end, gleam@option:map( + Max_age, + fun(Max_age@1) -> + [<<"Max-Age="/utf8>>, gleam@int:to_string(Max_age@1)] + end + ), gleam@option:map( + Domain, + fun(Domain@1) -> [<<"Domain="/utf8>>, Domain@1] end + ), gleam@option:map(Path, fun(Path@1) -> [<<"Path="/utf8>>, Path@1] end), case Secure of + true -> + {some, [<<"Secure"/utf8>>]}; + + false -> + none + end, case Http_only of + true -> + {some, [<<"HttpOnly"/utf8>>]}; + + false -> + none + end, gleam@option:map( + Same_site, + fun(Same_site@1) -> + [<<"SameSite="/utf8>>, same_site_to_string(Same_site@1)] + end + )], + gleam@list:filter_map( + _pipe, + fun(_capture) -> gleam@option:to_result(_capture, nil) end + ). + +-spec set_header(binary(), binary(), attributes()) -> binary(). +set_header(Name, Value, Attributes) -> + _pipe = [[Name, <<"="/utf8>>, Value] | + cookie_attributes_to_list(Attributes)], + _pipe@1 = gleam@list:map( + _pipe, + fun(_capture) -> gleam@string:join(_capture, <<""/utf8>>) end + ), + gleam@string:join(_pipe@1, <<"; "/utf8>>). diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache Binary files differnew file mode 100644 index 0000000..ea0a2f6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache_meta b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache_meta Binary files differnew file mode 100644 index 0000000..2108b82 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.erl new file mode 100644 index 0000000..50e6d31 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@request.erl @@ -0,0 +1,202 @@ +-module(gleam@http@request). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([to_uri/1, from_uri/1, get_header/2, set_header/3, prepend_header/3, set_body/2, map/2, path_segments/1, get_query/1, set_query/2, set_method/2, new/0, to/1, set_scheme/2, set_host/2, set_port/2, set_path/2, set_cookie/3, get_cookies/1]). +-export_type([request/1]). + +-type request(GHJ) :: {request, + gleam@http:method(), + list({binary(), binary()}), + GHJ, + gleam@http:scheme(), + binary(), + gleam@option:option(integer()), + binary(), + gleam@option:option(binary())}. + +-spec to_uri(request(any())) -> gleam@uri:uri(). +to_uri(Request) -> + {uri, + {some, gleam@http:scheme_to_string(erlang:element(5, Request))}, + none, + {some, erlang:element(6, Request)}, + erlang:element(7, Request), + erlang:element(8, Request), + erlang:element(9, Request), + none}. + +-spec from_uri(gleam@uri:uri()) -> {ok, request(binary())} | {error, nil}. +from_uri(Uri) -> + gleam@result:then( + begin + _pipe = erlang:element(2, Uri), + _pipe@1 = gleam@option:unwrap(_pipe, <<""/utf8>>), + gleam@http:scheme_from_string(_pipe@1) + end, + fun(Scheme) -> + gleam@result:then( + begin + _pipe@2 = erlang:element(4, Uri), + gleam@option:to_result(_pipe@2, nil) + end, + fun(Host) -> + Req = {request, + get, + [], + <<""/utf8>>, + Scheme, + Host, + erlang:element(5, Uri), + erlang:element(6, Uri), + erlang:element(7, Uri)}, + {ok, Req} + end + ) + end + ). + +-spec get_header(request(any()), binary()) -> {ok, binary()} | {error, nil}. +get_header(Request, Key) -> + gleam@list:key_find(erlang:element(3, Request), gleam@string:lowercase(Key)). + +-spec set_header(request(GHT), binary(), binary()) -> request(GHT). +set_header(Request, Key, Value) -> + Headers = gleam@list:key_set( + erlang:element(3, Request), + gleam@string:lowercase(Key), + Value + ), + erlang:setelement(3, Request, Headers). + +-spec prepend_header(request(GHW), binary(), binary()) -> request(GHW). +prepend_header(Request, Key, Value) -> + Headers = [{gleam@string:lowercase(Key), Value} | + erlang:element(3, Request)], + erlang:setelement(3, Request, Headers). + +-spec set_body(request(any()), GIB) -> request(GIB). +set_body(Req, Body) -> + {request, Method, Headers, _, Scheme, Host, Port, Path, Query} = Req, + {request, Method, Headers, Body, Scheme, Host, Port, Path, Query}. + +-spec map(request(GID), fun((GID) -> GIF)) -> request(GIF). +map(Request, Transform) -> + _pipe = erlang:element(4, Request), + _pipe@1 = Transform(_pipe), + set_body(Request, _pipe@1). + +-spec path_segments(request(any())) -> list(binary()). +path_segments(Request) -> + _pipe = erlang:element(8, Request), + gleam@uri:path_segments(_pipe). + +-spec get_query(request(any())) -> {ok, list({binary(), binary()})} | + {error, nil}. +get_query(Request) -> + case erlang:element(9, Request) of + {some, Query_string} -> + gleam@uri:parse_query(Query_string); + + none -> + {ok, []} + end. + +-spec set_query(request(GIP), list({binary(), binary()})) -> request(GIP). +set_query(Req, Query) -> + Pair = fun(T) -> + gleam@string_builder:from_strings( + [erlang:element(1, T), <<"="/utf8>>, erlang:element(2, T)] + ) + end, + Query@1 = begin + _pipe = Query, + _pipe@1 = gleam@list:map(_pipe, Pair), + _pipe@2 = gleam@list:intersperse( + _pipe@1, + gleam@string_builder:from_string(<<"&"/utf8>>) + ), + _pipe@3 = gleam@string_builder:concat(_pipe@2), + _pipe@4 = gleam@string_builder:to_string(_pipe@3), + {some, _pipe@4} + end, + erlang:setelement(9, Req, Query@1). + +-spec set_method(request(GIT), gleam@http:method()) -> request(GIT). +set_method(Req, Method) -> + erlang:setelement(2, Req, Method). + +-spec new() -> request(binary()). +new() -> + {request, + get, + [], + <<""/utf8>>, + https, + <<"localhost"/utf8>>, + none, + <<""/utf8>>, + none}. + +-spec to(binary()) -> {ok, request(binary())} | {error, nil}. +to(Url) -> + _pipe = Url, + _pipe@1 = gleam@uri:parse(_pipe), + gleam@result:then(_pipe@1, fun from_uri/1). + +-spec set_scheme(request(GJA), gleam@http:scheme()) -> request(GJA). +set_scheme(Req, Scheme) -> + erlang:setelement(5, Req, Scheme). + +-spec set_host(request(GJD), binary()) -> request(GJD). +set_host(Req, Host) -> + erlang:setelement(6, Req, Host). + +-spec set_port(request(GJG), integer()) -> request(GJG). +set_port(Req, Port) -> + erlang:setelement(7, Req, {some, Port}). + +-spec set_path(request(GJJ), binary()) -> request(GJJ). +set_path(Req, Path) -> + erlang:setelement(8, Req, Path). + +-spec set_cookie(request(GJM), binary(), binary()) -> request(GJM). +set_cookie(Req, Name, Value) -> + New_cookie_string = gleam@string:join([Name, Value], <<"="/utf8>>), + {Cookies_string@2, Headers@1} = case gleam@list:key_pop( + erlang:element(3, Req), + <<"cookie"/utf8>> + ) of + {ok, {Cookies_string, Headers}} -> + Cookies_string@1 = gleam@string:join( + [Cookies_string, New_cookie_string], + <<"; "/utf8>> + ), + {Cookies_string@1, Headers}; + + {error, nil} -> + {New_cookie_string, erlang:element(3, Req)} + end, + erlang:setelement( + 3, + Req, + [{<<"cookie"/utf8>>, Cookies_string@2} | Headers@1] + ). + +-spec get_cookies(request(any())) -> list({binary(), binary()}). +get_cookies(Req) -> + {request, _, Headers, _, _, _, _, _, _} = Req, + _pipe = Headers, + _pipe@1 = gleam@list:filter_map( + _pipe, + fun(Header) -> + {Name, Value} = Header, + case Name of + <<"cookie"/utf8>> -> + {ok, gleam@http@cookie:parse(Value)}; + + _ -> + {error, nil} + end + end + ), + gleam@list:flatten(_pipe@1). diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache Binary files differnew file mode 100644 index 0000000..70474f1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache_meta b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache_meta Binary files differnew file mode 100644 index 0000000..1f05041 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.erl new file mode 100644 index 0000000..27849e7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@response.erl @@ -0,0 +1,97 @@ +-module(gleam@http@response). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/1, get_header/2, set_header/3, prepend_header/3, set_body/2, try_map/2, map/2, redirect/1, get_cookies/1, set_cookie/4, expire_cookie/3]). +-export_type([response/1]). + +-type response(GON) :: {response, integer(), list({binary(), binary()}), GON}. + +-spec new(integer()) -> response(binary()). +new(Status) -> + {response, Status, [], <<""/utf8>>}. + +-spec get_header(response(any()), binary()) -> {ok, binary()} | {error, nil}. +get_header(Response, Key) -> + gleam@list:key_find( + erlang:element(3, Response), + gleam@string:lowercase(Key) + ). + +-spec set_header(response(GPC), binary(), binary()) -> response(GPC). +set_header(Response, Key, Value) -> + Headers = gleam@list:key_set( + erlang:element(3, Response), + gleam@string:lowercase(Key), + Value + ), + erlang:setelement(3, Response, Headers). + +-spec prepend_header(response(GPF), binary(), binary()) -> response(GPF). +prepend_header(Response, Key, Value) -> + Headers = [{gleam@string:lowercase(Key), Value} | + erlang:element(3, Response)], + erlang:setelement(3, Response, Headers). + +-spec set_body(response(any()), GPK) -> response(GPK). +set_body(Response, Body) -> + {response, Status, Headers, _} = Response, + {response, Status, Headers, Body}. + +-spec try_map(response(GOO), fun((GOO) -> {ok, GOQ} | {error, GOR})) -> {ok, + response(GOQ)} | + {error, GOR}. +try_map(Response, Transform) -> + gleam@result:then( + Transform(erlang:element(4, Response)), + fun(Body) -> {ok, set_body(Response, Body)} end + ). + +-spec map(response(GPM), fun((GPM) -> GPO)) -> response(GPO). +map(Response, Transform) -> + _pipe = erlang:element(4, Response), + _pipe@1 = Transform(_pipe), + set_body(Response, _pipe@1). + +-spec redirect(binary()) -> response(binary()). +redirect(Uri) -> + {response, + 303, + [{<<"location"/utf8>>, Uri}], + gleam@string:append(<<"You are being redirected to "/utf8>>, Uri)}. + +-spec get_cookies(response(any())) -> list({binary(), binary()}). +get_cookies(Resp) -> + {response, _, Headers, _} = Resp, + _pipe = Headers, + _pipe@1 = gleam@list:filter_map( + _pipe, + fun(Header) -> + {Name, Value} = Header, + case Name of + <<"set-cookie"/utf8>> -> + {ok, gleam@http@cookie:parse(Value)}; + + _ -> + {error, nil} + end + end + ), + gleam@list:flatten(_pipe@1). + +-spec set_cookie( + response(GPT), + binary(), + binary(), + gleam@http@cookie:attributes() +) -> response(GPT). +set_cookie(Response, Name, Value, Attributes) -> + prepend_header( + Response, + <<"set-cookie"/utf8>>, + gleam@http@cookie:set_header(Name, Value, Attributes) + ). + +-spec expire_cookie(response(GPW), binary(), gleam@http@cookie:attributes()) -> response(GPW). +expire_cookie(Response, Name, Attributes) -> + Attrs = erlang:setelement(2, Attributes, {some, 0}), + set_cookie(Response, Name, <<""/utf8>>, Attrs). diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache Binary files differnew file mode 100644 index 0000000..3c1fcc1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache_meta b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache_meta Binary files differnew file mode 100644 index 0000000..c0222d6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.erl new file mode 100644 index 0000000..3b4a425 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam@http@service.erl @@ -0,0 +1,82 @@ +-module(gleam@http@service). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([map_response_body/2, prepend_response_header/3, method_override/1]). + +-spec map_response_body( + fun((gleam@http@request:request(GSL)) -> gleam@http@response:response(GSM)), + fun((GSM) -> GSP) +) -> fun((gleam@http@request:request(GSL)) -> gleam@http@response:response(GSP)). +map_response_body(Service, Mapper) -> + fun(Req) -> _pipe = Req, + _pipe@1 = Service(_pipe), + gleam@http@response:map(_pipe@1, Mapper) end. + +-spec prepend_response_header( + fun((gleam@http@request:request(GSS)) -> gleam@http@response:response(GST)), + binary(), + binary() +) -> fun((gleam@http@request:request(GSS)) -> gleam@http@response:response(GST)). +prepend_response_header(Service, Key, Value) -> + fun(Req) -> _pipe = Req, + _pipe@1 = Service(_pipe), + gleam@http@response:prepend_header(_pipe@1, Key, Value) end. + +-spec ensure_post(gleam@http@request:request(GSY)) -> {ok, + gleam@http@request:request(GSY)} | + {error, nil}. +ensure_post(Req) -> + case erlang:element(2, Req) of + post -> + {ok, Req}; + + _ -> + {error, nil} + end. + +-spec get_override_method(gleam@http@request:request(any())) -> {ok, + gleam@http:method()} | + {error, nil}. +get_override_method(Request) -> + gleam@result:then( + gleam@http@request:get_query(Request), + fun(Query_params) -> + gleam@result:then( + gleam@list:key_find(Query_params, <<"_method"/utf8>>), + fun(Method) -> + gleam@result:then( + gleam@http:parse_method(Method), + fun(Method@1) -> case Method@1 of + put -> + {ok, Method@1}; + + patch -> + {ok, Method@1}; + + delete -> + {ok, Method@1}; + + _ -> + {error, nil} + end end + ) + end + ) + end + ). + +-spec method_override( + fun((gleam@http@request:request(GTF)) -> gleam@http@response:response(GTG)) +) -> fun((gleam@http@request:request(GTF)) -> gleam@http@response:response(GTG)). +method_override(Service) -> + fun(Request) -> _pipe = Request, + _pipe@1 = ensure_post(_pipe), + _pipe@2 = gleam@result:then(_pipe@1, fun get_override_method/1), + _pipe@3 = gleam@result:map( + _pipe@2, + fun(_capture) -> + gleam@http@request:set_method(Request, _capture) + end + ), + _pipe@4 = gleam@result:unwrap(_pipe@3, Request), + Service(_pipe@4) end. diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.erl b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.erl new file mode 100644 index 0000000..bb499bb --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.erl @@ -0,0 +1,88 @@ +-module(gleam_http_native). +-export([decode_method/1]). + +decode_method(Term) -> + case Term of + "connect" -> {ok, connect}; + "delete" -> {ok, delete}; + "get" -> {ok, get}; + "head" -> {ok, head}; + "options" -> {ok, options}; + "patch" -> {ok, patch}; + "post" -> {ok, post}; + "put" -> {ok, put}; + "trace" -> {ok, trace}; + "CONNECT" -> {ok, connect}; + "DELETE" -> {ok, delete}; + "GET" -> {ok, get}; + "HEAD" -> {ok, head}; + "OPTIONS" -> {ok, options}; + "PATCH" -> {ok, patch}; + "POST" -> {ok, post}; + "PUT" -> {ok, put}; + "TRACE" -> {ok, trace}; + "Connect" -> {ok, connect}; + "Delete" -> {ok, delete}; + "Get" -> {ok, get}; + "Head" -> {ok, head}; + "Options" -> {ok, options}; + "Patch" -> {ok, patch}; + "Post" -> {ok, post}; + "Put" -> {ok, put}; + "Trace" -> {ok, trace}; + 'connect' -> {ok, connect}; + 'delete' -> {ok, delete}; + 'get' -> {ok, get}; + 'head' -> {ok, head}; + 'options' -> {ok, options}; + 'patch' -> {ok, patch}; + 'post' -> {ok, post}; + 'put' -> {ok, put}; + 'trace' -> {ok, trace}; + 'CONNECT' -> {ok, connect}; + 'DELETE' -> {ok, delete}; + 'GET' -> {ok, get}; + 'HEAD' -> {ok, head}; + 'OPTIONS' -> {ok, options}; + 'PATCH' -> {ok, patch}; + 'POST' -> {ok, post}; + 'PUT' -> {ok, put}; + 'TRACE' -> {ok, trace}; + 'Connect' -> {ok, connect}; + 'Delete' -> {ok, delete}; + 'Get' -> {ok, get}; + 'Head' -> {ok, head}; + 'Options' -> {ok, options}; + 'Patch' -> {ok, patch}; + 'Post' -> {ok, post}; + 'Put' -> {ok, put}; + 'Trace' -> {ok, trace}; + <<"connect">> -> {ok, connect}; + <<"delete">> -> {ok, delete}; + <<"get">> -> {ok, get}; + <<"head">> -> {ok, head}; + <<"options">> -> {ok, options}; + <<"patch">> -> {ok, patch}; + <<"post">> -> {ok, post}; + <<"put">> -> {ok, put}; + <<"trace">> -> {ok, trace}; + <<"CONNECT">> -> {ok, connect}; + <<"DELETE">> -> {ok, delete}; + <<"GET">> -> {ok, get}; + <<"HEAD">> -> {ok, head}; + <<"OPTIONS">> -> {ok, options}; + <<"PATCH">> -> {ok, patch}; + <<"POST">> -> {ok, post}; + <<"PUT">> -> {ok, put}; + <<"TRACE">> -> {ok, trace}; + <<"Connect">> -> {ok, connect}; + <<"Delete">> -> {ok, delete}; + <<"Get">> -> {ok, get}; + <<"Head">> -> {ok, head}; + <<"Options">> -> {ok, options}; + <<"Patch">> -> {ok, patch}; + <<"Post">> -> {ok, post}; + <<"Put">> -> {ok, put}; + <<"Trace">> -> {ok, trace}; + _ -> {error, nil} + end. diff --git a/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.mjs b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.mjs new file mode 100644 index 0000000..c871a8b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/_gleam_artefacts/gleam_http_native.mjs @@ -0,0 +1,38 @@ +import { Ok, Error } from "./gleam.mjs"; +import { + Get, + Post, + Head, + Put, + Delete, + Trace, + Connect, + Options, + Patch, +} from "./gleam/http.mjs"; + +export function decode_method(value) { + try { + switch (value.toLowerCase()) { + case "get": + return new Ok(new Get()); + case "post": + return new Ok(new Post()); + case "head": + return new Ok(new Head()); + case "put": + return new Ok(new Put()); + case "delete": + return new Ok(new Delete()); + case "trace": + return new Ok(new Trace()); + case "connect": + return new Ok(new Connect()); + case "options": + return new Ok(new Options()); + case "patch": + return new Ok(new Patch()); + } + } catch {} + return new Error(undefined); +} diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http.beam Binary files differnew file mode 100644 index 0000000..1d6dab6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@cookie.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@cookie.beam Binary files differnew file mode 100644 index 0000000..0e9882c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@cookie.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@request.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@request.beam Binary files differnew file mode 100644 index 0000000..ef3cd15 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@request.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@response.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@response.beam Binary files differnew file mode 100644 index 0000000..a5a1f4c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@response.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@service.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@service.beam Binary files differnew file mode 100644 index 0000000..09e3162 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam@http@service.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http.app b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http.app new file mode 100644 index 0000000..5f55c6f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http.app @@ -0,0 +1,7 @@ +{application, gleam_http, [ + {vsn, "3.5.2"}, + {applications, [gleam_stdlib]}, + {description, "Types and functions for Gleam HTTP clients and servers"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http_native.beam b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http_native.beam Binary files differnew file mode 100644 index 0000000..b69ece0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/ebin/gleam_http_native.beam diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@cookie_Attributes.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@cookie_Attributes.hrl new file mode 100644 index 0000000..78a7d02 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@cookie_Attributes.hrl @@ -0,0 +1,8 @@ +-record(attributes, { + max_age :: gleam@option:option(integer()), + domain :: gleam@option:option(binary()), + path :: gleam@option:option(binary()), + secure :: boolean(), + http_only :: boolean(), + same_site :: gleam@option:option(gleam@http@cookie:same_site_policy()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@request_Request.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@request_Request.hrl new file mode 100644 index 0000000..c8bbae6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@request_Request.hrl @@ -0,0 +1,10 @@ +-record(request, { + method :: gleam@http:method(), + headers :: list({binary(), binary()}), + body :: any(), + scheme :: gleam@http:scheme(), + host :: binary(), + port :: gleam@option:option(integer()), + path :: binary(), + 'query' :: gleam@option:option(binary()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@response_Response.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@response_Response.hrl new file mode 100644 index 0000000..ba6f077 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http@response_Response.hrl @@ -0,0 +1,5 @@ +-record(response, { + status :: integer(), + headers :: list({binary(), binary()}), + body :: any() +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForBody.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForBody.hrl new file mode 100644 index 0000000..abd56dd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForBody.hrl @@ -0,0 +1,5 @@ +-record(more_required_for_body, { + chunk :: bitstring(), + continuation :: fun((bitstring()) -> {ok, gleam@http:multipart_body()} | + {error, nil}) +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForHeaders.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForHeaders.hrl new file mode 100644 index 0000000..43729c1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MoreRequiredForHeaders.hrl @@ -0,0 +1,4 @@ +-record(more_required_for_headers, { + continuation :: fun((bitstring()) -> {ok, gleam@http:multipart_headers()} | + {error, nil}) +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartBody.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartBody.hrl new file mode 100644 index 0000000..4521591 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartBody.hrl @@ -0,0 +1,5 @@ +-record(multipart_body, { + chunk :: bitstring(), + done :: boolean(), + remaining :: bitstring() +}). diff --git a/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartHeaders.hrl b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartHeaders.hrl new file mode 100644 index 0000000..d9fca5c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_http/include/gleam@http_MultipartHeaders.hrl @@ -0,0 +1,4 @@ +-record(multipart_headers, { + headers :: list({binary(), binary()}), + remaining :: bitstring() +}). diff --git a/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache Binary files differnew file mode 100644 index 0000000..84e8417 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache diff --git a/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache_meta b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache_meta Binary files differnew file mode 100644 index 0000000..a340156 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.erl b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.erl new file mode 100644 index 0000000..4629ee6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/_gleam_artefacts/gleam@httpc.erl @@ -0,0 +1,118 @@ +-module(gleam@httpc). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([send_bits/1, send/1]). +-export_type([charlist/0, erl_http_option/0, body_format/0, erl_option/0]). + +-type charlist() :: any(). + +-type erl_http_option() :: any(). + +-type body_format() :: binary. + +-type erl_option() :: {body_format, body_format()}. + +-spec charlist_header({binary(), binary()}) -> {charlist(), charlist()}. +charlist_header(Header) -> + {K, V} = Header, + {erlang:binary_to_list(K), erlang:binary_to_list(V)}. + +-spec string_header({charlist(), charlist()}) -> {binary(), binary()}. +string_header(Header) -> + {K, V} = Header, + {erlang:list_to_binary(K), erlang:list_to_binary(V)}. + +-spec send_bits(gleam@http@request:request(bitstring())) -> {ok, + gleam@http@response:response(bitstring())} | + {error, gleam@dynamic:dynamic_()}. +send_bits(Req) -> + Erl_url = begin + _pipe = Req, + _pipe@1 = gleam@http@request:to_uri(_pipe), + _pipe@2 = gleam@uri:to_string(_pipe@1), + erlang:binary_to_list(_pipe@2) + end, + Erl_headers = gleam@list:map(erlang:element(3, Req), fun charlist_header/1), + Erl_http_options = [], + Erl_options = [{body_format, binary}], + gleam@result:then(case erlang:element(2, Req) of + options -> + Erl_req = {Erl_url, Erl_headers}, + httpc:request( + erlang:element(2, Req), + Erl_req, + Erl_http_options, + Erl_options + ); + + head -> + Erl_req = {Erl_url, Erl_headers}, + httpc:request( + erlang:element(2, Req), + Erl_req, + Erl_http_options, + Erl_options + ); + + get -> + Erl_req = {Erl_url, Erl_headers}, + httpc:request( + erlang:element(2, Req), + Erl_req, + Erl_http_options, + Erl_options + ); + + _ -> + Erl_content_type = begin + _pipe@3 = Req, + _pipe@4 = gleam@http@request:get_header( + _pipe@3, + <<"content-type"/utf8>> + ), + _pipe@5 = gleam@result:unwrap( + _pipe@4, + <<"application/octet-stream"/utf8>> + ), + erlang:binary_to_list(_pipe@5) + end, + Erl_req@1 = {Erl_url, + Erl_headers, + Erl_content_type, + erlang:element(4, Req)}, + httpc:request( + erlang:element(2, Req), + Erl_req@1, + Erl_http_options, + Erl_options + ) + end, fun(Response) -> + {{_, Status, _}, Headers, Resp_body} = Response, + {ok, + {response, + Status, + gleam@list:map(Headers, fun string_header/1), + Resp_body}} + end). + +-spec send(gleam@http@request:request(binary())) -> {ok, + gleam@http@response:response(binary())} | + {error, gleam@dynamic:dynamic_()}. +send(Req) -> + gleam@result:then( + begin + _pipe = Req, + _pipe@1 = gleam@http@request:map(_pipe, fun gleam_stdlib:identity/1), + send_bits(_pipe@1) + end, + fun(Resp) -> case gleam@bit_array:to_string(erlang:element(4, Resp)) of + {ok, Body} -> + {ok, gleam@http@response:set_body(Resp, Body)}; + + {error, _} -> + {error, + gleam@dynamic:from( + <<"Response body was not valid UTF-8"/utf8>> + )} + end end + ). diff --git a/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam@httpc.beam b/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam@httpc.beam Binary files differnew file mode 100644 index 0000000..d4f3782 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam@httpc.beam diff --git a/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam_httpc.app b/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam_httpc.app new file mode 100644 index 0000000..c99b5ea --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_httpc/ebin/gleam_httpc.app @@ -0,0 +1,10 @@ +{application, gleam_httpc, [ + {vsn, "2.1.1"}, + {applications, [gleam_http, + gleam_stdlib, + inets, + ssl]}, + {description, "Gleam bindings to Erlang's built in HTTP client, httpc"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache Binary files differnew file mode 100644 index 0000000..df2a9bd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache_meta Binary files differnew file mode 100644 index 0000000..d5f2a3e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.erl new file mode 100644 index 0000000..2002046 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.erl @@ -0,0 +1,273 @@ +-module(gleam@otp@actor). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([continue/1, with_selector/2, to_erlang_start_result/1, start_spec/1, start/2, send/2, call/3]). +-export_type([message/1, next/2, init_result/2, self/2, spec/2, start_error/0, start_init_message/1]). + +-type message(HLY) :: {message, HLY} | + {system, gleam@otp@system:system_message()} | + {unexpected, gleam@dynamic:dynamic_()}. + +-type next(HLZ, HMA) :: {continue, + HMA, + gleam@option:option(gleam@erlang@process:selector(HLZ))} | + {stop, gleam@erlang@process:exit_reason()}. + +-type init_result(HMB, HMC) :: {ready, HMB, gleam@erlang@process:selector(HMC)} | + {failed, binary()}. + +-type self(HMD, HME) :: {self, + gleam@otp@system:mode(), + gleam@erlang@process:pid_(), + HMD, + gleam@erlang@process:subject(HME), + gleam@erlang@process:selector(message(HME)), + gleam@otp@system:debug_state(), + fun((HME, HMD) -> next(HME, HMD))}. + +-type spec(HMF, HMG) :: {spec, + fun(() -> init_result(HMF, HMG)), + integer(), + fun((HMG, HMF) -> next(HMG, HMF))}. + +-type start_error() :: init_timeout | + {init_failed, gleam@erlang@process:exit_reason()} | + {init_crashed, gleam@dynamic:dynamic_()}. + +-type start_init_message(HMH) :: {ack, + {ok, gleam@erlang@process:subject(HMH)} | + {error, gleam@erlang@process:exit_reason()}} | + {mon, gleam@erlang@process:process_down()}. + +-spec continue(HMO) -> next(any(), HMO). +continue(State) -> + {continue, State, none}. + +-spec with_selector(next(HMS, HMT), gleam@erlang@process:selector(HMS)) -> next(HMS, HMT). +with_selector(Value, Selector) -> + case Value of + {continue, State, _} -> + {continue, State, {some, Selector}}; + + _ -> + Value + end. + +-spec exit_process(gleam@erlang@process:exit_reason()) -> gleam@erlang@process:exit_reason(). +exit_process(Reason) -> + Reason. + +-spec selecting_system_messages(gleam@erlang@process:selector(message(HNE))) -> gleam@erlang@process:selector(message(HNE)). +selecting_system_messages(Selector) -> + _pipe = Selector, + gleam@erlang@process:selecting_record3( + _pipe, + erlang:binary_to_atom(<<"system"/utf8>>), + fun gleam_otp_external:convert_system_message/2 + ). + +-spec receive_message(self(any(), HNA)) -> message(HNA). +receive_message(Self) -> + Selector = case erlang:element(2, Self) of + suspended -> + _pipe = gleam_erlang_ffi:new_selector(), + selecting_system_messages(_pipe); + + running -> + _pipe@1 = gleam_erlang_ffi:new_selector(), + _pipe@2 = gleam@erlang@process:selecting_anything( + _pipe@1, + fun(Field@0) -> {unexpected, Field@0} end + ), + _pipe@3 = gleam_erlang_ffi:merge_selector( + _pipe@2, + erlang:element(6, Self) + ), + selecting_system_messages(_pipe@3) + end, + gleam_erlang_ffi:select(Selector). + +-spec process_status_info(self(any(), any())) -> gleam@otp@system:status_info(). +process_status_info(Self) -> + {status_info, + erlang:binary_to_atom(<<"gleam@otp@actor"/utf8>>), + erlang:element(3, Self), + erlang:element(2, Self), + erlang:element(7, Self), + gleam@dynamic:from(erlang:element(4, Self))}. + +-spec init_selector( + gleam@erlang@process:subject(HRT), + gleam@erlang@process:selector(HRT) +) -> gleam@erlang@process:selector(message(HRT)). +init_selector(Subject, Selector) -> + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = gleam@erlang@process:selecting( + _pipe, + Subject, + fun(Field@0) -> {message, Field@0} end + ), + gleam_erlang_ffi:merge_selector( + _pipe@1, + gleam_erlang_ffi:map_selector( + Selector, + fun(Field@0) -> {message, Field@0} end + ) + ). + +-spec loop(self(any(), any())) -> gleam@erlang@process:exit_reason(). +loop(Self) -> + case receive_message(Self) of + {system, System} -> + case System of + {get_state, Callback} -> + Callback(gleam@dynamic:from(erlang:element(4, Self))), + loop(Self); + + {resume, Callback@1} -> + Callback@1(), + loop(erlang:setelement(2, Self, running)); + + {suspend, Callback@2} -> + Callback@2(), + loop(erlang:setelement(2, Self, suspended)); + + {get_status, Callback@3} -> + Callback@3(process_status_info(Self)), + loop(Self) + end; + + {unexpected, Message} -> + logger:warning( + unicode:characters_to_list( + <<"Actor discarding unexpected message: ~s"/utf8>> + ), + [unicode:characters_to_list(gleam@string:inspect(Message))] + ), + loop(Self); + + {message, Msg} -> + case (erlang:element(8, Self))(Msg, erlang:element(4, Self)) of + {stop, Reason} -> + exit_process(Reason); + + {continue, State, New_selector} -> + Selector = begin + _pipe = New_selector, + _pipe@1 = gleam@option:map( + _pipe, + fun(_capture) -> + init_selector(erlang:element(5, Self), _capture) + end + ), + gleam@option:unwrap(_pipe@1, erlang:element(6, Self)) + end, + loop( + erlang:setelement( + 6, + erlang:setelement(4, Self, State), + Selector + ) + ) + end + end. + +-spec initialise_actor( + spec(any(), HNV), + gleam@erlang@process:subject({ok, gleam@erlang@process:subject(HNV)} | + {error, gleam@erlang@process:exit_reason()}) +) -> gleam@erlang@process:exit_reason(). +initialise_actor(Spec, Ack) -> + Subject = gleam@erlang@process:new_subject(), + case (erlang:element(2, Spec))() of + {ready, State, Selector} -> + Selector@1 = init_selector(Subject, Selector), + gleam@erlang@process:send(Ack, {ok, Subject}), + Self = {self, + running, + gleam@erlang@process:subject_owner(Ack), + State, + Subject, + Selector@1, + sys:debug_options([]), + erlang:element(4, Spec)}, + loop(Self); + + {failed, Reason} -> + gleam@erlang@process:send(Ack, {error, {abnormal, Reason}}), + exit_process({abnormal, Reason}) + end. + +-spec to_erlang_start_result( + {ok, gleam@erlang@process:subject(any())} | {error, start_error()} +) -> {ok, gleam@erlang@process:pid_()} | {error, gleam@dynamic:dynamic_()}. +to_erlang_start_result(Res) -> + case Res of + {ok, X} -> + {ok, gleam@erlang@process:subject_owner(X)}; + + {error, X@1} -> + {error, gleam@dynamic:from(X@1)} + end. + +-spec start_spec(spec(any(), HOJ)) -> {ok, gleam@erlang@process:subject(HOJ)} | + {error, start_error()}. +start_spec(Spec) -> + Ack_subject = gleam@erlang@process:new_subject(), + Child = gleam@erlang@process:start( + fun() -> initialise_actor(Spec, Ack_subject) end, + true + ), + Monitor = gleam@erlang@process:monitor_process(Child), + Selector = begin + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = gleam@erlang@process:selecting( + _pipe, + Ack_subject, + fun(Field@0) -> {ack, Field@0} end + ), + gleam@erlang@process:selecting_process_down( + _pipe@1, + Monitor, + fun(Field@0) -> {mon, Field@0} end + ) + end, + Result = case gleam_erlang_ffi:select(Selector, erlang:element(3, Spec)) of + {ok, {ack, {ok, Channel}}} -> + {ok, Channel}; + + {ok, {ack, {error, Reason}}} -> + {error, {init_failed, Reason}}; + + {ok, {mon, Down}} -> + {error, {init_crashed, erlang:element(3, Down)}}; + + {error, nil} -> + gleam@erlang@process:kill(Child), + {error, init_timeout} + end, + gleam_erlang_ffi:demonitor(Monitor), + Result. + +-spec start(HOP, fun((HOQ, HOP) -> next(HOQ, HOP))) -> {ok, + gleam@erlang@process:subject(HOQ)} | + {error, start_error()}. +start(State, Loop) -> + start_spec( + {spec, + fun() -> {ready, State, gleam_erlang_ffi:new_selector()} end, + 5000, + Loop} + ). + +-spec send(gleam@erlang@process:subject(HOW), HOW) -> nil. +send(Subject, Msg) -> + gleam@erlang@process:send(Subject, Msg). + +-spec call( + gleam@erlang@process:subject(HOY), + fun((gleam@erlang@process:subject(HPA)) -> HOY), + integer() +) -> HPA. +call(Selector, Make_message, Timeout) -> + gleam@erlang@process:call(Selector, Make_message, Timeout). diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache Binary files differnew file mode 100644 index 0000000..a2cc755 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache_meta Binary files differnew file mode 100644 index 0000000..1997b5a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.erl new file mode 100644 index 0000000..716078f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@intensity_tracker.erl @@ -0,0 +1,53 @@ +-module(gleam@otp@intensity_tracker). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/2, trim_window/3, add_event/1]). +-export_type([intensity_tracker/0, too_intense/0]). + +-opaque intensity_tracker() :: {intensity_tracker, + integer(), + integer(), + list(integer())}. + +-type too_intense() :: too_intense. + +-spec new(integer(), integer()) -> intensity_tracker(). +new(Limit, Period) -> + {intensity_tracker, Limit, Period, []}. + +-spec now_seconds() -> integer(). +now_seconds() -> + erlang:monotonic_time(1). + +-spec trim_window(list(integer()), integer(), integer()) -> list(integer()). +trim_window(Events, Now, Period) -> + case Events of + [] -> + []; + + [Event | Events@1] -> + case Now >= (Event + Period) of + true -> + [Event | trim_window(Events@1, Now, Period)]; + + false -> + [] + end + end. + +-spec add_event(intensity_tracker()) -> {ok, intensity_tracker()} | + {error, too_intense()}. +add_event(Tracker) -> + Now = now_seconds(), + Events = trim_window( + [Now | erlang:element(4, Tracker)], + Now, + erlang:element(3, Tracker) + ), + case gleam@list:length(Events) >= erlang:element(2, Tracker) of + true -> + {error, too_intense}; + + false -> + {ok, erlang:setelement(4, Tracker, Events)} + end. diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache Binary files differnew file mode 100644 index 0000000..a05f0e2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache_meta Binary files differnew file mode 100644 index 0000000..5f1cb59 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.erl new file mode 100644 index 0000000..9bad092 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@port.erl @@ -0,0 +1,8 @@ +-module(gleam@otp@port). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export_type([port_/0]). + +-type port_() :: any(). + + diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache Binary files differnew file mode 100644 index 0000000..2b4bef1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache_meta Binary files differnew file mode 100644 index 0000000..f6f257e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.erl new file mode 100644 index 0000000..bb07432 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@supervisor.erl @@ -0,0 +1,322 @@ +-module(gleam@otp@supervisor). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([add/2, supervisor/1, worker/1, returning/2, start_spec/1, start/1, application_stopped/0, to_erlang_start_result/1]). +-export_type([spec/2, children/1, child_spec/3, child_start_error/0, message/0, instruction/0, state/1, starter/1, child/1, handle_exit_error/0, application_start_mode/0, application_stop/0]). + +-type spec(HXT, HXU) :: {spec, + HXT, + integer(), + integer(), + fun((children(HXT)) -> children(HXU))}. + +-opaque children(HXV) :: {ready, starter(HXV)} | {failed, child_start_error()}. + +-opaque child_spec(HXW, HXX, HXY) :: {child_spec, + fun((HXX) -> {ok, gleam@erlang@process:subject(HXW)} | + {error, gleam@otp@actor:start_error()}), + fun((HXX, gleam@erlang@process:subject(HXW)) -> HXY)}. + +-type child_start_error() :: {child_start_error, + gleam@option:option(gleam@erlang@process:pid_()), + gleam@otp@actor:start_error()}. + +-opaque message() :: {exit, gleam@erlang@process:exit_message()} | + {retry_restart, gleam@erlang@process:pid_()}. + +-type instruction() :: start_all | {start_from, gleam@erlang@process:pid_()}. + +-type state(HXZ) :: {state, + gleam@otp@intensity_tracker:intensity_tracker(), + starter(HXZ), + gleam@erlang@process:subject(gleam@erlang@process:pid_())}. + +-type starter(HYA) :: {starter, + HYA, + gleam@option:option(fun((instruction()) -> {ok, + {starter(HYA), instruction()}} | + {error, child_start_error()}))}. + +-type child(HYB) :: {child, gleam@erlang@process:pid_(), HYB}. + +-type handle_exit_error() :: {restart_failed, + gleam@erlang@process:pid_(), + gleam@otp@intensity_tracker:intensity_tracker()} | + too_many_restarts. + +-type application_start_mode() :: normal | + {takeover, gleam@erlang@node:node_()} | + {failover, gleam@erlang@node:node_()}. + +-type application_stop() :: any(). + +-spec start_child(child_spec(any(), HYF, HYG), HYF) -> {ok, child(HYG)} | + {error, child_start_error()}. +start_child(Child_spec, Argument) -> + gleam@result:then( + begin + _pipe = (erlang:element(2, Child_spec))(Argument), + gleam@result:map_error( + _pipe, + fun(_capture) -> {child_start_error, none, _capture} end + ) + end, + fun(Subject) -> + {ok, + {child, + gleam@erlang@process:subject_owner(Subject), + (erlang:element(3, Child_spec))(Argument, Subject)}} + end + ). + +-spec shutdown_child( + gleam@erlang@process:pid_(), + child_spec(any(), any(), any()) +) -> nil. +shutdown_child(Pid, _) -> + gleam@erlang@process:send_exit(Pid). + +-spec perform_instruction_for_child( + HYT, + instruction(), + child_spec(any(), HYT, HYV), + child(HYV) +) -> {ok, {child(HYV), instruction()}} | {error, child_start_error()}. +perform_instruction_for_child(Argument, Instruction, Child_spec, Child) -> + Current = erlang:element(2, Child), + case Instruction of + {start_from, Target} when Target =/= Current -> + {ok, {Child, Instruction}}; + + _ -> + shutdown_child(Current, Child_spec), + gleam@result:then( + start_child(Child_spec, Argument), + fun(Child@1) -> {ok, {Child@1, start_all}} end + ) + end. + +-spec add_child_to_starter( + starter(HZD), + child_spec(any(), HZD, HZG), + child(HZG) +) -> starter(HZG). +add_child_to_starter(Starter, Child_spec, Child) -> + Starter@3 = fun(Instruction) -> + gleam@result:then(case erlang:element(3, Starter) of + {some, Start} -> + Start(Instruction); + + none -> + {ok, {Starter, Instruction}} + end, fun(_use0) -> + {Starter@1, Instruction@1} = _use0, + gleam@result:then( + perform_instruction_for_child( + erlang:element(2, Starter@1), + Instruction@1, + Child_spec, + Child + ), + fun(_use0@1) -> + {Child@1, Instruction@2} = _use0@1, + Starter@2 = add_child_to_starter( + Starter@1, + Child_spec, + Child@1 + ), + {ok, {Starter@2, Instruction@2}} + end + ) + end) + end, + {starter, erlang:element(3, Child), {some, Starter@3}}. + +-spec start_and_add_child(starter(HZM), child_spec(any(), HZM, HZP)) -> children(HZP). +start_and_add_child(State, Child_spec) -> + case start_child(Child_spec, erlang:element(2, State)) of + {ok, Child} -> + {ready, add_child_to_starter(State, Child_spec, Child)}; + + {error, Reason} -> + {failed, Reason} + end. + +-spec add(children(HZU), child_spec(any(), HZU, HZX)) -> children(HZX). +add(Children, Child_spec) -> + case Children of + {failed, Fail} -> + {failed, Fail}; + + {ready, State} -> + start_and_add_child(State, Child_spec) + end. + +-spec supervisor( + fun((IAC) -> {ok, gleam@erlang@process:subject(IAD)} | + {error, gleam@otp@actor:start_error()}) +) -> child_spec(IAD, IAC, IAC). +supervisor(Start) -> + {child_spec, Start, fun(Argument, _) -> Argument end}. + +-spec worker( + fun((IAK) -> {ok, gleam@erlang@process:subject(IAL)} | + {error, gleam@otp@actor:start_error()}) +) -> child_spec(IAL, IAK, IAK). +worker(Start) -> + {child_spec, Start, fun(Argument, _) -> Argument end}. + +-spec returning( + child_spec(IAS, IAT, any()), + fun((IAT, gleam@erlang@process:subject(IAS)) -> IAZ) +) -> child_spec(IAS, IAT, IAZ). +returning(Child, Updater) -> + {child_spec, erlang:element(2, Child), Updater}. + +-spec init(spec(any(), IBE)) -> gleam@otp@actor:init_result(state(IBE), message()). +init(Spec) -> + Retry = gleam@erlang@process:new_subject(), + gleam_erlang_ffi:trap_exits(true), + Selector = begin + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = gleam@erlang@process:selecting( + _pipe, + Retry, + fun(Field@0) -> {retry_restart, Field@0} end + ), + gleam@erlang@process:selecting_trapped_exits( + _pipe@1, + fun(Field@0) -> {exit, Field@0} end + ) + end, + Result = begin + _pipe@2 = {starter, erlang:element(2, Spec), none}, + _pipe@3 = {ready, _pipe@2}, + (erlang:element(5, Spec))(_pipe@3) + end, + case Result of + {ready, Starter} -> + Restarts = gleam@otp@intensity_tracker:new( + erlang:element(3, Spec), + erlang:element(4, Spec) + ), + State = {state, Restarts, Starter, Retry}, + {ready, State, Selector}; + + {failed, Error} -> + {failed, case erlang:element(3, Error) of + init_timeout -> + <<"Child initialisation timed out"/utf8>>; + + {init_crashed, Reason} -> + gleam@string:append( + <<"Child crashed during initialisation: "/utf8>>, + gleam@string:inspect(Reason) + ); + + {init_failed, Reason@1} -> + gleam@string:append( + <<"Child failed to start during initialisation: "/utf8>>, + gleam@string:inspect(Reason@1) + ) + end} + end. + +-spec handle_exit(gleam@erlang@process:pid_(), state(IBK)) -> gleam@otp@actor:next(message(), state(IBK)). +handle_exit(Pid, State) -> + Outcome = begin + _assert_subject = erlang:element(3, erlang:element(3, State)), + {some, Start} = case _assert_subject of + {some, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam/otp/supervisor"/utf8>>, + function => <<"handle_exit"/utf8>>, + line => 293}) + end, + gleam@result:then( + begin + _pipe = erlang:element(2, State), + _pipe@1 = gleam@otp@intensity_tracker:add_event(_pipe), + gleam@result:map_error(_pipe@1, fun(_) -> too_many_restarts end) + end, + fun(Restarts) -> + gleam@result:then( + begin + _pipe@2 = Start({start_from, Pid}), + gleam@result:map_error( + _pipe@2, + fun(E) -> + {restart_failed, + gleam@option:unwrap( + erlang:element(2, E), + Pid + ), + Restarts} + end + ) + end, + fun(_use0) -> + {Starter, _} = _use0, + {ok, + erlang:setelement( + 2, + erlang:setelement(3, State, Starter), + Restarts + )} + end + ) + end + ) + end, + case Outcome of + {ok, State@1} -> + gleam@otp@actor:continue(State@1); + + {error, {restart_failed, Failed_child, Restarts@1}} -> + gleam@erlang@process:send(erlang:element(4, State), Failed_child), + State@2 = erlang:setelement(2, State, Restarts@1), + gleam@otp@actor:continue(State@2); + + {error, too_many_restarts} -> + {stop, + {abnormal, + <<"Child processes restarted too many times within allowed period"/utf8>>}} + end. + +-spec loop(message(), state(IBP)) -> gleam@otp@actor:next(message(), state(IBP)). +loop(Message, State) -> + case Message of + {exit, Exit_message} -> + handle_exit(erlang:element(2, Exit_message), State); + + {retry_restart, Pid} -> + handle_exit(Pid, State) + end. + +-spec start_spec(spec(any(), any())) -> {ok, + gleam@erlang@process:subject(message())} | + {error, gleam@otp@actor:start_error()}. +start_spec(Spec) -> + gleam@otp@actor:start_spec( + {spec, fun() -> init(Spec) end, 60000, fun loop/2} + ). + +-spec start(fun((children(nil)) -> children(any()))) -> {ok, + gleam@erlang@process:subject(message())} | + {error, gleam@otp@actor:start_error()}. +start(Init) -> + start_spec({spec, nil, 1, 5, Init}). + +-spec application_stopped() -> application_stop(). +application_stopped() -> + gleam_otp_external:application_stopped(). + +-spec to_erlang_start_result( + {ok, gleam@erlang@process:subject(any())} | + {error, gleam@otp@actor:start_error()} +) -> {ok, gleam@erlang@process:pid_()} | {error, gleam@dynamic:dynamic_()}. +to_erlang_start_result(Res) -> + gleam@otp@actor:to_erlang_start_result(Res). diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache Binary files differnew file mode 100644 index 0000000..c489047 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache_meta Binary files differnew file mode 100644 index 0000000..9f64041 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.erl new file mode 100644 index 0000000..d6c6bfc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@system.erl @@ -0,0 +1,43 @@ +-module(gleam@otp@system). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([debug_state/1, get_state/1, suspend/1, resume/1]). +-export_type([mode/0, debug_option/0, debug_state/0, status_info/0, system_message/0, do_not_leak/0]). + +-type mode() :: running | suspended. + +-type debug_option() :: no_debug. + +-type debug_state() :: any(). + +-type status_info() :: {status_info, + gleam@erlang@atom:atom_(), + gleam@erlang@process:pid_(), + mode(), + debug_state(), + gleam@dynamic:dynamic_()}. + +-type system_message() :: {resume, fun(() -> nil)} | + {suspend, fun(() -> nil)} | + {get_state, fun((gleam@dynamic:dynamic_()) -> nil)} | + {get_status, fun((status_info()) -> nil)}. + +-type do_not_leak() :: any(). + +-spec debug_state(list(debug_option())) -> debug_state(). +debug_state(A) -> + sys:debug_options(A). + +-spec get_state(gleam@erlang@process:pid_()) -> gleam@dynamic:dynamic_(). +get_state(From) -> + sys:get_state(From). + +-spec suspend(gleam@erlang@process:pid_()) -> nil. +suspend(Pid) -> + sys:suspend(Pid), + nil. + +-spec resume(gleam@erlang@process:pid_()) -> nil. +resume(Pid) -> + sys:resume(Pid), + nil. diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache Binary files differnew file mode 100644 index 0000000..b71f5ea --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache_meta Binary files differnew file mode 100644 index 0000000..e4f89cf --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.erl new file mode 100644 index 0000000..7cb0540 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@task.erl @@ -0,0 +1,111 @@ +-module(gleam@otp@task). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([async/1, try_await/2, await/2, try_await_forever/1, await_forever/1]). +-export_type([task/1, await_error/0, message/1]). + +-opaque task(IKP) :: {task, + gleam@erlang@process:pid_(), + gleam@erlang@process:pid_(), + gleam@erlang@process:process_monitor(), + gleam@erlang@process:selector(message(IKP))}. + +-type await_error() :: timeout | {exit, gleam@dynamic:dynamic_()}. + +-type message(IKQ) :: {from_monitor, gleam@erlang@process:process_down()} | + {from_subject, IKQ}. + +-spec async(fun(() -> IKR)) -> task(IKR). +async(Work) -> + Owner = erlang:self(), + Subject = gleam@erlang@process:new_subject(), + Pid = gleam@erlang@process:start( + fun() -> gleam@erlang@process:send(Subject, Work()) end, + true + ), + Monitor = gleam@erlang@process:monitor_process(Pid), + Selector = begin + _pipe = gleam_erlang_ffi:new_selector(), + _pipe@1 = gleam@erlang@process:selecting_process_down( + _pipe, + Monitor, + fun(Field@0) -> {from_monitor, Field@0} end + ), + gleam@erlang@process:selecting( + _pipe@1, + Subject, + fun(Field@0) -> {from_subject, Field@0} end + ) + end, + {task, Owner, Pid, Monitor, Selector}. + +-spec assert_owner(task(any())) -> nil. +assert_owner(Task) -> + Self = erlang:self(), + case erlang:element(2, Task) =:= Self of + true -> + nil; + + false -> + gleam@erlang@process:send_abnormal_exit( + Self, + <<"awaited on a task that does not belong to this process"/utf8>> + ) + end. + +-spec try_await(task(IKV), integer()) -> {ok, IKV} | {error, await_error()}. +try_await(Task, Timeout) -> + assert_owner(Task), + case gleam_erlang_ffi:select(erlang:element(5, Task), Timeout) of + {ok, {from_subject, X}} -> + gleam_erlang_ffi:demonitor(erlang:element(4, Task)), + {ok, X}; + + {ok, {from_monitor, {process_down, _, Reason}}} -> + {error, {exit, Reason}}; + + {error, nil} -> + {error, timeout} + end. + +-spec await(task(IKZ), integer()) -> IKZ. +await(Task, Timeout) -> + _assert_subject = try_await(Task, Timeout), + {ok, Value} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam/otp/task"/utf8>>, + function => <<"await"/utf8>>, + line => 117}) + end, + Value. + +-spec try_await_forever(task(ILB)) -> {ok, ILB} | {error, await_error()}. +try_await_forever(Task) -> + assert_owner(Task), + case gleam_erlang_ffi:select(erlang:element(5, Task)) of + {from_subject, X} -> + gleam_erlang_ffi:demonitor(erlang:element(4, Task)), + {ok, X}; + + {from_monitor, {process_down, _, Reason}} -> + {error, {exit, Reason}} + end. + +-spec await_forever(task(ILF)) -> ILF. +await_forever(Task) -> + _assert_subject = try_await_forever(Task), + {ok, Value} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"gleam/otp/task"/utf8>>, + function => <<"await_forever"/utf8>>, + line => 149}) + end, + Value. diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache Binary files differnew file mode 100644 index 0000000..61dea2d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache_meta b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache_meta Binary files differnew file mode 100644 index 0000000..6b7a3a8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.erl new file mode 100644 index 0000000..03ae419 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp.erl @@ -0,0 +1,28 @@ +-module(gleam_otp). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([main/0]). + +-spec spawn_task(integer()) -> gleam@otp@task:task(nil). +spawn_task(I) -> + gleam@otp@task:async(fun() -> case (I rem 500) =:= 0 of + true -> + gleam@io:println( + <<"Hello from "/utf8, (gleam@int:to_string(I))/binary>> + ); + + false -> + nil + end end). + +-spec main() -> integer(). +main() -> + gleam@io:debug( + gleam_otp_test_external:get_message_queue_length(erlang:self()) + ), + _pipe = gleam@list:range(0, 1000000), + _pipe@1 = gleam@list:map(_pipe, fun spawn_task/1), + gleam@list:each(_pipe@1, fun gleam@otp@task:await_forever/1), + gleam@io:debug( + gleam_otp_test_external:get_message_queue_length(erlang:self()) + ). diff --git a/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp_external.erl b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp_external.erl new file mode 100644 index 0000000..8910a67 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam_otp_external.erl @@ -0,0 +1,43 @@ +-module(gleam_otp_external). + +-export([application_stopped/0, convert_system_message/2]). + +% TODO: support other system messages +% {replace_state, StateFn} +% {change_code, Mod, Vsn, Extra} +% {terminate, Reason} +% {debug, {log, Flag}} +% {debug, {trace, Flag}} +% {debug, {log_to_file, FileName}} +% {debug, {statistics, Flag}} +% {debug, no_debug} +% {debug, {install, {Func, FuncState}}} +% {debug, {install, {FuncId, Func, FuncState}}} +% {debug, {remove, FuncOrId}} +% GetStatus(Subject(StatusInfo)) +convert_system_message({From, Ref}, Request) when is_pid(From) -> + Reply = fun(Msg) -> + erlang:send(From, {Ref, Msg}), + nil + end, + System = fun(Callback) -> + {system, {Request, Callback}} + end, + case Request of + get_status -> System(fun(Status) -> Reply(process_status(Status)) end); + get_state -> System(Reply); + suspend -> System(fun() -> Reply(ok) end); + resume -> System(fun() -> Reply(ok) end); + Other -> {unexpeceted, Other} + end. + +process_status({status_info, Module, Parent, Mode, DebugState, State}) -> + Data = [ + get(), Mode, Parent, DebugState, + [{header, "Status for Gleam process " ++ pid_to_list(self())}, + {data, [{'Status', Mode}, {'Parent', Parent}, {'State', State}]}] + ], + {status, self(), {module, Module}, Data}. + +application_stopped() -> + ok. diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@actor.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@actor.beam Binary files differnew file mode 100644 index 0000000..7d3fd3e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@actor.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@intensity_tracker.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@intensity_tracker.beam Binary files differnew file mode 100644 index 0000000..da2acd0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@intensity_tracker.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@port.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@port.beam Binary files differnew file mode 100644 index 0000000..a4a7340 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@port.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@supervisor.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@supervisor.beam Binary files differnew file mode 100644 index 0000000..181508d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@supervisor.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@system.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@system.beam Binary files differnew file mode 100644 index 0000000..30d4309 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@system.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@task.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@task.beam Binary files differnew file mode 100644 index 0000000..0f710a1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam@otp@task.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.app b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.app new file mode 100644 index 0000000..21dd444 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.app @@ -0,0 +1,8 @@ +{application, gleam_otp, [ + {vsn, "0.8.0"}, + {applications, [gleam_erlang, + gleam_stdlib]}, + {description, "Fault tolerant multicore Gleam programs with OTP"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.beam Binary files differnew file mode 100644 index 0000000..47eb31e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp_external.beam b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp_external.beam Binary files differnew file mode 100644 index 0000000..5ffaafd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/ebin/gleam_otp_external.beam diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Continue.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Continue.hrl new file mode 100644 index 0000000..85677d1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Continue.hrl @@ -0,0 +1,4 @@ +-record(continue, { + state :: any(), + selector :: gleam@option:option(gleam@erlang@process:selector(any())) +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Ready.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Ready.hrl new file mode 100644 index 0000000..75faa95 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Ready.hrl @@ -0,0 +1 @@ +-record(ready, {state :: any(), selector :: gleam@erlang@process:selector(any())}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Spec.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Spec.hrl new file mode 100644 index 0000000..5287439 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@actor_Spec.hrl @@ -0,0 +1,5 @@ +-record(spec, { + init :: fun(() -> gleam@otp@actor:init_result(any(), any())), + init_timeout :: integer(), + loop :: fun((any(), any()) -> gleam@otp@actor:next(any(), any())) +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@intensity_tracker_IntensityTracker.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@intensity_tracker_IntensityTracker.hrl new file mode 100644 index 0000000..3ed0b01 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@intensity_tracker_IntensityTracker.hrl @@ -0,0 +1,5 @@ +-record(intensity_tracker, { + limit :: integer(), + period :: integer(), + events :: list(integer()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_ChildSpec.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_ChildSpec.hrl new file mode 100644 index 0000000..7afd07f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_ChildSpec.hrl @@ -0,0 +1,5 @@ +-record(child_spec, { + start :: fun((any()) -> {ok, gleam@erlang@process:subject(any())} | + {error, gleam@otp@actor:start_error()}), + returning :: fun((any(), gleam@erlang@process:subject(any())) -> any()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_Spec.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_Spec.hrl new file mode 100644 index 0000000..b10bd9f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@supervisor_Spec.hrl @@ -0,0 +1,6 @@ +-record(spec, { + argument :: any(), + max_frequency :: integer(), + frequency_period :: integer(), + init :: fun((gleam@otp@supervisor:children(any())) -> gleam@otp@supervisor:children(any())) +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@system_StatusInfo.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@system_StatusInfo.hrl new file mode 100644 index 0000000..99ab4cb --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@system_StatusInfo.hrl @@ -0,0 +1,7 @@ +-record(status_info, { + module :: gleam@erlang@atom:atom_(), + parent :: gleam@erlang@process:pid_(), + mode :: gleam@otp@system:mode(), + debug_state :: gleam@otp@system:debug_state(), + state :: gleam@dynamic:dynamic_() +}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Exit.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Exit.hrl new file mode 100644 index 0000000..7c83874 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Exit.hrl @@ -0,0 +1 @@ +-record(exit, {reason :: gleam@dynamic:dynamic_()}). diff --git a/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Task.hrl b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Task.hrl new file mode 100644 index 0000000..959bea8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_otp/include/gleam@otp@task_Task.hrl @@ -0,0 +1,6 @@ +-record(task, { + owner :: gleam@erlang@process:pid_(), + pid :: gleam@erlang@process:pid_(), + monitor :: gleam@erlang@process:process_monitor(), + selector :: gleam@erlang@process:selector(gleam@otp@task:message(any())) +}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/dict.mjs b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/dict.mjs new file mode 100644 index 0000000..a8309e0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/dict.mjs @@ -0,0 +1,957 @@ +/** + * This file uses jsdoc to annotate types. + * These types can be checked using the typescript compiler with "checkjs" option. + */ + +import { isEqual } from "./gleam.mjs"; + +const referenceMap = new WeakMap(); +const tempDataView = new DataView(new ArrayBuffer(8)); +let referenceUID = 0; +/** + * hash the object by reference using a weak map and incrementing uid + * @param {any} o + * @returns {number} + */ +function hashByReference(o) { + const known = referenceMap.get(o); + if (known !== undefined) { + return known; + } + const hash = referenceUID++; + if (referenceUID === 0x7fffffff) { + referenceUID = 0; + } + referenceMap.set(o, hash); + return hash; +} +/** + * merge two hashes in an order sensitive way + * @param {number} a + * @param {number} b + * @returns {number} + */ +function hashMerge(a, b) { + return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; +} +/** + * standard string hash popularised by java + * @param {string} s + * @returns {number} + */ +function hashString(s) { + let hash = 0; + const len = s.length; + for (let i = 0; i < len; i++) { + hash = (Math.imul(31, hash) + s.charCodeAt(i)) | 0; + } + return hash; +} +/** + * hash a number by converting to two integers and do some jumbling + * @param {number} n + * @returns {number} + */ +function hashNumber(n) { + tempDataView.setFloat64(0, n); + const i = tempDataView.getInt32(0); + const j = tempDataView.getInt32(4); + return Math.imul(0x45d9f3b, (i >> 16) ^ i) ^ j; +} +/** + * hash a BigInt by converting it to a string and hashing that + * @param {BigInt} n + * @returns {number} + */ +function hashBigInt(n) { + return hashString(n.toString()); +} +/** + * hash any js object + * @param {any} o + * @returns {number} + */ +function hashObject(o) { + const proto = Object.getPrototypeOf(o); + if (proto !== null && typeof proto.hashCode === "function") { + try { + const code = o.hashCode(o); + if (typeof code === "number") { + return code; + } + } catch {} + } + if (o instanceof Promise || o instanceof WeakSet || o instanceof WeakMap) { + return hashByReference(o); + } + if (o instanceof Date) { + return hashNumber(o.getTime()); + } + let h = 0; + if (o instanceof ArrayBuffer) { + o = new Uint8Array(o); + } + if (Array.isArray(o) || o instanceof Uint8Array) { + for (let i = 0; i < o.length; i++) { + h = (Math.imul(31, h) + getHash(o[i])) | 0; + } + } else if (o instanceof Set) { + o.forEach((v) => { + h = (h + getHash(v)) | 0; + }); + } else if (o instanceof Map) { + o.forEach((v, k) => { + h = (h + hashMerge(getHash(v), getHash(k))) | 0; + }); + } else { + const keys = Object.keys(o); + for (let i = 0; i < keys.length; i++) { + const k = keys[i]; + const v = o[k]; + h = (h + hashMerge(getHash(v), hashString(k))) | 0; + } + } + return h; +} +/** + * hash any js value + * @param {any} u + * @returns {number} + */ +export function getHash(u) { + if (u === null) return 0x42108422; + if (u === undefined) return 0x42108423; + if (u === true) return 0x42108421; + if (u === false) return 0x42108420; + switch (typeof u) { + case "number": + return hashNumber(u); + case "string": + return hashString(u); + case "bigint": + return hashBigInt(u); + case "object": + return hashObject(u); + case "symbol": + return hashByReference(u); + case "function": + return hashByReference(u); + default: + return 0; // should be unreachable + } +} +/** + * @template K,V + * @typedef {ArrayNode<K,V> | IndexNode<K,V> | CollisionNode<K,V>} Node + */ +/** + * @template K,V + * @typedef {{ type: typeof ENTRY, k: K, v: V }} Entry + */ +/** + * @template K,V + * @typedef {{ type: typeof ARRAY_NODE, size: number, array: (undefined | Entry<K,V> | Node<K,V>)[] }} ArrayNode + */ +/** + * @template K,V + * @typedef {{ type: typeof INDEX_NODE, bitmap: number, array: (Entry<K,V> | Node<K,V>)[] }} IndexNode + */ +/** + * @template K,V + * @typedef {{ type: typeof COLLISION_NODE, hash: number, array: Entry<K, V>[] }} CollisionNode + */ +/** + * @typedef {{ val: boolean }} Flag + */ +const SHIFT = 5; // number of bits you need to shift by to get the next bucket +const BUCKET_SIZE = Math.pow(2, SHIFT); +const MASK = BUCKET_SIZE - 1; // used to zero out all bits not in the bucket +const MAX_INDEX_NODE = BUCKET_SIZE / 2; // when does index node grow into array node +const MIN_ARRAY_NODE = BUCKET_SIZE / 4; // when does array node shrink to index node +const ENTRY = 0; +const ARRAY_NODE = 1; +const INDEX_NODE = 2; +const COLLISION_NODE = 3; +/** @type {IndexNode<any,any>} */ +const EMPTY = { + type: INDEX_NODE, + bitmap: 0, + array: [], +}; +/** + * Mask the hash to get only the bucket corresponding to shift + * @param {number} hash + * @param {number} shift + * @returns {number} + */ +function mask(hash, shift) { + return (hash >>> shift) & MASK; +} +/** + * Set only the Nth bit where N is the masked hash + * @param {number} hash + * @param {number} shift + * @returns {number} + */ +function bitpos(hash, shift) { + return 1 << mask(hash, shift); +} +/** + * Count the number of 1 bits in a number + * @param {number} x + * @returns {number} + */ +function bitcount(x) { + x -= (x >> 1) & 0x55555555; + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0f0f0f0f; + x += x >> 8; + x += x >> 16; + return x & 0x7f; +} +/** + * Calculate the array index of an item in a bitmap index node + * @param {number} bitmap + * @param {number} bit + * @returns {number} + */ +function index(bitmap, bit) { + return bitcount(bitmap & (bit - 1)); +} +/** + * Efficiently copy an array and set one value at an index + * @template T + * @param {T[]} arr + * @param {number} at + * @param {T} val + * @returns {T[]} + */ +function cloneAndSet(arr, at, val) { + const len = arr.length; + const out = new Array(len); + for (let i = 0; i < len; ++i) { + out[i] = arr[i]; + } + out[at] = val; + return out; +} +/** + * Efficiently copy an array and insert one value at an index + * @template T + * @param {T[]} arr + * @param {number} at + * @param {T} val + * @returns {T[]} + */ +function spliceIn(arr, at, val) { + const len = arr.length; + const out = new Array(len + 1); + let i = 0; + let g = 0; + while (i < at) { + out[g++] = arr[i++]; + } + out[g++] = val; + while (i < len) { + out[g++] = arr[i++]; + } + return out; +} +/** + * Efficiently copy an array and remove one value at an index + * @template T + * @param {T[]} arr + * @param {number} at + * @returns {T[]} + */ +function spliceOut(arr, at) { + const len = arr.length; + const out = new Array(len - 1); + let i = 0; + let g = 0; + while (i < at) { + out[g++] = arr[i++]; + } + ++i; + while (i < len) { + out[g++] = arr[i++]; + } + return out; +} +/** + * Create a new node containing two entries + * @template K,V + * @param {number} shift + * @param {K} key1 + * @param {V} val1 + * @param {number} key2hash + * @param {K} key2 + * @param {V} val2 + * @returns {Node<K,V>} + */ +function createNode(shift, key1, val1, key2hash, key2, val2) { + const key1hash = getHash(key1); + if (key1hash === key2hash) { + return { + type: COLLISION_NODE, + hash: key1hash, + array: [ + { type: ENTRY, k: key1, v: val1 }, + { type: ENTRY, k: key2, v: val2 }, + ], + }; + } + const addedLeaf = { val: false }; + return assoc( + assocIndex(EMPTY, shift, key1hash, key1, val1, addedLeaf), + shift, + key2hash, + key2, + val2, + addedLeaf + ); +} +/** + * @template T,K,V + * @callback AssocFunction + * @param {T} root + * @param {number} shift + * @param {number} hash + * @param {K} key + * @param {V} val + * @param {Flag} addedLeaf + * @returns {Node<K,V>} + */ +/** + * Associate a node with a new entry, creating a new node + * @template T,K,V + * @type {AssocFunction<Node<K,V>,K,V>} + */ +function assoc(root, shift, hash, key, val, addedLeaf) { + switch (root.type) { + case ARRAY_NODE: + return assocArray(root, shift, hash, key, val, addedLeaf); + case INDEX_NODE: + return assocIndex(root, shift, hash, key, val, addedLeaf); + case COLLISION_NODE: + return assocCollision(root, shift, hash, key, val, addedLeaf); + } +} +/** + * @template T,K,V + * @type {AssocFunction<ArrayNode<K,V>,K,V>} + */ +function assocArray(root, shift, hash, key, val, addedLeaf) { + const idx = mask(hash, shift); + const node = root.array[idx]; + // if the corresponding index is empty set the index to a newly created node + if (node === undefined) { + addedLeaf.val = true; + return { + type: ARRAY_NODE, + size: root.size + 1, + array: cloneAndSet(root.array, idx, { type: ENTRY, k: key, v: val }), + }; + } + if (node.type === ENTRY) { + // if keys are equal replace the entry + if (isEqual(key, node.k)) { + if (val === node.v) { + return root; + } + return { + type: ARRAY_NODE, + size: root.size, + array: cloneAndSet(root.array, idx, { + type: ENTRY, + k: key, + v: val, + }), + }; + } + // otherwise upgrade the entry to a node and insert + addedLeaf.val = true; + return { + type: ARRAY_NODE, + size: root.size, + array: cloneAndSet( + root.array, + idx, + createNode(shift + SHIFT, node.k, node.v, hash, key, val) + ), + }; + } + // otherwise call assoc on the child node + const n = assoc(node, shift + SHIFT, hash, key, val, addedLeaf); + // if the child node hasn't changed just return the old root + if (n === node) { + return root; + } + // otherwise set the index to the new node + return { + type: ARRAY_NODE, + size: root.size, + array: cloneAndSet(root.array, idx, n), + }; +} +/** + * @template T,K,V + * @type {AssocFunction<IndexNode<K,V>,K,V>} + */ +function assocIndex(root, shift, hash, key, val, addedLeaf) { + const bit = bitpos(hash, shift); + const idx = index(root.bitmap, bit); + // if there is already a item at this hash index.. + if ((root.bitmap & bit) !== 0) { + // if there is a node at the index (not an entry), call assoc on the child node + const node = root.array[idx]; + if (node.type !== ENTRY) { + const n = assoc(node, shift + SHIFT, hash, key, val, addedLeaf); + if (n === node) { + return root; + } + return { + type: INDEX_NODE, + bitmap: root.bitmap, + array: cloneAndSet(root.array, idx, n), + }; + } + // otherwise there is an entry at the index + // if the keys are equal replace the entry with the updated value + const nodeKey = node.k; + if (isEqual(key, nodeKey)) { + if (val === node.v) { + return root; + } + return { + type: INDEX_NODE, + bitmap: root.bitmap, + array: cloneAndSet(root.array, idx, { + type: ENTRY, + k: key, + v: val, + }), + }; + } + // if the keys are not equal, replace the entry with a new child node + addedLeaf.val = true; + return { + type: INDEX_NODE, + bitmap: root.bitmap, + array: cloneAndSet( + root.array, + idx, + createNode(shift + SHIFT, nodeKey, node.v, hash, key, val) + ), + }; + } else { + // else there is currently no item at the hash index + const n = root.array.length; + // if the number of nodes is at the maximum, expand this node into an array node + if (n >= MAX_INDEX_NODE) { + // create a 32 length array for the new array node (one for each bit in the hash) + const nodes = new Array(32); + // create and insert a node for the new entry + const jdx = mask(hash, shift); + nodes[jdx] = assocIndex(EMPTY, shift + SHIFT, hash, key, val, addedLeaf); + let j = 0; + let bitmap = root.bitmap; + // place each item in the index node into the correct spot in the array node + // loop through all 32 bits / array positions + for (let i = 0; i < 32; i++) { + if ((bitmap & 1) !== 0) { + const node = root.array[j++]; + nodes[i] = node; + } + // shift the bitmap to process the next bit + bitmap = bitmap >>> 1; + } + return { + type: ARRAY_NODE, + size: n + 1, + array: nodes, + }; + } else { + // else there is still space in this index node + // simply insert a new entry at the hash index + const newArray = spliceIn(root.array, idx, { + type: ENTRY, + k: key, + v: val, + }); + addedLeaf.val = true; + return { + type: INDEX_NODE, + bitmap: root.bitmap | bit, + array: newArray, + }; + } + } +} +/** + * @template T,K,V + * @type {AssocFunction<CollisionNode<K,V>,K,V>} + */ +function assocCollision(root, shift, hash, key, val, addedLeaf) { + // if there is a hash collision + if (hash === root.hash) { + const idx = collisionIndexOf(root, key); + // if this key already exists replace the entry with the new value + if (idx !== -1) { + const entry = root.array[idx]; + if (entry.v === val) { + return root; + } + return { + type: COLLISION_NODE, + hash: hash, + array: cloneAndSet(root.array, idx, { type: ENTRY, k: key, v: val }), + }; + } + // otherwise insert the entry at the end of the array + const size = root.array.length; + addedLeaf.val = true; + return { + type: COLLISION_NODE, + hash: hash, + array: cloneAndSet(root.array, size, { type: ENTRY, k: key, v: val }), + }; + } + // if there is no hash collision, upgrade to an index node + return assoc( + { + type: INDEX_NODE, + bitmap: bitpos(root.hash, shift), + array: [root], + }, + shift, + hash, + key, + val, + addedLeaf + ); +} +/** + * Find the index of a key in the collision node's array + * @template K,V + * @param {CollisionNode<K,V>} root + * @param {K} key + * @returns {number} + */ +function collisionIndexOf(root, key) { + const size = root.array.length; + for (let i = 0; i < size; i++) { + if (isEqual(key, root.array[i].k)) { + return i; + } + } + return -1; +} +/** + * @template T,K,V + * @callback FindFunction + * @param {T} root + * @param {number} shift + * @param {number} hash + * @param {K} key + * @returns {undefined | Entry<K,V>} + */ +/** + * Return the found entry or undefined if not present in the root + * @template K,V + * @type {FindFunction<Node<K,V>,K,V>} + */ +function find(root, shift, hash, key) { + switch (root.type) { + case ARRAY_NODE: + return findArray(root, shift, hash, key); + case INDEX_NODE: + return findIndex(root, shift, hash, key); + case COLLISION_NODE: + return findCollision(root, key); + } +} +/** + * @template K,V + * @type {FindFunction<ArrayNode<K,V>,K,V>} + */ +function findArray(root, shift, hash, key) { + const idx = mask(hash, shift); + const node = root.array[idx]; + if (node === undefined) { + return undefined; + } + if (node.type !== ENTRY) { + return find(node, shift + SHIFT, hash, key); + } + if (isEqual(key, node.k)) { + return node; + } + return undefined; +} +/** + * @template K,V + * @type {FindFunction<IndexNode<K,V>,K,V>} + */ +function findIndex(root, shift, hash, key) { + const bit = bitpos(hash, shift); + if ((root.bitmap & bit) === 0) { + return undefined; + } + const idx = index(root.bitmap, bit); + const node = root.array[idx]; + if (node.type !== ENTRY) { + return find(node, shift + SHIFT, hash, key); + } + if (isEqual(key, node.k)) { + return node; + } + return undefined; +} +/** + * @template K,V + * @param {CollisionNode<K,V>} root + * @param {K} key + * @returns {undefined | Entry<K,V>} + */ +function findCollision(root, key) { + const idx = collisionIndexOf(root, key); + if (idx < 0) { + return undefined; + } + return root.array[idx]; +} +/** + * @template T,K,V + * @callback WithoutFunction + * @param {T} root + * @param {number} shift + * @param {number} hash + * @param {K} key + * @returns {undefined | Node<K,V>} + */ +/** + * Remove an entry from the root, returning the updated root. + * Returns undefined if the node should be removed from the parent. + * @template K,V + * @type {WithoutFunction<Node<K,V>,K,V>} + * */ +function without(root, shift, hash, key) { + switch (root.type) { + case ARRAY_NODE: + return withoutArray(root, shift, hash, key); + case INDEX_NODE: + return withoutIndex(root, shift, hash, key); + case COLLISION_NODE: + return withoutCollision(root, key); + } +} +/** + * @template K,V + * @type {WithoutFunction<ArrayNode<K,V>,K,V>} + */ +function withoutArray(root, shift, hash, key) { + const idx = mask(hash, shift); + const node = root.array[idx]; + if (node === undefined) { + return root; // already empty + } + let n = undefined; + // if node is an entry and the keys are not equal there is nothing to remove + // if node is not an entry do a recursive call + if (node.type === ENTRY) { + if (!isEqual(node.k, key)) { + return root; // no changes + } + } else { + n = without(node, shift + SHIFT, hash, key); + if (n === node) { + return root; // no changes + } + } + // if the recursive call returned undefined the node should be removed + if (n === undefined) { + // if the number of child nodes is at the minimum, pack into an index node + if (root.size <= MIN_ARRAY_NODE) { + const arr = root.array; + const out = new Array(root.size - 1); + let i = 0; + let j = 0; + let bitmap = 0; + while (i < idx) { + const nv = arr[i]; + if (nv !== undefined) { + out[j] = nv; + bitmap |= 1 << i; + ++j; + } + ++i; + } + ++i; // skip copying the removed node + while (i < arr.length) { + const nv = arr[i]; + if (nv !== undefined) { + out[j] = nv; + bitmap |= 1 << i; + ++j; + } + ++i; + } + return { + type: INDEX_NODE, + bitmap: bitmap, + array: out, + }; + } + return { + type: ARRAY_NODE, + size: root.size - 1, + array: cloneAndSet(root.array, idx, n), + }; + } + return { + type: ARRAY_NODE, + size: root.size, + array: cloneAndSet(root.array, idx, n), + }; +} +/** + * @template K,V + * @type {WithoutFunction<IndexNode<K,V>,K,V>} + */ +function withoutIndex(root, shift, hash, key) { + const bit = bitpos(hash, shift); + if ((root.bitmap & bit) === 0) { + return root; // already empty + } + const idx = index(root.bitmap, bit); + const node = root.array[idx]; + // if the item is not an entry + if (node.type !== ENTRY) { + const n = without(node, shift + SHIFT, hash, key); + if (n === node) { + return root; // no changes + } + // if not undefined, the child node still has items, so update it + if (n !== undefined) { + return { + type: INDEX_NODE, + bitmap: root.bitmap, + array: cloneAndSet(root.array, idx, n), + }; + } + // otherwise the child node should be removed + // if it was the only child node, remove this node from the parent + if (root.bitmap === bit) { + return undefined; + } + // otherwise just remove the child node + return { + type: INDEX_NODE, + bitmap: root.bitmap ^ bit, + array: spliceOut(root.array, idx), + }; + } + // otherwise the item is an entry, remove it if the key matches + if (isEqual(key, node.k)) { + if (root.bitmap === bit) { + return undefined; + } + return { + type: INDEX_NODE, + bitmap: root.bitmap ^ bit, + array: spliceOut(root.array, idx), + }; + } + return root; +} +/** + * @template K,V + * @param {CollisionNode<K,V>} root + * @param {K} key + * @returns {undefined | Node<K,V>} + */ +function withoutCollision(root, key) { + const idx = collisionIndexOf(root, key); + // if the key not found, no changes + if (idx < 0) { + return root; + } + // otherwise the entry was found, remove it + // if it was the only entry in this node, remove the whole node + if (root.array.length === 1) { + return undefined; + } + // otherwise just remove the entry + return { + type: COLLISION_NODE, + hash: root.hash, + array: spliceOut(root.array, idx), + }; +} +/** + * @template K,V + * @param {undefined | Node<K,V>} root + * @param {(value:V,key:K)=>void} fn + * @returns {void} + */ +function forEach(root, fn) { + if (root === undefined) { + return; + } + const items = root.array; + const size = items.length; + for (let i = 0; i < size; i++) { + const item = items[i]; + if (item === undefined) { + continue; + } + if (item.type === ENTRY) { + fn(item.v, item.k); + continue; + } + forEach(item, fn); + } +} +/** + * Extra wrapper to keep track of Dict size and clean up the API + * @template K,V + */ +export default class Dict { + /** + * @template V + * @param {Record<string,V>} o + * @returns {Dict<string,V>} + */ + static fromObject(o) { + const keys = Object.keys(o); + /** @type Dict<string,V> */ + let m = Dict.new(); + for (let i = 0; i < keys.length; i++) { + const k = keys[i]; + m = m.set(k, o[k]); + } + return m; + } + /** + * @template K,V + * @param {Map<K,V>} o + * @returns {Dict<K,V>} + */ + static fromMap(o) { + /** @type Dict<K,V> */ + let m = Dict.new(); + o.forEach((v, k) => { + m = m.set(k, v); + }); + return m; + } + static new() { + return new Dict(undefined, 0); + } + /** + * @param {undefined | Node<K,V>} root + * @param {number} size + */ + constructor(root, size) { + this.root = root; + this.size = size; + } + /** + * @template NotFound + * @param {K} key + * @param {NotFound} notFound + * @returns {NotFound | V} + */ + get(key, notFound) { + if (this.root === undefined) { + return notFound; + } + const found = find(this.root, 0, getHash(key), key); + if (found === undefined) { + return notFound; + } + return found.v; + } + /** + * @param {K} key + * @param {V} val + * @returns {Dict<K,V>} + */ + set(key, val) { + const addedLeaf = { val: false }; + const root = this.root === undefined ? EMPTY : this.root; + const newRoot = assoc(root, 0, getHash(key), key, val, addedLeaf); + if (newRoot === this.root) { + return this; + } + return new Dict(newRoot, addedLeaf.val ? this.size + 1 : this.size); + } + /** + * @param {K} key + * @returns {Dict<K,V>} + */ + delete(key) { + if (this.root === undefined) { + return this; + } + const newRoot = without(this.root, 0, getHash(key), key); + if (newRoot === this.root) { + return this; + } + if (newRoot === undefined) { + return Dict.new(); + } + return new Dict(newRoot, this.size - 1); + } + /** + * @param {K} key + * @returns {boolean} + */ + has(key) { + if (this.root === undefined) { + return false; + } + return find(this.root, 0, getHash(key), key) !== undefined; + } + /** + * @returns {[K,V][]} + */ + entries() { + if (this.root === undefined) { + return []; + } + /** @type [K,V][] */ + const result = []; + this.forEach((v, k) => result.push([k, v])); + return result; + } + /** + * + * @param {(val:V,key:K)=>void} fn + */ + forEach(fn) { + forEach(this.root, fn); + } + hashCode() { + let h = 0; + this.forEach((v, k) => { + h = (h + hashMerge(getHash(v), getHash(k))) | 0; + }); + return h; + } + /** + * @param {unknown} o + * @returns {boolean} + */ + equals(o) { + if (!(o instanceof Dict) || this.size !== o.size) { + return false; + } + let equal = true; + this.forEach((v, k) => { + equal = equal && isEqual(o.get(k, !v), v); + }); + return equal; + } +} diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache Binary files differnew file mode 100644 index 0000000..ec2f726 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache_meta Binary files differnew file mode 100644 index 0000000..a935fcc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.erl new file mode 100644 index 0000000..d8d44c3 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@base.erl @@ -0,0 +1,20 @@ +-module(gleam@base). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([encode64/2, decode64/1, url_encode64/2, url_decode64/1]). + +-spec encode64(bitstring(), boolean()) -> binary(). +encode64(Input, Padding) -> + gleam@bit_array:base64_encode(Input, Padding). + +-spec decode64(binary()) -> {ok, bitstring()} | {error, nil}. +decode64(Encoded) -> + gleam@bit_array:base64_decode(Encoded). + +-spec url_encode64(bitstring(), boolean()) -> binary(). +url_encode64(Input, Padding) -> + gleam@bit_array:base64_url_encode(Input, Padding). + +-spec url_decode64(binary()) -> {ok, bitstring()} | {error, nil}. +url_decode64(Encoded) -> + gleam@bit_array:base64_url_decode(Encoded). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache Binary files differnew file mode 100644 index 0000000..1019a88 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta Binary files differnew file mode 100644 index 0000000..bfd3dd8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.erl new file mode 100644 index 0000000..ae8e5ff --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_array.erl @@ -0,0 +1,102 @@ +-module(gleam@bit_array). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from_string/1, byte_size/1, slice/3, is_utf8/1, to_string/1, concat/1, append/2, base64_encode/2, base64_decode/1, base64_url_encode/2, base64_url_decode/1, base16_encode/1, base16_decode/1]). + +-spec from_string(binary()) -> bitstring(). +from_string(X) -> + gleam_stdlib:identity(X). + +-spec byte_size(bitstring()) -> integer(). +byte_size(X) -> + erlang:byte_size(X). + +-spec slice(bitstring(), integer(), integer()) -> {ok, bitstring()} | + {error, nil}. +slice(String, Position, Length) -> + gleam_stdlib:bit_array_slice(String, Position, Length). + +-spec do_is_utf8(bitstring()) -> boolean(). +do_is_utf8(Bits) -> + case Bits of + <<>> -> + true; + + <<_/utf8, Rest/binary>> -> + do_is_utf8(Rest); + + _ -> + false + end. + +-spec is_utf8(bitstring()) -> boolean(). +is_utf8(Bits) -> + do_is_utf8(Bits). + +-spec do_to_string(bitstring()) -> {ok, binary()} | {error, nil}. +do_to_string(Bits) -> + case is_utf8(Bits) of + true -> + {ok, gleam_stdlib:identity(Bits)}; + + false -> + {error, nil} + end. + +-spec to_string(bitstring()) -> {ok, binary()} | {error, nil}. +to_string(Bits) -> + do_to_string(Bits). + +-spec concat(list(bitstring())) -> bitstring(). +concat(Bit_arrays) -> + gleam_stdlib:bit_array_concat(Bit_arrays). + +-spec append(bitstring(), bitstring()) -> bitstring(). +append(First, Second) -> + gleam_stdlib:bit_array_concat([First, Second]). + +-spec base64_encode(bitstring(), boolean()) -> binary(). +base64_encode(Input, Padding) -> + Encoded = base64:encode(Input), + case Padding of + true -> + Encoded; + + false -> + gleam@string:replace(Encoded, <<"="/utf8>>, <<""/utf8>>) + end. + +-spec base64_decode(binary()) -> {ok, bitstring()} | {error, nil}. +base64_decode(Encoded) -> + Padded = case erlang:byte_size(gleam_stdlib:identity(Encoded)) rem 4 of + 0 -> + Encoded; + + N -> + gleam@string:append( + Encoded, + gleam@string:repeat(<<"="/utf8>>, 4 - N) + ) + end, + gleam_stdlib:base_decode64(Padded). + +-spec base64_url_encode(bitstring(), boolean()) -> binary(). +base64_url_encode(Input, Padding) -> + _pipe = base64_encode(Input, Padding), + _pipe@1 = gleam@string:replace(_pipe, <<"+"/utf8>>, <<"-"/utf8>>), + gleam@string:replace(_pipe@1, <<"/"/utf8>>, <<"_"/utf8>>). + +-spec base64_url_decode(binary()) -> {ok, bitstring()} | {error, nil}. +base64_url_decode(Encoded) -> + _pipe = Encoded, + _pipe@1 = gleam@string:replace(_pipe, <<"-"/utf8>>, <<"+"/utf8>>), + _pipe@2 = gleam@string:replace(_pipe@1, <<"_"/utf8>>, <<"/"/utf8>>), + base64_decode(_pipe@2). + +-spec base16_encode(bitstring()) -> binary(). +base16_encode(Input) -> + binary:encode_hex(Input). + +-spec base16_decode(binary()) -> {ok, bitstring()} | {error, nil}. +base16_decode(Input) -> + gleam_stdlib:base16_decode(Input). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache Binary files differnew file mode 100644 index 0000000..98cc7fa --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache_meta Binary files differnew file mode 100644 index 0000000..bc4a1a5 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.erl new file mode 100644 index 0000000..648605f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_builder.erl @@ -0,0 +1,66 @@ +-module(gleam@bit_builder). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/0, prepend/2, append/2, prepend_builder/2, append_builder/2, prepend_string/2, append_string/2, concat/1, concat_bit_strings/1, from_string/1, from_string_builder/1, from_bit_string/1, to_bit_string/1, byte_size/1]). + +-spec new() -> gleam@bytes_builder:bytes_builder(). +new() -> + gleam@bytes_builder:new(). + +-spec prepend(gleam@bytes_builder:bytes_builder(), bitstring()) -> gleam@bytes_builder:bytes_builder(). +prepend(To, Prefix) -> + gleam@bytes_builder:prepend(To, Prefix). + +-spec append(gleam@bytes_builder:bytes_builder(), bitstring()) -> gleam@bytes_builder:bytes_builder(). +append(To, Suffix) -> + gleam@bytes_builder:append(To, Suffix). + +-spec prepend_builder( + gleam@bytes_builder:bytes_builder(), + gleam@bytes_builder:bytes_builder() +) -> gleam@bytes_builder:bytes_builder(). +prepend_builder(To, Prefix) -> + gleam@bytes_builder:prepend_builder(To, Prefix). + +-spec append_builder( + gleam@bytes_builder:bytes_builder(), + gleam@bytes_builder:bytes_builder() +) -> gleam@bytes_builder:bytes_builder(). +append_builder(First, Second) -> + gleam_stdlib:iodata_append(First, Second). + +-spec prepend_string(gleam@bytes_builder:bytes_builder(), binary()) -> gleam@bytes_builder:bytes_builder(). +prepend_string(To, Prefix) -> + gleam@bytes_builder:prepend_string(To, Prefix). + +-spec append_string(gleam@bytes_builder:bytes_builder(), binary()) -> gleam@bytes_builder:bytes_builder(). +append_string(To, Suffix) -> + gleam@bytes_builder:append_string(To, Suffix). + +-spec concat(list(gleam@bytes_builder:bytes_builder())) -> gleam@bytes_builder:bytes_builder(). +concat(Builders) -> + gleam_stdlib:identity(Builders). + +-spec concat_bit_strings(list(bitstring())) -> gleam@bytes_builder:bytes_builder(). +concat_bit_strings(Bits) -> + gleam_stdlib:identity(Bits). + +-spec from_string(binary()) -> gleam@bytes_builder:bytes_builder(). +from_string(String) -> + gleam_stdlib:wrap_list(String). + +-spec from_string_builder(gleam@string_builder:string_builder()) -> gleam@bytes_builder:bytes_builder(). +from_string_builder(Builder) -> + gleam_stdlib:wrap_list(Builder). + +-spec from_bit_string(bitstring()) -> gleam@bytes_builder:bytes_builder(). +from_bit_string(Bits) -> + gleam_stdlib:wrap_list(Bits). + +-spec to_bit_string(gleam@bytes_builder:bytes_builder()) -> bitstring(). +to_bit_string(Builder) -> + erlang:list_to_bitstring(Builder). + +-spec byte_size(gleam@bytes_builder:bytes_builder()) -> integer(). +byte_size(Builder) -> + erlang:iolist_size(Builder). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache Binary files differnew file mode 100644 index 0000000..04638ff --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache_meta Binary files differnew file mode 100644 index 0000000..f9f229f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.erl new file mode 100644 index 0000000..d1eea04 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bit_string.erl @@ -0,0 +1,33 @@ +-module(gleam@bit_string). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from_string/1, byte_size/1, append/2, slice/3, is_utf8/1, to_string/1, concat/1]). + +-spec from_string(binary()) -> bitstring(). +from_string(X) -> + gleam_stdlib:identity(X). + +-spec byte_size(bitstring()) -> integer(). +byte_size(X) -> + erlang:byte_size(X). + +-spec append(bitstring(), bitstring()) -> bitstring(). +append(First, Second) -> + gleam@bit_array:append(First, Second). + +-spec slice(bitstring(), integer(), integer()) -> {ok, bitstring()} | + {error, nil}. +slice(String, Position, Length) -> + gleam_stdlib:bit_array_slice(String, Position, Length). + +-spec is_utf8(bitstring()) -> boolean(). +is_utf8(Bits) -> + gleam@bit_array:is_utf8(Bits). + +-spec to_string(bitstring()) -> {ok, binary()} | {error, nil}. +to_string(Bits) -> + gleam@bit_array:to_string(Bits). + +-spec concat(list(bitstring())) -> bitstring(). +concat(Bit_strings) -> + gleam_stdlib:bit_array_concat(Bit_strings). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache Binary files differnew file mode 100644 index 0000000..7ff9604 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta Binary files differnew file mode 100644 index 0000000..33ef24c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.erl new file mode 100644 index 0000000..8f6abcc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bool.erl @@ -0,0 +1,162 @@ +-module(gleam@bool). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export(['and'/2, 'or'/2, negate/1, nor/2, nand/2, exclusive_or/2, exclusive_nor/2, compare/2, max/2, min/2, to_int/1, to_string/1, guard/3, lazy_guard/3]). + +-spec 'and'(boolean(), boolean()) -> boolean(). +'and'(A, B) -> + A andalso B. + +-spec 'or'(boolean(), boolean()) -> boolean(). +'or'(A, B) -> + A orelse B. + +-spec negate(boolean()) -> boolean(). +negate(Bool) -> + case Bool of + true -> + false; + + false -> + true + end. + +-spec nor(boolean(), boolean()) -> boolean(). +nor(A, B) -> + case {A, B} of + {false, false} -> + true; + + {false, true} -> + false; + + {true, false} -> + false; + + {true, true} -> + false + end. + +-spec nand(boolean(), boolean()) -> boolean(). +nand(A, B) -> + case {A, B} of + {false, false} -> + true; + + {false, true} -> + true; + + {true, false} -> + true; + + {true, true} -> + false + end. + +-spec exclusive_or(boolean(), boolean()) -> boolean(). +exclusive_or(A, B) -> + case {A, B} of + {false, false} -> + false; + + {false, true} -> + true; + + {true, false} -> + true; + + {true, true} -> + false + end. + +-spec exclusive_nor(boolean(), boolean()) -> boolean(). +exclusive_nor(A, B) -> + case {A, B} of + {false, false} -> + true; + + {false, true} -> + false; + + {true, false} -> + false; + + {true, true} -> + true + end. + +-spec compare(boolean(), boolean()) -> gleam@order:order(). +compare(A, B) -> + case {A, B} of + {true, true} -> + eq; + + {true, false} -> + gt; + + {false, false} -> + eq; + + {false, true} -> + lt + end. + +-spec max(boolean(), boolean()) -> boolean(). +max(A, B) -> + case A of + true -> + true; + + false -> + B + end. + +-spec min(boolean(), boolean()) -> boolean(). +min(A, B) -> + case A of + false -> + false; + + true -> + B + end. + +-spec to_int(boolean()) -> integer(). +to_int(Bool) -> + case Bool of + false -> + 0; + + true -> + 1 + end. + +-spec to_string(boolean()) -> binary(). +to_string(Bool) -> + case Bool of + false -> + <<"False"/utf8>>; + + true -> + <<"True"/utf8>> + end. + +-spec guard(boolean(), CYG, fun(() -> CYG)) -> CYG. +guard(Requirement, Consequence, Alternative) -> + case Requirement of + true -> + Consequence; + + false -> + Alternative() + end. + +-spec lazy_guard(boolean(), fun(() -> CYH), fun(() -> CYH)) -> CYH. +lazy_guard(Requirement, Consequence, Alternative) -> + case Requirement of + true -> + Consequence(); + + false -> + Alternative() + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache Binary files differnew file mode 100644 index 0000000..2564637 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache_meta Binary files differnew file mode 100644 index 0000000..7b614aa --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.erl new file mode 100644 index 0000000..61851fc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@bytes_builder.erl @@ -0,0 +1,87 @@ +-module(gleam@bytes_builder). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([append_builder/2, prepend_builder/2, concat/1, new/0, from_string/1, prepend_string/2, append_string/2, from_string_builder/1, from_bit_array/1, prepend/2, append/2, concat_bit_arrays/1, to_bit_array/1, byte_size/1]). +-export_type([bytes_builder/0]). + +-opaque bytes_builder() :: {bytes, bitstring()} | + {text, gleam@string_builder:string_builder()} | + {many, list(bytes_builder())}. + +-spec append_builder(bytes_builder(), bytes_builder()) -> bytes_builder(). +append_builder(First, Second) -> + gleam_stdlib:iodata_append(First, Second). + +-spec prepend_builder(bytes_builder(), bytes_builder()) -> bytes_builder(). +prepend_builder(Second, First) -> + gleam_stdlib:iodata_append(First, Second). + +-spec concat(list(bytes_builder())) -> bytes_builder(). +concat(Builders) -> + gleam_stdlib:identity(Builders). + +-spec new() -> bytes_builder(). +new() -> + gleam_stdlib:identity([]). + +-spec from_string(binary()) -> bytes_builder(). +from_string(String) -> + gleam_stdlib:wrap_list(String). + +-spec prepend_string(bytes_builder(), binary()) -> bytes_builder(). +prepend_string(Second, First) -> + gleam_stdlib:iodata_append(gleam_stdlib:wrap_list(First), Second). + +-spec append_string(bytes_builder(), binary()) -> bytes_builder(). +append_string(First, Second) -> + gleam_stdlib:iodata_append(First, gleam_stdlib:wrap_list(Second)). + +-spec from_string_builder(gleam@string_builder:string_builder()) -> bytes_builder(). +from_string_builder(Builder) -> + gleam_stdlib:wrap_list(Builder). + +-spec from_bit_array(bitstring()) -> bytes_builder(). +from_bit_array(Bits) -> + gleam_stdlib:wrap_list(Bits). + +-spec prepend(bytes_builder(), bitstring()) -> bytes_builder(). +prepend(Second, First) -> + gleam_stdlib:iodata_append(gleam_stdlib:wrap_list(First), Second). + +-spec append(bytes_builder(), bitstring()) -> bytes_builder(). +append(First, Second) -> + gleam_stdlib:iodata_append(First, gleam_stdlib:wrap_list(Second)). + +-spec concat_bit_arrays(list(bitstring())) -> bytes_builder(). +concat_bit_arrays(Bits) -> + gleam_stdlib:identity(Bits). + +-spec to_list(list(list(bytes_builder())), list(bitstring())) -> list(bitstring()). +to_list(Stack, Acc) -> + case Stack of + [] -> + Acc; + + [[] | Remaining_stack] -> + to_list(Remaining_stack, Acc); + + [[{bytes, Bits} | Rest] | Remaining_stack@1] -> + to_list([Rest | Remaining_stack@1], [Bits | Acc]); + + [[{text, Builder} | Rest@1] | Remaining_stack@2] -> + Bits@1 = gleam_stdlib:identity( + gleam@string_builder:to_string(Builder) + ), + to_list([Rest@1 | Remaining_stack@2], [Bits@1 | Acc]); + + [[{many, Builders} | Rest@2] | Remaining_stack@3] -> + to_list([Builders, Rest@2 | Remaining_stack@3], Acc) + end. + +-spec to_bit_array(bytes_builder()) -> bitstring(). +to_bit_array(Builder) -> + erlang:list_to_bitstring(Builder). + +-spec byte_size(bytes_builder()) -> integer(). +byte_size(Builder) -> + erlang:iolist_size(Builder). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache Binary files differnew file mode 100644 index 0000000..2aa2fe6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta Binary files differnew file mode 100644 index 0000000..4410520 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.erl new file mode 100644 index 0000000..8dd79fd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dict.erl @@ -0,0 +1,97 @@ +-module(gleam@dict). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([size/1, to_list/1, from_list/1, has_key/2, new/0, get/2, insert/3, map_values/2, keys/1, values/1, filter/2, take/2, merge/2, delete/2, drop/2, update/3, fold/3]). +-export_type([dict/2]). + +-type dict(KS, KT) :: any() | {gleam_phantom, KS, KT}. + +-spec size(dict(any(), any())) -> integer(). +size(Dict) -> + maps:size(Dict). + +-spec to_list(dict(LC, LD)) -> list({LC, LD}). +to_list(Dict) -> + maps:to_list(Dict). + +-spec from_list(list({LM, LN})) -> dict(LM, LN). +from_list(List) -> + maps:from_list(List). + +-spec has_key(dict(LW, any()), LW) -> boolean(). +has_key(Dict, Key) -> + maps:is_key(Key, Dict). + +-spec new() -> dict(any(), any()). +new() -> + maps:new(). + +-spec get(dict(MM, MN), MM) -> {ok, MN} | {error, nil}. +get(From, Get) -> + gleam_stdlib:map_get(From, Get). + +-spec insert(dict(MY, MZ), MY, MZ) -> dict(MY, MZ). +insert(Dict, Key, Value) -> + maps:put(Key, Value, Dict). + +-spec map_values(dict(NK, NL), fun((NK, NL) -> NO)) -> dict(NK, NO). +map_values(Dict, Fun) -> + maps:map(Fun, Dict). + +-spec keys(dict(NY, any())) -> list(NY). +keys(Dict) -> + maps:keys(Dict). + +-spec values(dict(any(), OJ)) -> list(OJ). +values(Dict) -> + maps:values(Dict). + +-spec filter(dict(OS, OT), fun((OS, OT) -> boolean())) -> dict(OS, OT). +filter(Dict, Predicate) -> + maps:filter(Predicate, Dict). + +-spec take(dict(PE, PF), list(PE)) -> dict(PE, PF). +take(Dict, Desired_keys) -> + maps:with(Desired_keys, Dict). + +-spec merge(dict(PS, PT), dict(PS, PT)) -> dict(PS, PT). +merge(Dict, New_entries) -> + maps:merge(Dict, New_entries). + +-spec delete(dict(QI, QJ), QI) -> dict(QI, QJ). +delete(Dict, Key) -> + maps:remove(Key, Dict). + +-spec drop(dict(QU, QV), list(QU)) -> dict(QU, QV). +drop(Dict, Disallowed_keys) -> + case Disallowed_keys of + [] -> + Dict; + + [X | Xs] -> + drop(delete(Dict, X), Xs) + end. + +-spec update(dict(RB, RC), RB, fun((gleam@option:option(RC)) -> RC)) -> dict(RB, RC). +update(Dict, Key, Fun) -> + _pipe = Dict, + _pipe@1 = get(_pipe, Key), + _pipe@2 = gleam@option:from_result(_pipe@1), + _pipe@3 = Fun(_pipe@2), + insert(Dict, Key, _pipe@3). + +-spec do_fold(list({RI, RJ}), RL, fun((RL, RI, RJ) -> RL)) -> RL. +do_fold(List, Initial, Fun) -> + case List of + [] -> + Initial; + + [{K, V} | Rest] -> + do_fold(Rest, Fun(Initial, K, V), Fun) + end. + +-spec fold(dict(RM, RN), RQ, fun((RQ, RM, RN) -> RQ)) -> RQ. +fold(Dict, Initial, Fun) -> + _pipe = Dict, + _pipe@1 = to_list(_pipe), + do_fold(_pipe@1, Initial, Fun). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache Binary files differnew file mode 100644 index 0000000..810ef80 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta Binary files differnew file mode 100644 index 0000000..9ae5074 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.erl new file mode 100644 index 0000000..8475e8c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@dynamic.erl @@ -0,0 +1,808 @@ +-module(gleam@dynamic). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([from/1, unsafe_coerce/1, dynamic/1, bit_array/1, bit_string/1, classify/1, int/1, float/1, bool/1, shallow_list/1, optional/1, any/1, decode1/2, result/2, list/1, string/1, field/2, optional_field/2, element/2, tuple2/2, tuple3/3, tuple4/4, tuple5/5, tuple6/6, dict/2, map/2, decode2/3, decode3/4, decode4/5, decode5/6, decode6/7, decode7/8, decode8/9, decode9/10]). +-export_type([dynamic_/0, decode_error/0, unknown_tuple/0]). + +-type dynamic_() :: any(). + +-type decode_error() :: {decode_error, binary(), binary(), list(binary())}. + +-type unknown_tuple() :: any(). + +-spec from(any()) -> dynamic_(). +from(A) -> + gleam_stdlib:identity(A). + +-spec unsafe_coerce(dynamic_()) -> any(). +unsafe_coerce(A) -> + gleam_stdlib:identity(A). + +-spec dynamic(dynamic_()) -> {ok, dynamic_()} | {error, list(decode_error())}. +dynamic(Value) -> + {ok, Value}. + +-spec bit_array(dynamic_()) -> {ok, bitstring()} | {error, list(decode_error())}. +bit_array(Data) -> + gleam_stdlib:decode_bit_array(Data). + +-spec bit_string(dynamic_()) -> {ok, bitstring()} | + {error, list(decode_error())}. +bit_string(Data) -> + bit_array(Data). + +-spec put_expected(decode_error(), binary()) -> decode_error(). +put_expected(Error, Expected) -> + erlang:setelement(2, Error, Expected). + +-spec classify(dynamic_()) -> binary(). +classify(Data) -> + gleam_stdlib:classify_dynamic(Data). + +-spec int(dynamic_()) -> {ok, integer()} | {error, list(decode_error())}. +int(Data) -> + gleam_stdlib:decode_int(Data). + +-spec float(dynamic_()) -> {ok, float()} | {error, list(decode_error())}. +float(Data) -> + gleam_stdlib:decode_float(Data). + +-spec bool(dynamic_()) -> {ok, boolean()} | {error, list(decode_error())}. +bool(Data) -> + gleam_stdlib:decode_bool(Data). + +-spec shallow_list(dynamic_()) -> {ok, list(dynamic_())} | + {error, list(decode_error())}. +shallow_list(Value) -> + gleam_stdlib:decode_list(Value). + +-spec optional(fun((dynamic_()) -> {ok, DVA} | {error, list(decode_error())})) -> fun((dynamic_()) -> {ok, + gleam@option:option(DVA)} | + {error, list(decode_error())}). +optional(Decode) -> + fun(Value) -> gleam_stdlib:decode_option(Value, Decode) end. + +-spec at_least_decode_tuple_error(integer(), dynamic_()) -> {ok, any()} | + {error, list(decode_error())}. +at_least_decode_tuple_error(Size, Data) -> + S = case Size of + 1 -> + <<""/utf8>>; + + _ -> + <<"s"/utf8>> + end, + Error = begin + _pipe = [<<"Tuple of at least "/utf8>>, + gleam@int:to_string(Size), + <<" element"/utf8>>, + S], + _pipe@1 = gleam@string_builder:from_strings(_pipe), + _pipe@2 = gleam@string_builder:to_string(_pipe@1), + {decode_error, _pipe@2, classify(Data), []} + end, + {error, [Error]}. + +-spec any(list(fun((dynamic_()) -> {ok, DZH} | {error, list(decode_error())}))) -> fun((dynamic_()) -> {ok, + DZH} | + {error, list(decode_error())}). +any(Decoders) -> + fun(Data) -> case Decoders of + [] -> + {error, + [{decode_error, <<"another type"/utf8>>, classify(Data), []}]}; + + [Decoder | Decoders@1] -> + case Decoder(Data) of + {ok, Decoded} -> + {ok, Decoded}; + + {error, _} -> + (any(Decoders@1))(Data) + end + end end. + +-spec all_errors({ok, any()} | {error, list(decode_error())}) -> list(decode_error()). +all_errors(Result) -> + case Result of + {ok, _} -> + []; + + {error, Errors} -> + Errors + end. + +-spec decode1( + fun((DZL) -> DZM), + fun((dynamic_()) -> {ok, DZL} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, DZM} | {error, list(decode_error())}). +decode1(Constructor, T1) -> + fun(Value) -> case T1(Value) of + {ok, A} -> + {ok, Constructor(A)}; + + A@1 -> + {error, all_errors(A@1)} + end end. + +-spec push_path(decode_error(), any()) -> decode_error(). +push_path(Error, Name) -> + Name@1 = from(Name), + Decoder = any( + [fun string/1, + fun(X) -> gleam@result:map(int(X), fun gleam@int:to_string/1) end] + ), + Name@3 = case Decoder(Name@1) of + {ok, Name@2} -> + Name@2; + + {error, _} -> + _pipe = [<<"<"/utf8>>, classify(Name@1), <<">"/utf8>>], + _pipe@1 = gleam@string_builder:from_strings(_pipe), + gleam@string_builder:to_string(_pipe@1) + end, + erlang:setelement(4, Error, [Name@3 | erlang:element(4, Error)]). + +-spec result( + fun((dynamic_()) -> {ok, DUO} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DUQ} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {ok, DUO} | {error, DUQ}} | + {error, list(decode_error())}). +result(Decode_ok, Decode_error) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_result(Value), + fun(Inner_result) -> case Inner_result of + {ok, Raw} -> + gleam@result:'try'( + begin + _pipe = Decode_ok(Raw), + map_errors( + _pipe, + fun(_capture) -> + push_path(_capture, <<"ok"/utf8>>) + end + ) + end, + fun(Value@1) -> {ok, {ok, Value@1}} end + ); + + {error, Raw@1} -> + gleam@result:'try'( + begin + _pipe@1 = Decode_error(Raw@1), + map_errors( + _pipe@1, + fun(_capture@1) -> + push_path(_capture@1, <<"error"/utf8>>) + end + ) + end, + fun(Value@2) -> {ok, {error, Value@2}} end + ) + end end + ) + end. + +-spec list(fun((dynamic_()) -> {ok, DUV} | {error, list(decode_error())})) -> fun((dynamic_()) -> {ok, + list(DUV)} | + {error, list(decode_error())}). +list(Decoder_type) -> + fun(Dynamic) -> + gleam@result:'try'(shallow_list(Dynamic), fun(List) -> _pipe = List, + _pipe@1 = gleam@list:try_map(_pipe, Decoder_type), + map_errors( + _pipe@1, + fun(_capture) -> push_path(_capture, <<"*"/utf8>>) end + ) end) + end. + +-spec map_errors( + {ok, DTJ} | {error, list(decode_error())}, + fun((decode_error()) -> decode_error()) +) -> {ok, DTJ} | {error, list(decode_error())}. +map_errors(Result, F) -> + gleam@result:map_error( + Result, + fun(_capture) -> gleam@list:map(_capture, F) end + ). + +-spec decode_string(dynamic_()) -> {ok, binary()} | + {error, list(decode_error())}. +decode_string(Data) -> + _pipe = bit_array(Data), + _pipe@1 = map_errors( + _pipe, + fun(_capture) -> put_expected(_capture, <<"String"/utf8>>) end + ), + gleam@result:'try'( + _pipe@1, + fun(Raw) -> case gleam@bit_array:to_string(Raw) of + {ok, String} -> + {ok, String}; + + {error, nil} -> + {error, + [{decode_error, + <<"String"/utf8>>, + <<"BitArray"/utf8>>, + []}]} + end end + ). + +-spec string(dynamic_()) -> {ok, binary()} | {error, list(decode_error())}. +string(Data) -> + decode_string(Data). + +-spec field( + any(), + fun((dynamic_()) -> {ok, DVK} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, DVK} | {error, list(decode_error())}). +field(Name, Inner_type) -> + fun(Value) -> + Missing_field_error = {decode_error, + <<"field"/utf8>>, + <<"nothing"/utf8>>, + []}, + gleam@result:'try'( + gleam_stdlib:decode_field(Value, Name), + fun(Maybe_inner) -> _pipe = Maybe_inner, + _pipe@1 = gleam@option:to_result(_pipe, [Missing_field_error]), + _pipe@2 = gleam@result:'try'(_pipe@1, Inner_type), + map_errors( + _pipe@2, + fun(_capture) -> push_path(_capture, Name) end + ) end + ) + end. + +-spec optional_field( + any(), + fun((dynamic_()) -> {ok, DVO} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, gleam@option:option(DVO)} | + {error, list(decode_error())}). +optional_field(Name, Inner_type) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_field(Value, Name), + fun(Maybe_inner) -> case Maybe_inner of + none -> + {ok, none}; + + {some, Dynamic_inner} -> + _pipe = Dynamic_inner, + _pipe@1 = gleam_stdlib:decode_option(_pipe, Inner_type), + map_errors( + _pipe@1, + fun(_capture) -> push_path(_capture, Name) end + ) + end end + ) + end. + +-spec element( + integer(), + fun((dynamic_()) -> {ok, DVW} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, DVW} | {error, list(decode_error())}). +element(Index, Inner_type) -> + fun(Data) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple(Data), + fun(Tuple) -> + Size = gleam_stdlib:size_of_tuple(Tuple), + gleam@result:'try'(case Index >= 0 of + true -> + case Index < Size of + true -> + gleam_stdlib:tuple_get(Tuple, Index); + + false -> + at_least_decode_tuple_error(Index + 1, Data) + end; + + false -> + case gleam@int:absolute_value(Index) =< Size of + true -> + gleam_stdlib:tuple_get(Tuple, Size + Index); + + false -> + at_least_decode_tuple_error( + gleam@int:absolute_value(Index), + Data + ) + end + end, fun(Data@1) -> _pipe = Inner_type(Data@1), + map_errors( + _pipe, + fun(_capture) -> push_path(_capture, Index) end + ) end) + end + ) + end. + +-spec tuple_errors({ok, any()} | {error, list(decode_error())}, binary()) -> list(decode_error()). +tuple_errors(Result, Name) -> + case Result of + {ok, _} -> + []; + + {error, Errors} -> + gleam@list:map( + Errors, + fun(_capture) -> push_path(_capture, Name) end + ) + end. + +-spec tuple2( + fun((dynamic_()) -> {ok, DWW} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DWY} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {DWW, DWY}} | {error, list(decode_error())}). +tuple2(Decode1, Decode2) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple2(Value), + fun(_use0) -> + {A, B} = _use0, + case {Decode1(A), Decode2(B)} of + {{ok, A@1}, {ok, B@1}} -> + {ok, {A@1, B@1}}; + + {A@2, B@2} -> + _pipe = tuple_errors(A@2, <<"0"/utf8>>), + _pipe@1 = gleam@list:append( + _pipe, + tuple_errors(B@2, <<"1"/utf8>>) + ), + {error, _pipe@1} + end + end + ) + end. + +-spec tuple3( + fun((dynamic_()) -> {ok, DXB} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXD} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXF} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {DXB, DXD, DXF}} | {error, list(decode_error())}). +tuple3(Decode1, Decode2, Decode3) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple3(Value), + fun(_use0) -> + {A, B, C} = _use0, + case {Decode1(A), Decode2(B), Decode3(C)} of + {{ok, A@1}, {ok, B@1}, {ok, C@1}} -> + {ok, {A@1, B@1, C@1}}; + + {A@2, B@2, C@2} -> + _pipe = tuple_errors(A@2, <<"0"/utf8>>), + _pipe@1 = gleam@list:append( + _pipe, + tuple_errors(B@2, <<"1"/utf8>>) + ), + _pipe@2 = gleam@list:append( + _pipe@1, + tuple_errors(C@2, <<"2"/utf8>>) + ), + {error, _pipe@2} + end + end + ) + end. + +-spec tuple4( + fun((dynamic_()) -> {ok, DXI} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXK} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXM} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXO} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {DXI, DXK, DXM, DXO}} | + {error, list(decode_error())}). +tuple4(Decode1, Decode2, Decode3, Decode4) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple4(Value), + fun(_use0) -> + {A, B, C, D} = _use0, + case {Decode1(A), Decode2(B), Decode3(C), Decode4(D)} of + {{ok, A@1}, {ok, B@1}, {ok, C@1}, {ok, D@1}} -> + {ok, {A@1, B@1, C@1, D@1}}; + + {A@2, B@2, C@2, D@2} -> + _pipe = tuple_errors(A@2, <<"0"/utf8>>), + _pipe@1 = gleam@list:append( + _pipe, + tuple_errors(B@2, <<"1"/utf8>>) + ), + _pipe@2 = gleam@list:append( + _pipe@1, + tuple_errors(C@2, <<"2"/utf8>>) + ), + _pipe@3 = gleam@list:append( + _pipe@2, + tuple_errors(D@2, <<"3"/utf8>>) + ), + {error, _pipe@3} + end + end + ) + end. + +-spec tuple5( + fun((dynamic_()) -> {ok, DXR} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXT} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXV} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXX} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DXZ} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {DXR, DXT, DXV, DXX, DXZ}} | + {error, list(decode_error())}). +tuple5(Decode1, Decode2, Decode3, Decode4, Decode5) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple5(Value), + fun(_use0) -> + {A, B, C, D, E} = _use0, + case {Decode1(A), + Decode2(B), + Decode3(C), + Decode4(D), + Decode5(E)} of + {{ok, A@1}, {ok, B@1}, {ok, C@1}, {ok, D@1}, {ok, E@1}} -> + {ok, {A@1, B@1, C@1, D@1, E@1}}; + + {A@2, B@2, C@2, D@2, E@2} -> + _pipe = tuple_errors(A@2, <<"0"/utf8>>), + _pipe@1 = gleam@list:append( + _pipe, + tuple_errors(B@2, <<"1"/utf8>>) + ), + _pipe@2 = gleam@list:append( + _pipe@1, + tuple_errors(C@2, <<"2"/utf8>>) + ), + _pipe@3 = gleam@list:append( + _pipe@2, + tuple_errors(D@2, <<"3"/utf8>>) + ), + _pipe@4 = gleam@list:append( + _pipe@3, + tuple_errors(E@2, <<"4"/utf8>>) + ), + {error, _pipe@4} + end + end + ) + end. + +-spec tuple6( + fun((dynamic_()) -> {ok, DYC} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYE} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYG} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYI} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYK} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYM} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, {DYC, DYE, DYG, DYI, DYK, DYM}} | + {error, list(decode_error())}). +tuple6(Decode1, Decode2, Decode3, Decode4, Decode5, Decode6) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_tuple6(Value), + fun(_use0) -> + {A, B, C, D, E, F} = _use0, + case {Decode1(A), + Decode2(B), + Decode3(C), + Decode4(D), + Decode5(E), + Decode6(F)} of + {{ok, A@1}, + {ok, B@1}, + {ok, C@1}, + {ok, D@1}, + {ok, E@1}, + {ok, F@1}} -> + {ok, {A@1, B@1, C@1, D@1, E@1, F@1}}; + + {A@2, B@2, C@2, D@2, E@2, F@2} -> + _pipe = tuple_errors(A@2, <<"0"/utf8>>), + _pipe@1 = gleam@list:append( + _pipe, + tuple_errors(B@2, <<"1"/utf8>>) + ), + _pipe@2 = gleam@list:append( + _pipe@1, + tuple_errors(C@2, <<"2"/utf8>>) + ), + _pipe@3 = gleam@list:append( + _pipe@2, + tuple_errors(D@2, <<"3"/utf8>>) + ), + _pipe@4 = gleam@list:append( + _pipe@3, + tuple_errors(E@2, <<"4"/utf8>>) + ), + _pipe@5 = gleam@list:append( + _pipe@4, + tuple_errors(F@2, <<"5"/utf8>>) + ), + {error, _pipe@5} + end + end + ) + end. + +-spec dict( + fun((dynamic_()) -> {ok, DYP} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYR} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, gleam@dict:dict(DYP, DYR)} | + {error, list(decode_error())}). +dict(Key_type, Value_type) -> + fun(Value) -> + gleam@result:'try'( + gleam_stdlib:decode_map(Value), + fun(Map) -> + gleam@result:'try'( + begin + _pipe = Map, + _pipe@1 = gleam@dict:to_list(_pipe), + gleam@list:try_map( + _pipe@1, + fun(Pair) -> + {K, V} = Pair, + gleam@result:'try'( + begin + _pipe@2 = Key_type(K), + map_errors( + _pipe@2, + fun(_capture) -> + push_path( + _capture, + <<"keys"/utf8>> + ) + end + ) + end, + fun(K@1) -> + gleam@result:'try'( + begin + _pipe@3 = Value_type(V), + map_errors( + _pipe@3, + fun(_capture@1) -> + push_path( + _capture@1, + <<"values"/utf8>> + ) + end + ) + end, + fun(V@1) -> {ok, {K@1, V@1}} end + ) + end + ) + end + ) + end, + fun(Pairs) -> {ok, gleam@dict:from_list(Pairs)} end + ) + end + ) + end. + +-spec map( + fun((dynamic_()) -> {ok, DYW} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DYY} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, gleam@dict:dict(DYW, DYY)} | + {error, list(decode_error())}). +map(Key_type, Value_type) -> + dict(Key_type, Value_type). + +-spec decode2( + fun((DZP, DZQ) -> DZR), + fun((dynamic_()) -> {ok, DZP} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DZQ} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, DZR} | {error, list(decode_error())}). +decode2(Constructor, T1, T2) -> + fun(Value) -> case {T1(Value), T2(Value)} of + {{ok, A}, {ok, B}} -> + {ok, Constructor(A, B)}; + + {A@1, B@1} -> + {error, gleam@list:concat([all_errors(A@1), all_errors(B@1)])} + end end. + +-spec decode3( + fun((DZV, DZW, DZX) -> DZY), + fun((dynamic_()) -> {ok, DZV} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DZW} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, DZX} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, DZY} | {error, list(decode_error())}). +decode3(Constructor, T1, T2, T3) -> + fun(Value) -> case {T1(Value), T2(Value), T3(Value)} of + {{ok, A}, {ok, B}, {ok, C}} -> + {ok, Constructor(A, B, C)}; + + {A@1, B@1, C@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), all_errors(B@1), all_errors(C@1)] + )} + end end. + +-spec decode4( + fun((EAD, EAE, EAF, EAG) -> EAH), + fun((dynamic_()) -> {ok, EAD} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAE} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAF} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAG} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, EAH} | {error, list(decode_error())}). +decode4(Constructor, T1, T2, T3, T4) -> + fun(X) -> case {T1(X), T2(X), T3(X), T4(X)} of + {{ok, A}, {ok, B}, {ok, C}, {ok, D}} -> + {ok, Constructor(A, B, C, D)}; + + {A@1, B@1, C@1, D@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1)] + )} + end end. + +-spec decode5( + fun((EAN, EAO, EAP, EAQ, EAR) -> EAS), + fun((dynamic_()) -> {ok, EAN} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAO} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAP} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAQ} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EAR} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, EAS} | {error, list(decode_error())}). +decode5(Constructor, T1, T2, T3, T4, T5) -> + fun(X) -> case {T1(X), T2(X), T3(X), T4(X), T5(X)} of + {{ok, A}, {ok, B}, {ok, C}, {ok, D}, {ok, E}} -> + {ok, Constructor(A, B, C, D, E)}; + + {A@1, B@1, C@1, D@1, E@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1), + all_errors(E@1)] + )} + end end. + +-spec decode6( + fun((EAZ, EBA, EBB, EBC, EBD, EBE) -> EBF), + fun((dynamic_()) -> {ok, EAZ} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBA} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBB} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBC} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBD} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBE} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, EBF} | {error, list(decode_error())}). +decode6(Constructor, T1, T2, T3, T4, T5, T6) -> + fun(X) -> case {T1(X), T2(X), T3(X), T4(X), T5(X), T6(X)} of + {{ok, A}, {ok, B}, {ok, C}, {ok, D}, {ok, E}, {ok, F}} -> + {ok, Constructor(A, B, C, D, E, F)}; + + {A@1, B@1, C@1, D@1, E@1, F@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1), + all_errors(E@1), + all_errors(F@1)] + )} + end end. + +-spec decode7( + fun((EBN, EBO, EBP, EBQ, EBR, EBS, EBT) -> EBU), + fun((dynamic_()) -> {ok, EBN} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBO} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBP} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBQ} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBR} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBS} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EBT} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, EBU} | {error, list(decode_error())}). +decode7(Constructor, T1, T2, T3, T4, T5, T6, T7) -> + fun(X) -> case {T1(X), T2(X), T3(X), T4(X), T5(X), T6(X), T7(X)} of + {{ok, A}, {ok, B}, {ok, C}, {ok, D}, {ok, E}, {ok, F}, {ok, G}} -> + {ok, Constructor(A, B, C, D, E, F, G)}; + + {A@1, B@1, C@1, D@1, E@1, F@1, G@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1), + all_errors(E@1), + all_errors(F@1), + all_errors(G@1)] + )} + end end. + +-spec decode8( + fun((ECD, ECE, ECF, ECG, ECH, ECI, ECJ, ECK) -> ECL), + fun((dynamic_()) -> {ok, ECD} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECE} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECF} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECG} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECH} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECI} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECJ} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECK} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, ECL} | {error, list(decode_error())}). +decode8(Constructor, T1, T2, T3, T4, T5, T6, T7, T8) -> + fun(X) -> case {T1(X), T2(X), T3(X), T4(X), T5(X), T6(X), T7(X), T8(X)} of + {{ok, A}, + {ok, B}, + {ok, C}, + {ok, D}, + {ok, E}, + {ok, F}, + {ok, G}, + {ok, H}} -> + {ok, Constructor(A, B, C, D, E, F, G, H)}; + + {A@1, B@1, C@1, D@1, E@1, F@1, G@1, H@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1), + all_errors(E@1), + all_errors(F@1), + all_errors(G@1), + all_errors(H@1)] + )} + end end. + +-spec decode9( + fun((ECV, ECW, ECX, ECY, ECZ, EDA, EDB, EDC, EDD) -> EDE), + fun((dynamic_()) -> {ok, ECV} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECW} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECX} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECY} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, ECZ} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EDA} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EDB} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EDC} | {error, list(decode_error())}), + fun((dynamic_()) -> {ok, EDD} | {error, list(decode_error())}) +) -> fun((dynamic_()) -> {ok, EDE} | {error, list(decode_error())}). +decode9(Constructor, T1, T2, T3, T4, T5, T6, T7, T8, T9) -> + fun(X) -> + case {T1(X), T2(X), T3(X), T4(X), T5(X), T6(X), T7(X), T8(X), T9(X)} of + {{ok, A}, + {ok, B}, + {ok, C}, + {ok, D}, + {ok, E}, + {ok, F}, + {ok, G}, + {ok, H}, + {ok, I}} -> + {ok, Constructor(A, B, C, D, E, F, G, H, I)}; + + {A@1, B@1, C@1, D@1, E@1, F@1, G@1, H@1, I@1} -> + {error, + gleam@list:concat( + [all_errors(A@1), + all_errors(B@1), + all_errors(C@1), + all_errors(D@1), + all_errors(E@1), + all_errors(F@1), + all_errors(G@1), + all_errors(H@1), + all_errors(I@1)] + )} + end + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache Binary files differnew file mode 100644 index 0000000..94e0f92 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta Binary files differnew file mode 100644 index 0000000..f10b39f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.erl new file mode 100644 index 0000000..50e3ea3 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@float.erl @@ -0,0 +1,181 @@ +-module(gleam@float). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([parse/1, to_string/1, compare/2, min/2, max/2, clamp/3, ceiling/1, floor/1, round/1, truncate/1, absolute_value/1, loosely_compare/3, loosely_equals/3, power/2, square_root/1, negate/1, sum/1, product/1, random/2, divide/2, add/2, multiply/2, subtract/2]). + +-spec parse(binary()) -> {ok, float()} | {error, nil}. +parse(String) -> + gleam_stdlib:parse_float(String). + +-spec to_string(float()) -> binary(). +to_string(X) -> + gleam_stdlib:float_to_string(X). + +-spec compare(float(), float()) -> gleam@order:order(). +compare(A, B) -> + case A =:= B of + true -> + eq; + + false -> + case A < B of + true -> + lt; + + false -> + gt + end + end. + +-spec min(float(), float()) -> float(). +min(A, B) -> + case A < B of + true -> + A; + + false -> + B + end. + +-spec max(float(), float()) -> float(). +max(A, B) -> + case A > B of + true -> + A; + + false -> + B + end. + +-spec clamp(float(), float(), float()) -> float(). +clamp(X, Min_bound, Max_bound) -> + _pipe = X, + _pipe@1 = min(_pipe, Max_bound), + max(_pipe@1, Min_bound). + +-spec ceiling(float()) -> float(). +ceiling(X) -> + math:ceil(X). + +-spec floor(float()) -> float(). +floor(X) -> + math:floor(X). + +-spec round(float()) -> integer(). +round(X) -> + erlang:round(X). + +-spec truncate(float()) -> integer(). +truncate(X) -> + erlang:trunc(X). + +-spec absolute_value(float()) -> float(). +absolute_value(X) -> + case X >= +0.0 of + true -> + X; + + _ -> + +0.0 - X + end. + +-spec loosely_compare(float(), float(), float()) -> gleam@order:order(). +loosely_compare(A, B, Tolerance) -> + Difference = absolute_value(A - B), + case Difference =< Tolerance of + true -> + eq; + + false -> + compare(A, B) + end. + +-spec loosely_equals(float(), float(), float()) -> boolean(). +loosely_equals(A, B, Tolerance) -> + Difference = absolute_value(A - B), + Difference =< Tolerance. + +-spec power(float(), float()) -> {ok, float()} | {error, nil}. +power(Base, Exponent) -> + Fractional = (ceiling(Exponent) - Exponent) > +0.0, + case ((Base < +0.0) andalso Fractional) orelse ((Base =:= +0.0) andalso (Exponent + < +0.0)) of + true -> + {error, nil}; + + false -> + {ok, math:pow(Base, Exponent)} + end. + +-spec square_root(float()) -> {ok, float()} | {error, nil}. +square_root(X) -> + power(X, 0.5). + +-spec negate(float()) -> float(). +negate(X) -> + -1.0 * X. + +-spec do_sum(list(float()), float()) -> float(). +do_sum(Numbers, Initial) -> + case Numbers of + [] -> + Initial; + + [X | Rest] -> + do_sum(Rest, X + Initial) + end. + +-spec sum(list(float())) -> float(). +sum(Numbers) -> + _pipe = Numbers, + do_sum(_pipe, +0.0). + +-spec do_product(list(float()), float()) -> float(). +do_product(Numbers, Initial) -> + case Numbers of + [] -> + Initial; + + [X | Rest] -> + do_product(Rest, X * Initial) + end. + +-spec product(list(float())) -> float(). +product(Numbers) -> + case Numbers of + [] -> + 1.0; + + _ -> + do_product(Numbers, 1.0) + end. + +-spec random(float(), float()) -> float(). +random(Min, Max) -> + (rand:uniform() * (Max - Min)) + Min. + +-spec divide(float(), float()) -> {ok, float()} | {error, nil}. +divide(A, B) -> + case B of + +0.0 -> + {error, nil}; + + B@1 -> + {ok, case B@1 of + +0.0 -> +0.0; + -0.0 -> -0.0; + Gleam@denominator -> A / Gleam@denominator + end} + end. + +-spec add(float(), float()) -> float(). +add(A, B) -> + A + B. + +-spec multiply(float(), float()) -> float(). +multiply(A, B) -> + A * B. + +-spec subtract(float(), float()) -> float(). +subtract(A, B) -> + A - B. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache Binary files differnew file mode 100644 index 0000000..f9fe0f4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta Binary files differnew file mode 100644 index 0000000..ffb4624 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.erl new file mode 100644 index 0000000..524293a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@function.erl @@ -0,0 +1,67 @@ +-module(gleam@function). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([compose/2, curry2/1, curry3/1, curry4/1, curry5/1, curry6/1, flip/1, identity/1, constant/1, tap/2, apply1/2, apply2/3, apply3/4]). + +-spec compose(fun((DFV) -> DFW), fun((DFW) -> DFX)) -> fun((DFV) -> DFX). +compose(Fun1, Fun2) -> + fun(A) -> Fun2(Fun1(A)) end. + +-spec curry2(fun((DFY, DFZ) -> DGA)) -> fun((DFY) -> fun((DFZ) -> DGA)). +curry2(Fun) -> + fun(A) -> fun(B) -> Fun(A, B) end end. + +-spec curry3(fun((DGC, DGD, DGE) -> DGF)) -> fun((DGC) -> fun((DGD) -> fun((DGE) -> DGF))). +curry3(Fun) -> + fun(A) -> fun(B) -> fun(C) -> Fun(A, B, C) end end end. + +-spec curry4(fun((DGH, DGI, DGJ, DGK) -> DGL)) -> fun((DGH) -> fun((DGI) -> fun((DGJ) -> fun((DGK) -> DGL)))). +curry4(Fun) -> + fun(A) -> fun(B) -> fun(C) -> fun(D) -> Fun(A, B, C, D) end end end end. + +-spec curry5(fun((DGN, DGO, DGP, DGQ, DGR) -> DGS)) -> fun((DGN) -> fun((DGO) -> fun((DGP) -> fun((DGQ) -> fun((DGR) -> DGS))))). +curry5(Fun) -> + fun(A) -> + fun(B) -> + fun(C) -> fun(D) -> fun(E) -> Fun(A, B, C, D, E) end end end + end + end. + +-spec curry6(fun((DGU, DGV, DGW, DGX, DGY, DGZ) -> DHA)) -> fun((DGU) -> fun((DGV) -> fun((DGW) -> fun((DGX) -> fun((DGY) -> fun((DGZ) -> DHA)))))). +curry6(Fun) -> + fun(A) -> + fun(B) -> + fun(C) -> + fun(D) -> fun(E) -> fun(F) -> Fun(A, B, C, D, E, F) end end end + end + end + end. + +-spec flip(fun((DHC, DHD) -> DHE)) -> fun((DHD, DHC) -> DHE). +flip(Fun) -> + fun(B, A) -> Fun(A, B) end. + +-spec identity(DHF) -> DHF. +identity(X) -> + X. + +-spec constant(DHG) -> fun((any()) -> DHG). +constant(Value) -> + fun(_) -> Value end. + +-spec tap(DHI, fun((DHI) -> any())) -> DHI. +tap(Arg, Effect) -> + Effect(Arg), + Arg. + +-spec apply1(fun((DHK) -> DHL), DHK) -> DHL. +apply1(Fun, Arg1) -> + Fun(Arg1). + +-spec apply2(fun((DHM, DHN) -> DHO), DHM, DHN) -> DHO. +apply2(Fun, Arg1, Arg2) -> + Fun(Arg1, Arg2). + +-spec apply3(fun((DHP, DHQ, DHR) -> DHS), DHP, DHQ, DHR) -> DHS. +apply3(Fun, Arg1, Arg2, Arg3) -> + Fun(Arg1, Arg2, Arg3). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache Binary files differnew file mode 100644 index 0000000..0afeaae --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta Binary files differnew file mode 100644 index 0000000..2d987e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.erl new file mode 100644 index 0000000..b1960b7 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@int.erl @@ -0,0 +1,332 @@ +-module(gleam@int). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([absolute_value/1, parse/1, base_parse/2, to_string/1, to_base_string/2, to_base2/1, to_base8/1, to_base16/1, to_base36/1, to_float/1, power/2, square_root/1, compare/2, min/2, max/2, clamp/3, is_even/1, is_odd/1, negate/1, sum/1, product/1, digits/2, undigits/2, random/2, divide/2, remainder/2, modulo/2, floor_divide/2, add/2, multiply/2, subtract/2, bitwise_and/2, bitwise_not/1, bitwise_or/2, bitwise_exclusive_or/2, bitwise_shift_left/2, bitwise_shift_right/2]). +-export_type([invalid_base/0]). + +-type invalid_base() :: invalid_base. + +-spec absolute_value(integer()) -> integer(). +absolute_value(X) -> + case X >= 0 of + true -> + X; + + false -> + X * -1 + end. + +-spec parse(binary()) -> {ok, integer()} | {error, nil}. +parse(String) -> + gleam_stdlib:parse_int(String). + +-spec base_parse(binary(), integer()) -> {ok, integer()} | {error, nil}. +base_parse(String, Base) -> + case (Base >= 2) andalso (Base =< 36) of + true -> + gleam_stdlib:int_from_base_string(String, Base); + + false -> + {error, nil} + end. + +-spec to_string(integer()) -> binary(). +to_string(X) -> + erlang:integer_to_binary(X). + +-spec to_base_string(integer(), integer()) -> {ok, binary()} | + {error, invalid_base()}. +to_base_string(X, Base) -> + case (Base >= 2) andalso (Base =< 36) of + true -> + {ok, erlang:integer_to_binary(X, Base)}; + + false -> + {error, invalid_base} + end. + +-spec to_base2(integer()) -> binary(). +to_base2(X) -> + erlang:integer_to_binary(X, 2). + +-spec to_base8(integer()) -> binary(). +to_base8(X) -> + erlang:integer_to_binary(X, 8). + +-spec to_base16(integer()) -> binary(). +to_base16(X) -> + erlang:integer_to_binary(X, 16). + +-spec to_base36(integer()) -> binary(). +to_base36(X) -> + erlang:integer_to_binary(X, 36). + +-spec to_float(integer()) -> float(). +to_float(X) -> + erlang:float(X). + +-spec power(integer(), float()) -> {ok, float()} | {error, nil}. +power(Base, Exponent) -> + _pipe = Base, + _pipe@1 = to_float(_pipe), + gleam@float:power(_pipe@1, Exponent). + +-spec square_root(integer()) -> {ok, float()} | {error, nil}. +square_root(X) -> + _pipe = X, + _pipe@1 = to_float(_pipe), + gleam@float:square_root(_pipe@1). + +-spec compare(integer(), integer()) -> gleam@order:order(). +compare(A, B) -> + case A =:= B of + true -> + eq; + + false -> + case A < B of + true -> + lt; + + false -> + gt + end + end. + +-spec min(integer(), integer()) -> integer(). +min(A, B) -> + case A < B of + true -> + A; + + false -> + B + end. + +-spec max(integer(), integer()) -> integer(). +max(A, B) -> + case A > B of + true -> + A; + + false -> + B + end. + +-spec clamp(integer(), integer(), integer()) -> integer(). +clamp(X, Min_bound, Max_bound) -> + _pipe = X, + _pipe@1 = min(_pipe, Max_bound), + max(_pipe@1, Min_bound). + +-spec is_even(integer()) -> boolean(). +is_even(X) -> + (X rem 2) =:= 0. + +-spec is_odd(integer()) -> boolean(). +is_odd(X) -> + (X rem 2) /= 0. + +-spec negate(integer()) -> integer(). +negate(X) -> + -1 * X. + +-spec do_sum(list(integer()), integer()) -> integer(). +do_sum(Numbers, Initial) -> + case Numbers of + [] -> + Initial; + + [X | Rest] -> + do_sum(Rest, X + Initial) + end. + +-spec sum(list(integer())) -> integer(). +sum(Numbers) -> + _pipe = Numbers, + do_sum(_pipe, 0). + +-spec do_product(list(integer()), integer()) -> integer(). +do_product(Numbers, Initial) -> + case Numbers of + [] -> + Initial; + + [X | Rest] -> + do_product(Rest, X * Initial) + end. + +-spec product(list(integer())) -> integer(). +product(Numbers) -> + case Numbers of + [] -> + 1; + + _ -> + do_product(Numbers, 1) + end. + +-spec do_digits(integer(), integer(), list(integer())) -> list(integer()). +do_digits(X, Base, Acc) -> + case absolute_value(X) < Base of + true -> + [X | Acc]; + + false -> + do_digits(case Base of + 0 -> 0; + Gleam@denominator -> X div Gleam@denominator + end, Base, [case Base of + 0 -> 0; + Gleam@denominator@1 -> X rem Gleam@denominator@1 + end | Acc]) + end. + +-spec digits(integer(), integer()) -> {ok, list(integer())} | + {error, invalid_base()}. +digits(X, Base) -> + case Base < 2 of + true -> + {error, invalid_base}; + + false -> + {ok, do_digits(X, Base, [])} + end. + +-spec do_undigits(list(integer()), integer(), integer()) -> {ok, integer()} | + {error, invalid_base()}. +do_undigits(Numbers, Base, Acc) -> + case Numbers of + [] -> + {ok, Acc}; + + [Digit | _] when Digit >= Base -> + {error, invalid_base}; + + [Digit@1 | Rest] -> + do_undigits(Rest, Base, (Acc * Base) + Digit@1) + end. + +-spec undigits(list(integer()), integer()) -> {ok, integer()} | + {error, invalid_base()}. +undigits(Numbers, Base) -> + case Base < 2 of + true -> + {error, invalid_base}; + + false -> + do_undigits(Numbers, Base, 0) + end. + +-spec random(integer(), integer()) -> integer(). +random(Min, Max) -> + _pipe = gleam@float:random(to_float(Min), to_float(Max)), + _pipe@1 = gleam@float:floor(_pipe), + gleam@float:round(_pipe@1). + +-spec divide(integer(), integer()) -> {ok, integer()} | {error, nil}. +divide(Dividend, Divisor) -> + case Divisor of + 0 -> + {error, nil}; + + Divisor@1 -> + {ok, case Divisor@1 of + 0 -> 0; + Gleam@denominator -> Dividend div Gleam@denominator + end} + end. + +-spec remainder(integer(), integer()) -> {ok, integer()} | {error, nil}. +remainder(Dividend, Divisor) -> + case Divisor of + 0 -> + {error, nil}; + + Divisor@1 -> + {ok, case Divisor@1 of + 0 -> 0; + Gleam@denominator -> Dividend rem Gleam@denominator + end} + end. + +-spec modulo(integer(), integer()) -> {ok, integer()} | {error, nil}. +modulo(Dividend, Divisor) -> + case Divisor of + 0 -> + {error, nil}; + + _ -> + Remainder = case Divisor of + 0 -> 0; + Gleam@denominator -> Dividend rem Gleam@denominator + end, + case (Remainder * Divisor) < 0 of + true -> + {ok, Remainder + Divisor}; + + false -> + {ok, Remainder} + end + end. + +-spec floor_divide(integer(), integer()) -> {ok, integer()} | {error, nil}. +floor_divide(Dividend, Divisor) -> + case Divisor of + 0 -> + {error, nil}; + + Divisor@1 -> + case ((Dividend * Divisor@1) < 0) andalso ((case Divisor@1 of + 0 -> 0; + Gleam@denominator -> Dividend rem Gleam@denominator + end) /= 0) of + true -> + {ok, (case Divisor@1 of + 0 -> 0; + Gleam@denominator@1 -> Dividend div Gleam@denominator@1 + end) - 1}; + + false -> + {ok, case Divisor@1 of + 0 -> 0; + Gleam@denominator@2 -> Dividend div Gleam@denominator@2 + end} + end + end. + +-spec add(integer(), integer()) -> integer(). +add(A, B) -> + A + B. + +-spec multiply(integer(), integer()) -> integer(). +multiply(A, B) -> + A * B. + +-spec subtract(integer(), integer()) -> integer(). +subtract(A, B) -> + A - B. + +-spec bitwise_and(integer(), integer()) -> integer(). +bitwise_and(X, Y) -> + erlang:'band'(X, Y). + +-spec bitwise_not(integer()) -> integer(). +bitwise_not(X) -> + erlang:'bnot'(X). + +-spec bitwise_or(integer(), integer()) -> integer(). +bitwise_or(X, Y) -> + erlang:'bor'(X, Y). + +-spec bitwise_exclusive_or(integer(), integer()) -> integer(). +bitwise_exclusive_or(X, Y) -> + erlang:'bxor'(X, Y). + +-spec bitwise_shift_left(integer(), integer()) -> integer(). +bitwise_shift_left(X, Y) -> + erlang:'bsl'(X, Y). + +-spec bitwise_shift_right(integer(), integer()) -> integer(). +bitwise_shift_right(X, Y) -> + erlang:'bsr'(X, Y). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache Binary files differnew file mode 100644 index 0000000..3174256 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta Binary files differnew file mode 100644 index 0000000..06ce652 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.erl new file mode 100644 index 0000000..fbbe91f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@io.erl @@ -0,0 +1,27 @@ +-module(gleam@io). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([print/1, print_error/1, println/1, println_error/1, debug/1]). + +-spec print(binary()) -> nil. +print(String) -> + gleam_stdlib:print(String). + +-spec print_error(binary()) -> nil. +print_error(String) -> + gleam_stdlib:print_error(String). + +-spec println(binary()) -> nil. +println(String) -> + gleam_stdlib:println(String). + +-spec println_error(binary()) -> nil. +println_error(String) -> + gleam_stdlib:println_error(String). + +-spec debug(FBV) -> FBV. +debug(Term) -> + _pipe = Term, + _pipe@1 = gleam@string:inspect(_pipe), + gleam_stdlib:println_error(_pipe@1), + Term. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache Binary files differnew file mode 100644 index 0000000..afd5ec8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache_meta Binary files differnew file mode 100644 index 0000000..2dcb80d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.erl new file mode 100644 index 0000000..d107b2c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@iterator.erl @@ -0,0 +1,744 @@ +-module(gleam@iterator). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([unfold/2, repeatedly/1, repeat/1, from_list/1, transform/3, fold/3, run/1, to_list/1, step/1, take/2, drop/2, map/2, map2/3, append/2, flatten/1, concat/1, flat_map/2, filter/2, cycle/1, find/2, index/1, iterate/2, take_while/2, drop_while/2, scan/3, zip/2, chunk/2, sized_chunk/2, intersperse/2, any/2, all/2, group/2, reduce/2, last/1, empty/0, once/1, range/2, single/1, interleave/2, fold_until/3, try_fold/3, first/1, at/2, length/1, each/2, yield/2]). +-export_type([action/1, iterator/1, step/2, chunk/2, sized_chunk/1]). + +-type action(BPF) :: stop | {continue, BPF, fun(() -> action(BPF))}. + +-opaque iterator(BPG) :: {iterator, fun(() -> action(BPG))}. + +-type step(BPH, BPI) :: {next, BPH, BPI} | done. + +-type chunk(BPJ, BPK) :: {another_by, + list(BPJ), + BPK, + BPJ, + fun(() -> action(BPJ))} | + {last_by, list(BPJ)}. + +-type sized_chunk(BPL) :: {another, list(BPL), fun(() -> action(BPL))} | + {last, list(BPL)} | + no_more. + +-spec stop() -> action(any()). +stop() -> + stop. + +-spec do_unfold(BPO, fun((BPO) -> step(BPP, BPO))) -> fun(() -> action(BPP)). +do_unfold(Initial, F) -> + fun() -> case F(Initial) of + {next, X, Acc} -> + {continue, X, do_unfold(Acc, F)}; + + done -> + stop + end end. + +-spec unfold(BPT, fun((BPT) -> step(BPU, BPT))) -> iterator(BPU). +unfold(Initial, F) -> + _pipe = Initial, + _pipe@1 = do_unfold(_pipe, F), + {iterator, _pipe@1}. + +-spec repeatedly(fun(() -> BPY)) -> iterator(BPY). +repeatedly(F) -> + unfold(nil, fun(_) -> {next, F(), nil} end). + +-spec repeat(BQA) -> iterator(BQA). +repeat(X) -> + repeatedly(fun() -> X end). + +-spec from_list(list(BQC)) -> iterator(BQC). +from_list(List) -> + Yield = fun(Acc) -> case Acc of + [] -> + done; + + [Head | Tail] -> + {next, Head, Tail} + end end, + unfold(List, Yield). + +-spec do_transform( + fun(() -> action(BQF)), + BQH, + fun((BQH, BQF) -> step(BQI, BQH)) +) -> fun(() -> action(BQI)). +do_transform(Continuation, State, F) -> + fun() -> case Continuation() of + stop -> + stop; + + {continue, El, Next} -> + case F(State, El) of + done -> + stop; + + {next, Yield, Next_state} -> + {continue, Yield, do_transform(Next, Next_state, F)} + end + end end. + +-spec transform(iterator(BQM), BQO, fun((BQO, BQM) -> step(BQP, BQO))) -> iterator(BQP). +transform(Iterator, Initial, F) -> + _pipe = do_transform(erlang:element(2, Iterator), Initial, F), + {iterator, _pipe}. + +-spec do_fold(fun(() -> action(BQT)), fun((BQV, BQT) -> BQV), BQV) -> BQV. +do_fold(Continuation, F, Accumulator) -> + case Continuation() of + {continue, Elem, Next} -> + do_fold(Next, F, F(Accumulator, Elem)); + + stop -> + Accumulator + end. + +-spec fold(iterator(BQW), BQY, fun((BQY, BQW) -> BQY)) -> BQY. +fold(Iterator, Initial, F) -> + _pipe = erlang:element(2, Iterator), + do_fold(_pipe, F, Initial). + +-spec run(iterator(any())) -> nil. +run(Iterator) -> + fold(Iterator, nil, fun(_, _) -> nil end). + +-spec to_list(iterator(BRB)) -> list(BRB). +to_list(Iterator) -> + _pipe = Iterator, + _pipe@1 = fold(_pipe, [], fun(Acc, E) -> [E | Acc] end), + gleam@list:reverse(_pipe@1). + +-spec step(iterator(BRE)) -> step(BRE, iterator(BRE)). +step(Iterator) -> + case (erlang:element(2, Iterator))() of + stop -> + done; + + {continue, E, A} -> + {next, E, {iterator, A}} + end. + +-spec do_take(fun(() -> action(BRJ)), integer()) -> fun(() -> action(BRJ)). +do_take(Continuation, Desired) -> + fun() -> case Desired > 0 of + false -> + stop; + + true -> + case Continuation() of + stop -> + stop; + + {continue, E, Next} -> + {continue, E, do_take(Next, Desired - 1)} + end + end end. + +-spec take(iterator(BRM), integer()) -> iterator(BRM). +take(Iterator, Desired) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_take(_pipe, Desired), + {iterator, _pipe@1}. + +-spec do_drop(fun(() -> action(BRP)), integer()) -> action(BRP). +do_drop(Continuation, Desired) -> + case Continuation() of + stop -> + stop; + + {continue, E, Next} -> + case Desired > 0 of + true -> + do_drop(Next, Desired - 1); + + false -> + {continue, E, Next} + end + end. + +-spec drop(iterator(BRS), integer()) -> iterator(BRS). +drop(Iterator, Desired) -> + _pipe = fun() -> do_drop(erlang:element(2, Iterator), Desired) end, + {iterator, _pipe}. + +-spec do_map(fun(() -> action(BRV)), fun((BRV) -> BRX)) -> fun(() -> action(BRX)). +do_map(Continuation, F) -> + fun() -> case Continuation() of + stop -> + stop; + + {continue, E, Continuation@1} -> + {continue, F(E), do_map(Continuation@1, F)} + end end. + +-spec map(iterator(BRZ), fun((BRZ) -> BSB)) -> iterator(BSB). +map(Iterator, F) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_map(_pipe, F), + {iterator, _pipe@1}. + +-spec do_map2( + fun(() -> action(BSD)), + fun(() -> action(BSF)), + fun((BSD, BSF) -> BSH) +) -> fun(() -> action(BSH)). +do_map2(Continuation1, Continuation2, Fun) -> + fun() -> case Continuation1() of + stop -> + stop; + + {continue, A, Next_a} -> + case Continuation2() of + stop -> + stop; + + {continue, B, Next_b} -> + {continue, Fun(A, B), do_map2(Next_a, Next_b, Fun)} + end + end end. + +-spec map2(iterator(BSJ), iterator(BSL), fun((BSJ, BSL) -> BSN)) -> iterator(BSN). +map2(Iterator1, Iterator2, Fun) -> + _pipe = do_map2( + erlang:element(2, Iterator1), + erlang:element(2, Iterator2), + Fun + ), + {iterator, _pipe}. + +-spec do_append(fun(() -> action(BSP)), fun(() -> action(BSP))) -> action(BSP). +do_append(First, Second) -> + case First() of + {continue, E, First@1} -> + {continue, E, fun() -> do_append(First@1, Second) end}; + + stop -> + Second() + end. + +-spec append(iterator(BST), iterator(BST)) -> iterator(BST). +append(First, Second) -> + _pipe = fun() -> + do_append(erlang:element(2, First), erlang:element(2, Second)) + end, + {iterator, _pipe}. + +-spec do_flatten(fun(() -> action(iterator(BSX)))) -> action(BSX). +do_flatten(Flattened) -> + case Flattened() of + stop -> + stop; + + {continue, It, Next_iterator} -> + do_append( + erlang:element(2, It), + fun() -> do_flatten(Next_iterator) end + ) + end. + +-spec flatten(iterator(iterator(BTB))) -> iterator(BTB). +flatten(Iterator) -> + _pipe = fun() -> do_flatten(erlang:element(2, Iterator)) end, + {iterator, _pipe}. + +-spec concat(list(iterator(BTF))) -> iterator(BTF). +concat(Iterators) -> + flatten(from_list(Iterators)). + +-spec flat_map(iterator(BTJ), fun((BTJ) -> iterator(BTL))) -> iterator(BTL). +flat_map(Iterator, F) -> + _pipe = Iterator, + _pipe@1 = map(_pipe, F), + flatten(_pipe@1). + +-spec do_filter(fun(() -> action(BTO)), fun((BTO) -> boolean())) -> action(BTO). +do_filter(Continuation, Predicate) -> + case Continuation() of + stop -> + stop; + + {continue, E, Iterator} -> + case Predicate(E) of + true -> + {continue, E, fun() -> do_filter(Iterator, Predicate) end}; + + false -> + do_filter(Iterator, Predicate) + end + end. + +-spec filter(iterator(BTR), fun((BTR) -> boolean())) -> iterator(BTR). +filter(Iterator, Predicate) -> + _pipe = fun() -> do_filter(erlang:element(2, Iterator), Predicate) end, + {iterator, _pipe}. + +-spec cycle(iterator(BTU)) -> iterator(BTU). +cycle(Iterator) -> + _pipe = repeat(Iterator), + flatten(_pipe). + +-spec do_find(fun(() -> action(BTY)), fun((BTY) -> boolean())) -> {ok, BTY} | + {error, nil}. +do_find(Continuation, F) -> + case Continuation() of + stop -> + {error, nil}; + + {continue, E, Next} -> + case F(E) of + true -> + {ok, E}; + + false -> + do_find(Next, F) + end + end. + +-spec find(iterator(BUC), fun((BUC) -> boolean())) -> {ok, BUC} | {error, nil}. +find(Haystack, Is_desired) -> + _pipe = erlang:element(2, Haystack), + do_find(_pipe, Is_desired). + +-spec do_index(fun(() -> action(BUG)), integer()) -> fun(() -> action({integer(), + BUG})). +do_index(Continuation, Next) -> + fun() -> case Continuation() of + stop -> + stop; + + {continue, E, Continuation@1} -> + {continue, {Next, E}, do_index(Continuation@1, Next + 1)} + end end. + +-spec index(iterator(BUJ)) -> iterator({integer(), BUJ}). +index(Iterator) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_index(_pipe, 0), + {iterator, _pipe@1}. + +-spec iterate(BUM, fun((BUM) -> BUM)) -> iterator(BUM). +iterate(Initial, F) -> + unfold(Initial, fun(Element) -> {next, Element, F(Element)} end). + +-spec do_take_while(fun(() -> action(BUO)), fun((BUO) -> boolean())) -> fun(() -> action(BUO)). +do_take_while(Continuation, Predicate) -> + fun() -> case Continuation() of + stop -> + stop; + + {continue, E, Next} -> + case Predicate(E) of + false -> + stop; + + true -> + {continue, E, do_take_while(Next, Predicate)} + end + end end. + +-spec take_while(iterator(BUR), fun((BUR) -> boolean())) -> iterator(BUR). +take_while(Iterator, Predicate) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_take_while(_pipe, Predicate), + {iterator, _pipe@1}. + +-spec do_drop_while(fun(() -> action(BUU)), fun((BUU) -> boolean())) -> action(BUU). +do_drop_while(Continuation, Predicate) -> + case Continuation() of + stop -> + stop; + + {continue, E, Next} -> + case Predicate(E) of + false -> + {continue, E, Next}; + + true -> + do_drop_while(Next, Predicate) + end + end. + +-spec drop_while(iterator(BUX), fun((BUX) -> boolean())) -> iterator(BUX). +drop_while(Iterator, Predicate) -> + _pipe = fun() -> do_drop_while(erlang:element(2, Iterator), Predicate) end, + {iterator, _pipe}. + +-spec do_scan(fun(() -> action(BVA)), fun((BVC, BVA) -> BVC), BVC) -> fun(() -> action(BVC)). +do_scan(Continuation, F, Accumulator) -> + fun() -> case Continuation() of + stop -> + stop; + + {continue, El, Next} -> + Accumulated = F(Accumulator, El), + {continue, Accumulated, do_scan(Next, F, Accumulated)} + end end. + +-spec scan(iterator(BVE), BVG, fun((BVG, BVE) -> BVG)) -> iterator(BVG). +scan(Iterator, Initial, F) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_scan(_pipe, F, Initial), + {iterator, _pipe@1}. + +-spec do_zip(fun(() -> action(BVI)), fun(() -> action(BVK))) -> fun(() -> action({BVI, + BVK})). +do_zip(Left, Right) -> + fun() -> case Left() of + stop -> + stop; + + {continue, El_left, Next_left} -> + case Right() of + stop -> + stop; + + {continue, El_right, Next_right} -> + {continue, + {El_left, El_right}, + do_zip(Next_left, Next_right)} + end + end end. + +-spec zip(iterator(BVN), iterator(BVP)) -> iterator({BVN, BVP}). +zip(Left, Right) -> + _pipe = do_zip(erlang:element(2, Left), erlang:element(2, Right)), + {iterator, _pipe}. + +-spec next_chunk(fun(() -> action(BVS)), fun((BVS) -> BVU), BVU, list(BVS)) -> chunk(BVS, BVU). +next_chunk(Continuation, F, Previous_key, Current_chunk) -> + case Continuation() of + stop -> + {last_by, gleam@list:reverse(Current_chunk)}; + + {continue, E, Next} -> + Key = F(E), + case Key =:= Previous_key of + true -> + next_chunk(Next, F, Key, [E | Current_chunk]); + + false -> + {another_by, + gleam@list:reverse(Current_chunk), + Key, + E, + Next} + end + end. + +-spec do_chunk(fun(() -> action(BVY)), fun((BVY) -> BWA), BWA, BVY) -> action(list(BVY)). +do_chunk(Continuation, F, Previous_key, Previous_element) -> + case next_chunk(Continuation, F, Previous_key, [Previous_element]) of + {last_by, Chunk} -> + {continue, Chunk, fun stop/0}; + + {another_by, Chunk@1, Key, El, Next} -> + {continue, Chunk@1, fun() -> do_chunk(Next, F, Key, El) end} + end. + +-spec chunk(iterator(BWD), fun((BWD) -> any())) -> iterator(list(BWD)). +chunk(Iterator, F) -> + _pipe = fun() -> case (erlang:element(2, Iterator))() of + stop -> + stop; + + {continue, E, Next} -> + do_chunk(Next, F, F(E), E) + end end, + {iterator, _pipe}. + +-spec next_sized_chunk(fun(() -> action(BWI)), integer(), list(BWI)) -> sized_chunk(BWI). +next_sized_chunk(Continuation, Left, Current_chunk) -> + case Continuation() of + stop -> + case Current_chunk of + [] -> + no_more; + + Remaining -> + {last, gleam@list:reverse(Remaining)} + end; + + {continue, E, Next} -> + Chunk = [E | Current_chunk], + case Left > 1 of + false -> + {another, gleam@list:reverse(Chunk), Next}; + + true -> + next_sized_chunk(Next, Left - 1, Chunk) + end + end. + +-spec do_sized_chunk(fun(() -> action(BWM)), integer()) -> fun(() -> action(list(BWM))). +do_sized_chunk(Continuation, Count) -> + fun() -> case next_sized_chunk(Continuation, Count, []) of + no_more -> + stop; + + {last, Chunk} -> + {continue, Chunk, fun stop/0}; + + {another, Chunk@1, Next_element} -> + {continue, Chunk@1, do_sized_chunk(Next_element, Count)} + end end. + +-spec sized_chunk(iterator(BWQ), integer()) -> iterator(list(BWQ)). +sized_chunk(Iterator, Count) -> + _pipe = erlang:element(2, Iterator), + _pipe@1 = do_sized_chunk(_pipe, Count), + {iterator, _pipe@1}. + +-spec do_intersperse(fun(() -> action(BWU)), BWU) -> action(BWU). +do_intersperse(Continuation, Separator) -> + case Continuation() of + stop -> + stop; + + {continue, E, Next} -> + Next_interspersed = fun() -> do_intersperse(Next, Separator) end, + {continue, Separator, fun() -> {continue, E, Next_interspersed} end} + end. + +-spec intersperse(iterator(BWX), BWX) -> iterator(BWX). +intersperse(Iterator, Elem) -> + _pipe = fun() -> case (erlang:element(2, Iterator))() of + stop -> + stop; + + {continue, E, Next} -> + {continue, E, fun() -> do_intersperse(Next, Elem) end} + end end, + {iterator, _pipe}. + +-spec do_any(fun(() -> action(BXA)), fun((BXA) -> boolean())) -> boolean(). +do_any(Continuation, Predicate) -> + case Continuation() of + stop -> + false; + + {continue, E, Next} -> + case Predicate(E) of + true -> + true; + + false -> + do_any(Next, Predicate) + end + end. + +-spec any(iterator(BXC), fun((BXC) -> boolean())) -> boolean(). +any(Iterator, Predicate) -> + _pipe = erlang:element(2, Iterator), + do_any(_pipe, Predicate). + +-spec do_all(fun(() -> action(BXE)), fun((BXE) -> boolean())) -> boolean(). +do_all(Continuation, Predicate) -> + case Continuation() of + stop -> + true; + + {continue, E, Next} -> + case Predicate(E) of + true -> + do_all(Next, Predicate); + + false -> + false + end + end. + +-spec all(iterator(BXG), fun((BXG) -> boolean())) -> boolean(). +all(Iterator, Predicate) -> + _pipe = erlang:element(2, Iterator), + do_all(_pipe, Predicate). + +-spec update_group_with(BXI) -> fun((gleam@option:option(list(BXI))) -> list(BXI)). +update_group_with(El) -> + fun(Maybe_group) -> case Maybe_group of + {some, Group} -> + [El | Group]; + + none -> + [El] + end end. + +-spec group_updater(fun((BXM) -> BXN)) -> fun((gleam@dict:dict(BXN, list(BXM)), BXM) -> gleam@dict:dict(BXN, list(BXM))). +group_updater(F) -> + fun(Groups, Elem) -> _pipe = Groups, + gleam@dict:update(_pipe, F(Elem), update_group_with(Elem)) end. + +-spec group(iterator(BXU), fun((BXU) -> BXW)) -> gleam@dict:dict(BXW, list(BXU)). +group(Iterator, Key) -> + _pipe = Iterator, + _pipe@1 = fold(_pipe, gleam@dict:new(), group_updater(Key)), + gleam@dict:map_values( + _pipe@1, + fun(_, Group) -> gleam@list:reverse(Group) end + ). + +-spec reduce(iterator(BYA), fun((BYA, BYA) -> BYA)) -> {ok, BYA} | {error, nil}. +reduce(Iterator, F) -> + case (erlang:element(2, Iterator))() of + stop -> + {error, nil}; + + {continue, E, Next} -> + _pipe = do_fold(Next, F, E), + {ok, _pipe} + end. + +-spec last(iterator(BYE)) -> {ok, BYE} | {error, nil}. +last(Iterator) -> + _pipe = Iterator, + reduce(_pipe, fun(_, Elem) -> Elem end). + +-spec empty() -> iterator(any()). +empty() -> + {iterator, fun stop/0}. + +-spec once(fun(() -> BYK)) -> iterator(BYK). +once(F) -> + _pipe = fun() -> {continue, F(), fun stop/0} end, + {iterator, _pipe}. + +-spec range(integer(), integer()) -> iterator(integer()). +range(Start, Stop) -> + case gleam@int:compare(Start, Stop) of + eq -> + once(fun() -> Start end); + + gt -> + unfold(Start, fun(Current) -> case Current < Stop of + false -> + {next, Current, Current - 1}; + + true -> + done + end end); + + lt -> + unfold(Start, fun(Current@1) -> case Current@1 > Stop of + false -> + {next, Current@1, Current@1 + 1}; + + true -> + done + end end) + end. + +-spec single(BYM) -> iterator(BYM). +single(Elem) -> + once(fun() -> Elem end). + +-spec do_interleave(fun(() -> action(BYO)), fun(() -> action(BYO))) -> action(BYO). +do_interleave(Current, Next) -> + case Current() of + stop -> + Next(); + + {continue, E, Next_other} -> + {continue, E, fun() -> do_interleave(Next, Next_other) end} + end. + +-spec interleave(iterator(BYS), iterator(BYS)) -> iterator(BYS). +interleave(Left, Right) -> + _pipe = fun() -> + do_interleave(erlang:element(2, Left), erlang:element(2, Right)) + end, + {iterator, _pipe}. + +-spec do_fold_until( + fun(() -> action(BYW)), + fun((BYY, BYW) -> gleam@list:continue_or_stop(BYY)), + BYY +) -> BYY. +do_fold_until(Continuation, F, Accumulator) -> + case Continuation() of + stop -> + Accumulator; + + {continue, Elem, Next} -> + case F(Accumulator, Elem) of + {continue, Accumulator@1} -> + do_fold_until(Next, F, Accumulator@1); + + {stop, Accumulator@2} -> + Accumulator@2 + end + end. + +-spec fold_until( + iterator(BZA), + BZC, + fun((BZC, BZA) -> gleam@list:continue_or_stop(BZC)) +) -> BZC. +fold_until(Iterator, Initial, F) -> + _pipe = erlang:element(2, Iterator), + do_fold_until(_pipe, F, Initial). + +-spec do_try_fold( + fun(() -> action(BZE)), + fun((BZG, BZE) -> {ok, BZG} | {error, BZH}), + BZG +) -> {ok, BZG} | {error, BZH}. +do_try_fold(Continuation, F, Accumulator) -> + case Continuation() of + stop -> + {ok, Accumulator}; + + {continue, Elem, Next} -> + gleam@result:'try'( + F(Accumulator, Elem), + fun(Accumulator@1) -> do_try_fold(Next, F, Accumulator@1) end + ) + end. + +-spec try_fold(iterator(BZM), BZO, fun((BZO, BZM) -> {ok, BZO} | {error, BZP})) -> {ok, + BZO} | + {error, BZP}. +try_fold(Iterator, Initial, F) -> + _pipe = erlang:element(2, Iterator), + do_try_fold(_pipe, F, Initial). + +-spec first(iterator(BZU)) -> {ok, BZU} | {error, nil}. +first(Iterator) -> + case (erlang:element(2, Iterator))() of + stop -> + {error, nil}; + + {continue, E, _} -> + {ok, E} + end. + +-spec at(iterator(BZY), integer()) -> {ok, BZY} | {error, nil}. +at(Iterator, Index) -> + _pipe = Iterator, + _pipe@1 = drop(_pipe, Index), + first(_pipe@1). + +-spec do_length(fun(() -> action(any())), integer()) -> integer(). +do_length(Continuation, Length) -> + case Continuation() of + stop -> + Length; + + {continue, _, Next} -> + do_length(Next, Length + 1) + end. + +-spec length(iterator(any())) -> integer(). +length(Iterator) -> + _pipe = erlang:element(2, Iterator), + do_length(_pipe, 0). + +-spec each(iterator(CAG), fun((CAG) -> any())) -> nil. +each(Iterator, F) -> + _pipe = Iterator, + _pipe@1 = map(_pipe, F), + run(_pipe@1). + +-spec yield(CAJ, fun(() -> iterator(CAJ))) -> iterator(CAJ). +yield(Element, Next) -> + {iterator, fun() -> {continue, Element, erlang:element(2, Next())} end}. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache Binary files differnew file mode 100644 index 0000000..a8c076a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta Binary files differnew file mode 100644 index 0000000..56b294f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.erl new file mode 100644 index 0000000..ef8ad42 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@list.erl @@ -0,0 +1,1129 @@ +-module(gleam@list). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([length/1, reverse/1, is_empty/1, contains/2, first/1, rest/1, filter/2, filter_map/2, map/2, map2/3, index_map/2, try_map/2, drop/2, take/2, new/0, append/2, prepend/2, concat/1, flatten/1, flat_map/2, fold/3, group/2, map_fold/3, fold_right/3, index_fold/3, try_fold/3, fold_until/3, find/2, find_map/2, all/2, any/2, zip/2, strict_zip/2, unzip/1, intersperse/2, at/2, unique/1, sort/2, range/2, repeat/2, split/2, split_while/2, key_find/2, key_filter/2, pop/2, pop_map/2, key_pop/2, key_set/3, each/2, try_each/2, partition/2, permutations/1, window/2, window_by_2/1, drop_while/2, take_while/2, chunk/2, sized_chunk/2, reduce/2, scan/3, last/1, combinations/2, combination_pairs/1, transpose/1, interleave/1, shuffle/1]). +-export_type([length_mismatch/0, continue_or_stop/1]). + +-type length_mismatch() :: length_mismatch. + +-type continue_or_stop(UD) :: {continue, UD} | {stop, UD}. + +-spec length(list(any())) -> integer(). +length(List) -> + erlang:length(List). + +-spec reverse(list(UI)) -> list(UI). +reverse(Xs) -> + lists:reverse(Xs). + +-spec is_empty(list(any())) -> boolean(). +is_empty(List) -> + List =:= []. + +-spec contains(list(UQ), UQ) -> boolean(). +contains(List, Elem) -> + case List of + [] -> + false; + + [First | _] when First =:= Elem -> + true; + + [_ | Rest] -> + contains(Rest, Elem) + end. + +-spec first(list(US)) -> {ok, US} | {error, nil}. +first(List) -> + case List of + [] -> + {error, nil}; + + [X | _] -> + {ok, X} + end. + +-spec rest(list(UW)) -> {ok, list(UW)} | {error, nil}. +rest(List) -> + case List of + [] -> + {error, nil}; + + [_ | Xs] -> + {ok, Xs} + end. + +-spec update_group(fun((VB) -> VC)) -> fun((gleam@dict:dict(VC, list(VB)), VB) -> gleam@dict:dict(VC, list(VB))). +update_group(F) -> + fun(Groups, Elem) -> case gleam@dict:get(Groups, F(Elem)) of + {ok, Existing} -> + gleam@dict:insert(Groups, F(Elem), [Elem | Existing]); + + {error, _} -> + gleam@dict:insert(Groups, F(Elem), [Elem]) + end end. + +-spec do_filter(list(VP), fun((VP) -> boolean()), list(VP)) -> list(VP). +do_filter(List, Fun, Acc) -> + case List of + [] -> + reverse(Acc); + + [X | Xs] -> + New_acc = case Fun(X) of + true -> + [X | Acc]; + + false -> + Acc + end, + do_filter(Xs, Fun, New_acc) + end. + +-spec filter(list(VT), fun((VT) -> boolean())) -> list(VT). +filter(List, Predicate) -> + do_filter(List, Predicate, []). + +-spec do_filter_map(list(VW), fun((VW) -> {ok, VY} | {error, any()}), list(VY)) -> list(VY). +do_filter_map(List, Fun, Acc) -> + case List of + [] -> + reverse(Acc); + + [X | Xs] -> + New_acc = case Fun(X) of + {ok, X@1} -> + [X@1 | Acc]; + + {error, _} -> + Acc + end, + do_filter_map(Xs, Fun, New_acc) + end. + +-spec filter_map(list(WE), fun((WE) -> {ok, WG} | {error, any()})) -> list(WG). +filter_map(List, Fun) -> + do_filter_map(List, Fun, []). + +-spec do_map(list(WL), fun((WL) -> WN), list(WN)) -> list(WN). +do_map(List, Fun, Acc) -> + case List of + [] -> + reverse(Acc); + + [X | Xs] -> + do_map(Xs, Fun, [Fun(X) | Acc]) + end. + +-spec map(list(WQ), fun((WQ) -> WS)) -> list(WS). +map(List, Fun) -> + do_map(List, Fun, []). + +-spec do_map2(list(XA), list(XC), fun((XA, XC) -> XE), list(XE)) -> list(XE). +do_map2(List1, List2, Fun, Acc) -> + case {List1, List2} of + {[], _} -> + reverse(Acc); + + {_, []} -> + reverse(Acc); + + {[A | As_], [B | Bs]} -> + do_map2(As_, Bs, Fun, [Fun(A, B) | Acc]) + end. + +-spec map2(list(WU), list(WW), fun((WU, WW) -> WY)) -> list(WY). +map2(List1, List2, Fun) -> + do_map2(List1, List2, Fun, []). + +-spec do_index_map(list(XM), fun((integer(), XM) -> XO), integer(), list(XO)) -> list(XO). +do_index_map(List, Fun, Index, Acc) -> + case List of + [] -> + reverse(Acc); + + [X | Xs] -> + Acc@1 = [Fun(Index, X) | Acc], + do_index_map(Xs, Fun, Index + 1, Acc@1) + end. + +-spec index_map(list(XR), fun((integer(), XR) -> XT)) -> list(XT). +index_map(List, Fun) -> + do_index_map(List, Fun, 0, []). + +-spec do_try_map(list(XV), fun((XV) -> {ok, XX} | {error, XY}), list(XX)) -> {ok, + list(XX)} | + {error, XY}. +do_try_map(List, Fun, Acc) -> + case List of + [] -> + {ok, reverse(Acc)}; + + [X | Xs] -> + case Fun(X) of + {ok, Y} -> + do_try_map(Xs, Fun, [Y | Acc]); + + {error, Error} -> + {error, Error} + end + end. + +-spec try_map(list(YF), fun((YF) -> {ok, YH} | {error, YI})) -> {ok, list(YH)} | + {error, YI}. +try_map(List, Fun) -> + do_try_map(List, Fun, []). + +-spec drop(list(YO), integer()) -> list(YO). +drop(List, N) -> + case N =< 0 of + true -> + List; + + false -> + case List of + [] -> + []; + + [_ | Xs] -> + drop(Xs, N - 1) + end + end. + +-spec do_take(list(YR), integer(), list(YR)) -> list(YR). +do_take(List, N, Acc) -> + case N =< 0 of + true -> + reverse(Acc); + + false -> + case List of + [] -> + reverse(Acc); + + [X | Xs] -> + do_take(Xs, N - 1, [X | Acc]) + end + end. + +-spec take(list(YV), integer()) -> list(YV). +take(List, N) -> + do_take(List, N, []). + +-spec new() -> list(any()). +new() -> + []. + +-spec append(list(AAA), list(AAA)) -> list(AAA). +append(First, Second) -> + lists:append(First, Second). + +-spec prepend(list(AAI), AAI) -> list(AAI). +prepend(List, Item) -> + [Item | List]. + +-spec reverse_and_prepend(list(AAL), list(AAL)) -> list(AAL). +reverse_and_prepend(Prefix, Suffix) -> + case Prefix of + [] -> + Suffix; + + [First | Rest] -> + reverse_and_prepend(Rest, [First | Suffix]) + end. + +-spec do_concat(list(list(AAP)), list(AAP)) -> list(AAP). +do_concat(Lists, Acc) -> + case Lists of + [] -> + reverse(Acc); + + [List | Further_lists] -> + do_concat(Further_lists, reverse_and_prepend(List, Acc)) + end. + +-spec concat(list(list(AAU))) -> list(AAU). +concat(Lists) -> + do_concat(Lists, []). + +-spec flatten(list(list(AAY))) -> list(AAY). +flatten(Lists) -> + do_concat(Lists, []). + +-spec flat_map(list(ABC), fun((ABC) -> list(ABE))) -> list(ABE). +flat_map(List, Fun) -> + _pipe = map(List, Fun), + concat(_pipe). + +-spec fold(list(ABH), ABJ, fun((ABJ, ABH) -> ABJ)) -> ABJ. +fold(List, Initial, Fun) -> + case List of + [] -> + Initial; + + [X | Rest] -> + fold(Rest, Fun(Initial, X), Fun) + end. + +-spec group(list(VJ), fun((VJ) -> VL)) -> gleam@dict:dict(VL, list(VJ)). +group(List, Key) -> + fold(List, gleam@dict:new(), update_group(Key)). + +-spec map_fold(list(XH), XJ, fun((XJ, XH) -> {XJ, XK})) -> {XJ, list(XK)}. +map_fold(List, Acc, Fun) -> + _pipe = fold( + List, + {Acc, []}, + fun(Acc@1, Item) -> + {Current_acc, Items} = Acc@1, + {Next_acc, Next_item} = Fun(Current_acc, Item), + {Next_acc, [Next_item | Items]} + end + ), + gleam@pair:map_second(_pipe, fun reverse/1). + +-spec fold_right(list(ABK), ABM, fun((ABM, ABK) -> ABM)) -> ABM. +fold_right(List, Initial, Fun) -> + case List of + [] -> + Initial; + + [X | Rest] -> + Fun(fold_right(Rest, Initial, Fun), X) + end. + +-spec do_index_fold( + list(ABN), + ABP, + fun((ABP, ABN, integer()) -> ABP), + integer() +) -> ABP. +do_index_fold(Over, Acc, With, Index) -> + case Over of + [] -> + Acc; + + [First | Rest] -> + do_index_fold(Rest, With(Acc, First, Index), With, Index + 1) + end. + +-spec index_fold(list(ABQ), ABS, fun((ABS, ABQ, integer()) -> ABS)) -> ABS. +index_fold(Over, Initial, Fun) -> + do_index_fold(Over, Initial, Fun, 0). + +-spec try_fold(list(ABT), ABV, fun((ABV, ABT) -> {ok, ABV} | {error, ABW})) -> {ok, + ABV} | + {error, ABW}. +try_fold(Collection, Accumulator, Fun) -> + case Collection of + [] -> + {ok, Accumulator}; + + [First | Rest] -> + case Fun(Accumulator, First) of + {ok, Result} -> + try_fold(Rest, Result, Fun); + + {error, _} = Error -> + Error + end + end. + +-spec fold_until(list(ACB), ACD, fun((ACD, ACB) -> continue_or_stop(ACD))) -> ACD. +fold_until(Collection, Accumulator, Fun) -> + case Collection of + [] -> + Accumulator; + + [First | Rest] -> + case Fun(Accumulator, First) of + {continue, Next_accumulator} -> + fold_until(Rest, Next_accumulator, Fun); + + {stop, B} -> + B + end + end. + +-spec find(list(ACF), fun((ACF) -> boolean())) -> {ok, ACF} | {error, nil}. +find(Haystack, Is_desired) -> + case Haystack of + [] -> + {error, nil}; + + [X | Rest] -> + case Is_desired(X) of + true -> + {ok, X}; + + _ -> + find(Rest, Is_desired) + end + end. + +-spec find_map(list(ACJ), fun((ACJ) -> {ok, ACL} | {error, any()})) -> {ok, ACL} | + {error, nil}. +find_map(Haystack, Fun) -> + case Haystack of + [] -> + {error, nil}; + + [X | Rest] -> + case Fun(X) of + {ok, X@1} -> + {ok, X@1}; + + _ -> + find_map(Rest, Fun) + end + end. + +-spec all(list(ACR), fun((ACR) -> boolean())) -> boolean(). +all(List, Predicate) -> + case List of + [] -> + true; + + [First | Rest] -> + case Predicate(First) of + true -> + all(Rest, Predicate); + + false -> + false + end + end. + +-spec any(list(ACT), fun((ACT) -> boolean())) -> boolean(). +any(List, Predicate) -> + case List of + [] -> + false; + + [First | Rest] -> + case Predicate(First) of + true -> + true; + + false -> + any(Rest, Predicate) + end + end. + +-spec do_zip(list(ACV), list(ACX), list({ACV, ACX})) -> list({ACV, ACX}). +do_zip(Xs, Ys, Acc) -> + case {Xs, Ys} of + {[X | Xs@1], [Y | Ys@1]} -> + do_zip(Xs@1, Ys@1, [{X, Y} | Acc]); + + {_, _} -> + reverse(Acc) + end. + +-spec zip(list(ADB), list(ADD)) -> list({ADB, ADD}). +zip(List, Other) -> + do_zip(List, Other, []). + +-spec strict_zip(list(ADG), list(ADI)) -> {ok, list({ADG, ADI})} | + {error, length_mismatch()}. +strict_zip(List, Other) -> + case length(List) =:= length(Other) of + true -> + {ok, zip(List, Other)}; + + false -> + {error, length_mismatch} + end. + +-spec do_unzip(list({ATA, ATB}), list(ATA), list(ATB)) -> {list(ATA), list(ATB)}. +do_unzip(Input, Xs, Ys) -> + case Input of + [] -> + {reverse(Xs), reverse(Ys)}; + + [{X, Y} | Rest] -> + do_unzip(Rest, [X | Xs], [Y | Ys]) + end. + +-spec unzip(list({ADR, ADS})) -> {list(ADR), list(ADS)}. +unzip(Input) -> + do_unzip(Input, [], []). + +-spec do_intersperse(list(ADW), ADW, list(ADW)) -> list(ADW). +do_intersperse(List, Separator, Acc) -> + case List of + [] -> + reverse(Acc); + + [X | Rest] -> + do_intersperse(Rest, Separator, [X, Separator | Acc]) + end. + +-spec intersperse(list(AEA), AEA) -> list(AEA). +intersperse(List, Elem) -> + case List of + [] -> + List; + + [_] -> + List; + + [X | Rest] -> + do_intersperse(Rest, Elem, [X]) + end. + +-spec at(list(AED), integer()) -> {ok, AED} | {error, nil}. +at(List, Index) -> + case Index >= 0 of + true -> + _pipe = List, + _pipe@1 = drop(_pipe, Index), + first(_pipe@1); + + false -> + {error, nil} + end. + +-spec unique(list(AEH)) -> list(AEH). +unique(List) -> + case List of + [] -> + []; + + [X | Rest] -> + [X | unique(filter(Rest, fun(Y) -> Y /= X end))] + end. + +-spec merge_up( + integer(), + integer(), + list(AEK), + list(AEK), + list(AEK), + fun((AEK, AEK) -> gleam@order:order()) +) -> list(AEK). +merge_up(Na, Nb, A, B, Acc, Compare) -> + case {Na, Nb, A, B} of + {0, 0, _, _} -> + Acc; + + {_, 0, [Ax | Ar], _} -> + merge_up(Na - 1, Nb, Ar, B, [Ax | Acc], Compare); + + {0, _, _, [Bx | Br]} -> + merge_up(Na, Nb - 1, A, Br, [Bx | Acc], Compare); + + {_, _, [Ax@1 | Ar@1], [Bx@1 | Br@1]} -> + case Compare(Ax@1, Bx@1) of + gt -> + merge_up(Na, Nb - 1, A, Br@1, [Bx@1 | Acc], Compare); + + _ -> + merge_up(Na - 1, Nb, Ar@1, B, [Ax@1 | Acc], Compare) + end; + + {_, _, _, _} -> + Acc + end. + +-spec merge_down( + integer(), + integer(), + list(AEP), + list(AEP), + list(AEP), + fun((AEP, AEP) -> gleam@order:order()) +) -> list(AEP). +merge_down(Na, Nb, A, B, Acc, Compare) -> + case {Na, Nb, A, B} of + {0, 0, _, _} -> + Acc; + + {_, 0, [Ax | Ar], _} -> + merge_down(Na - 1, Nb, Ar, B, [Ax | Acc], Compare); + + {0, _, _, [Bx | Br]} -> + merge_down(Na, Nb - 1, A, Br, [Bx | Acc], Compare); + + {_, _, [Ax@1 | Ar@1], [Bx@1 | Br@1]} -> + case Compare(Bx@1, Ax@1) of + lt -> + merge_down(Na - 1, Nb, Ar@1, B, [Ax@1 | Acc], Compare); + + _ -> + merge_down(Na, Nb - 1, A, Br@1, [Bx@1 | Acc], Compare) + end; + + {_, _, _, _} -> + Acc + end. + +-spec merge_sort( + list(AEU), + integer(), + fun((AEU, AEU) -> gleam@order:order()), + boolean() +) -> list(AEU). +merge_sort(L, Ln, Compare, Down) -> + N = Ln div 2, + A = L, + B = drop(L, N), + case Ln < 3 of + true -> + case Down of + true -> + merge_down(N, Ln - N, A, B, [], Compare); + + false -> + merge_up(N, Ln - N, A, B, [], Compare) + end; + + false -> + case Down of + true -> + merge_down( + N, + Ln - N, + merge_sort(A, N, Compare, false), + merge_sort(B, Ln - N, Compare, false), + [], + Compare + ); + + false -> + merge_up( + N, + Ln - N, + merge_sort(A, N, Compare, true), + merge_sort(B, Ln - N, Compare, true), + [], + Compare + ) + end + end. + +-spec sort(list(AEX), fun((AEX, AEX) -> gleam@order:order())) -> list(AEX). +sort(List, Compare) -> + merge_sort(List, length(List), Compare, true). + +-spec tail_recursive_range(integer(), integer(), list(integer())) -> list(integer()). +tail_recursive_range(Start, Stop, Acc) -> + case gleam@int:compare(Start, Stop) of + eq -> + [Stop | Acc]; + + gt -> + tail_recursive_range(Start, Stop + 1, [Stop | Acc]); + + lt -> + tail_recursive_range(Start, Stop - 1, [Stop | Acc]) + end. + +-spec range(integer(), integer()) -> list(integer()). +range(Start, Stop) -> + tail_recursive_range(Start, Stop, []). + +-spec do_repeat(AFD, integer(), list(AFD)) -> list(AFD). +do_repeat(A, Times, Acc) -> + case Times =< 0 of + true -> + Acc; + + false -> + do_repeat(A, Times - 1, [A | Acc]) + end. + +-spec repeat(AFG, integer()) -> list(AFG). +repeat(A, Times) -> + do_repeat(A, Times, []). + +-spec do_split(list(AFI), integer(), list(AFI)) -> {list(AFI), list(AFI)}. +do_split(List, N, Taken) -> + case N =< 0 of + true -> + {reverse(Taken), List}; + + false -> + case List of + [] -> + {reverse(Taken), []}; + + [X | Xs] -> + do_split(Xs, N - 1, [X | Taken]) + end + end. + +-spec split(list(AFN), integer()) -> {list(AFN), list(AFN)}. +split(List, Index) -> + do_split(List, Index, []). + +-spec do_split_while(list(AFR), fun((AFR) -> boolean()), list(AFR)) -> {list(AFR), + list(AFR)}. +do_split_while(List, F, Acc) -> + case List of + [] -> + {reverse(Acc), []}; + + [X | Xs] -> + case F(X) of + false -> + {reverse(Acc), List}; + + _ -> + do_split_while(Xs, F, [X | Acc]) + end + end. + +-spec split_while(list(AFW), fun((AFW) -> boolean())) -> {list(AFW), list(AFW)}. +split_while(List, Predicate) -> + do_split_while(List, Predicate, []). + +-spec key_find(list({AGA, AGB}), AGA) -> {ok, AGB} | {error, nil}. +key_find(Keyword_list, Desired_key) -> + find_map( + Keyword_list, + fun(Keyword) -> + {Key, Value} = Keyword, + case Key =:= Desired_key of + true -> + {ok, Value}; + + false -> + {error, nil} + end + end + ). + +-spec key_filter(list({AGF, AGG}), AGF) -> list(AGG). +key_filter(Keyword_list, Desired_key) -> + filter_map( + Keyword_list, + fun(Keyword) -> + {Key, Value} = Keyword, + case Key =:= Desired_key of + true -> + {ok, Value}; + + false -> + {error, nil} + end + end + ). + +-spec do_pop(list(AWT), fun((AWT) -> boolean()), list(AWT)) -> {ok, + {AWT, list(AWT)}} | + {error, nil}. +do_pop(Haystack, Predicate, Checked) -> + case Haystack of + [] -> + {error, nil}; + + [X | Rest] -> + case Predicate(X) of + true -> + {ok, {X, append(reverse(Checked), Rest)}}; + + false -> + do_pop(Rest, Predicate, [X | Checked]) + end + end. + +-spec pop(list(AGN), fun((AGN) -> boolean())) -> {ok, {AGN, list(AGN)}} | + {error, nil}. +pop(Haystack, Is_desired) -> + do_pop(Haystack, Is_desired, []). + +-spec do_pop_map(list(AXH), fun((AXH) -> {ok, AXU} | {error, any()}), list(AXH)) -> {ok, + {AXU, list(AXH)}} | + {error, nil}. +do_pop_map(Haystack, Mapper, Checked) -> + case Haystack of + [] -> + {error, nil}; + + [X | Rest] -> + case Mapper(X) of + {ok, Y} -> + {ok, {Y, append(reverse(Checked), Rest)}}; + + {error, _} -> + do_pop_map(Rest, Mapper, [X | Checked]) + end + end. + +-spec pop_map(list(AGW), fun((AGW) -> {ok, AGY} | {error, any()})) -> {ok, + {AGY, list(AGW)}} | + {error, nil}. +pop_map(Haystack, Is_desired) -> + do_pop_map(Haystack, Is_desired, []). + +-spec key_pop(list({AHF, AHG}), AHF) -> {ok, {AHG, list({AHF, AHG})}} | + {error, nil}. +key_pop(Haystack, Key) -> + pop_map( + Haystack, + fun(Entry) -> + {K, V} = Entry, + case K of + K@1 when K@1 =:= Key -> + {ok, V}; + + _ -> + {error, nil} + end + end + ). + +-spec key_set(list({AHL, AHM}), AHL, AHM) -> list({AHL, AHM}). +key_set(List, Key, Value) -> + case List of + [] -> + [{Key, Value}]; + + [{K, _} | Rest] when K =:= Key -> + [{Key, Value} | Rest]; + + [First | Rest@1] -> + [First | key_set(Rest@1, Key, Value)] + end. + +-spec each(list(AHP), fun((AHP) -> any())) -> nil. +each(List, F) -> + case List of + [] -> + nil; + + [X | Xs] -> + F(X), + each(Xs, F) + end. + +-spec try_each(list(AHS), fun((AHS) -> {ok, any()} | {error, AHV})) -> {ok, nil} | + {error, AHV}. +try_each(List, Fun) -> + case List of + [] -> + {ok, nil}; + + [X | Xs] -> + case Fun(X) of + {ok, _} -> + try_each(Xs, Fun); + + {error, E} -> + {error, E} + end + end. + +-spec do_partition(list(AZB), fun((AZB) -> boolean()), list(AZB), list(AZB)) -> {list(AZB), + list(AZB)}. +do_partition(List, Categorise, Trues, Falses) -> + case List of + [] -> + {reverse(Trues), reverse(Falses)}; + + [X | Xs] -> + case Categorise(X) of + true -> + do_partition(Xs, Categorise, [X | Trues], Falses); + + false -> + do_partition(Xs, Categorise, Trues, [X | Falses]) + end + end. + +-spec partition(list(AIF), fun((AIF) -> boolean())) -> {list(AIF), list(AIF)}. +partition(List, Categorise) -> + do_partition(List, Categorise, [], []). + +-spec permutations(list(AIJ)) -> list(list(AIJ)). +permutations(L) -> + case L of + [] -> + [[]]; + + _ -> + _pipe = L, + _pipe@5 = index_map(_pipe, fun(I_idx, I) -> _pipe@1 = L, + _pipe@2 = index_fold( + _pipe@1, + [], + fun(Acc, J, J_idx) -> case I_idx =:= J_idx of + true -> + Acc; + + false -> + [J | Acc] + end end + ), + _pipe@3 = reverse(_pipe@2), + _pipe@4 = permutations(_pipe@3), + map(_pipe@4, fun(Permutation) -> [I | Permutation] end) end), + concat(_pipe@5) + end. + +-spec do_window(list(list(AIN)), list(AIN), integer()) -> list(list(AIN)). +do_window(Acc, L, N) -> + Window = take(L, N), + case length(Window) =:= N of + true -> + do_window([Window | Acc], drop(L, 1), N); + + false -> + Acc + end. + +-spec window(list(AIT), integer()) -> list(list(AIT)). +window(L, N) -> + _pipe = do_window([], L, N), + reverse(_pipe). + +-spec window_by_2(list(AIX)) -> list({AIX, AIX}). +window_by_2(L) -> + zip(L, drop(L, 1)). + +-spec drop_while(list(AJA), fun((AJA) -> boolean())) -> list(AJA). +drop_while(List, Predicate) -> + case List of + [] -> + []; + + [X | Xs] -> + case Predicate(X) of + true -> + drop_while(Xs, Predicate); + + false -> + [X | Xs] + end + end. + +-spec do_take_while(list(AJD), fun((AJD) -> boolean()), list(AJD)) -> list(AJD). +do_take_while(List, Predicate, Acc) -> + case List of + [] -> + reverse(Acc); + + [First | Rest] -> + case Predicate(First) of + true -> + do_take_while(Rest, Predicate, [First | Acc]); + + false -> + reverse(Acc) + end + end. + +-spec take_while(list(AJH), fun((AJH) -> boolean())) -> list(AJH). +take_while(List, Predicate) -> + do_take_while(List, Predicate, []). + +-spec do_chunk(list(AJK), fun((AJK) -> AJM), AJM, list(AJK), list(list(AJK))) -> list(list(AJK)). +do_chunk(List, F, Previous_key, Current_chunk, Acc) -> + case List of + [First | Rest] -> + Key = F(First), + case Key =:= Previous_key of + false -> + New_acc = [reverse(Current_chunk) | Acc], + do_chunk(Rest, F, Key, [First], New_acc); + + _ -> + do_chunk(Rest, F, Key, [First | Current_chunk], Acc) + end; + + _ -> + reverse([reverse(Current_chunk) | Acc]) + end. + +-spec chunk(list(AJS), fun((AJS) -> any())) -> list(list(AJS)). +chunk(List, F) -> + case List of + [] -> + []; + + [First | Rest] -> + do_chunk(Rest, F, F(First), [First], []) + end. + +-spec do_sized_chunk( + list(AJX), + integer(), + integer(), + list(AJX), + list(list(AJX)) +) -> list(list(AJX)). +do_sized_chunk(List, Count, Left, Current_chunk, Acc) -> + case List of + [] -> + case Current_chunk of + [] -> + reverse(Acc); + + Remaining -> + reverse([reverse(Remaining) | Acc]) + end; + + [First | Rest] -> + Chunk = [First | Current_chunk], + case Left > 1 of + false -> + do_sized_chunk( + Rest, + Count, + Count, + [], + [reverse(Chunk) | Acc] + ); + + true -> + do_sized_chunk(Rest, Count, Left - 1, Chunk, Acc) + end + end. + +-spec sized_chunk(list(AKE), integer()) -> list(list(AKE)). +sized_chunk(List, Count) -> + do_sized_chunk(List, Count, Count, [], []). + +-spec reduce(list(AKI), fun((AKI, AKI) -> AKI)) -> {ok, AKI} | {error, nil}. +reduce(List, Fun) -> + case List of + [] -> + {error, nil}; + + [First | Rest] -> + {ok, fold(Rest, First, Fun)} + end. + +-spec do_scan(list(AKM), AKO, list(AKO), fun((AKO, AKM) -> AKO)) -> list(AKO). +do_scan(List, Accumulator, Accumulated, Fun) -> + case List of + [] -> + reverse(Accumulated); + + [X | Xs] -> + Next = Fun(Accumulator, X), + do_scan(Xs, Next, [Next | Accumulated], Fun) + end. + +-spec scan(list(AKR), AKT, fun((AKT, AKR) -> AKT)) -> list(AKT). +scan(List, Initial, Fun) -> + do_scan(List, Initial, [], Fun). + +-spec last(list(AKV)) -> {ok, AKV} | {error, nil}. +last(List) -> + _pipe = List, + reduce(_pipe, fun(_, Elem) -> Elem end). + +-spec combinations(list(AKZ), integer()) -> list(list(AKZ)). +combinations(Items, N) -> + case N of + 0 -> + [[]]; + + _ -> + case Items of + [] -> + []; + + [X | Xs] -> + First_combinations = begin + _pipe = map( + combinations(Xs, N - 1), + fun(Com) -> [X | Com] end + ), + reverse(_pipe) + end, + fold( + First_combinations, + combinations(Xs, N), + fun(Acc, C) -> [C | Acc] end + ) + end + end. + +-spec do_combination_pairs(list(ALD)) -> list(list({ALD, ALD})). +do_combination_pairs(Items) -> + case Items of + [] -> + []; + + [X | Xs] -> + First_combinations = map(Xs, fun(Other) -> {X, Other} end), + [First_combinations | do_combination_pairs(Xs)] + end. + +-spec combination_pairs(list(ALH)) -> list({ALH, ALH}). +combination_pairs(Items) -> + _pipe = do_combination_pairs(Items), + concat(_pipe). + +-spec transpose(list(list(ALO))) -> list(list(ALO)). +transpose(List_of_list) -> + Take_first = fun(List) -> case List of + [] -> + []; + + [F] -> + [F]; + + [F@1 | _] -> + [F@1] + end end, + case List_of_list of + [] -> + []; + + [[] | Xss] -> + transpose(Xss); + + Rows -> + Firsts = begin + _pipe = Rows, + _pipe@1 = map(_pipe, Take_first), + concat(_pipe@1) + end, + Rest = transpose(map(Rows, fun(_capture) -> drop(_capture, 1) end)), + [Firsts | Rest] + end. + +-spec interleave(list(list(ALK))) -> list(ALK). +interleave(List) -> + _pipe = transpose(List), + concat(_pipe). + +-spec do_shuffle_pair_unwrap(list({float(), ALT}), list(ALT)) -> list(ALT). +do_shuffle_pair_unwrap(List, Acc) -> + case List of + [] -> + Acc; + + [Elem_pair | Enumerable] -> + do_shuffle_pair_unwrap( + Enumerable, + [erlang:element(2, Elem_pair) | Acc] + ) + end. + +-spec do_shuffle_by_pair_indexes(list({float(), ALX})) -> list({float(), ALX}). +do_shuffle_by_pair_indexes(List_of_pairs) -> + sort( + List_of_pairs, + fun(A_pair, B_pair) -> + gleam@float:compare( + erlang:element(1, A_pair), + erlang:element(1, B_pair) + ) + end + ). + +-spec shuffle(list(AMA)) -> list(AMA). +shuffle(List) -> + _pipe = List, + _pipe@1 = fold( + _pipe, + [], + fun(Acc, A) -> [{gleam@float:random(+0.0, 1.0), A} | Acc] end + ), + _pipe@2 = do_shuffle_by_pair_indexes(_pipe@1), + do_shuffle_pair_unwrap(_pipe@2, []). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache Binary files differnew file mode 100644 index 0000000..0c28857 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache_meta Binary files differnew file mode 100644 index 0000000..03b0ec9 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.erl new file mode 100644 index 0000000..885de7e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@map.erl @@ -0,0 +1,76 @@ +-module(gleam@map). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([size/1, to_list/1, from_list/1, has_key/2, new/0, get/2, insert/3, map_values/2, keys/1, values/1, filter/2, take/2, merge/2, delete/2, drop/2, update/3, fold/3]). + +-spec size(gleam@dict:dict(any(), any())) -> integer(). +size(Map) -> + gleam@dict:size(Map). + +-spec to_list(gleam@dict:dict(CZB, CZC)) -> list({CZB, CZC}). +to_list(Map) -> + gleam@dict:to_list(Map). + +-spec from_list(list({CZE, CZF})) -> gleam@dict:dict(CZE, CZF). +from_list(List) -> + gleam@dict:from_list(List). + +-spec has_key(gleam@dict:dict(CZJ, any()), CZJ) -> boolean(). +has_key(Map, Key) -> + gleam@dict:has_key(Map, Key). + +-spec new() -> gleam@dict:dict(any(), any()). +new() -> + gleam@dict:new(). + +-spec get(gleam@dict:dict(CZM, CZN), CZM) -> {ok, CZN} | {error, nil}. +get(From, Get) -> + gleam@dict:get(From, Get). + +-spec insert(gleam@dict:dict(CZR, CZS), CZR, CZS) -> gleam@dict:dict(CZR, CZS). +insert(Map, Key, Value) -> + gleam@dict:insert(Map, Key, Value). + +-spec map_values(gleam@dict:dict(CZV, CZW), fun((CZV, CZW) -> CZX)) -> gleam@dict:dict(CZV, CZX). +map_values(Map, Fun) -> + gleam@dict:map_values(Map, Fun). + +-spec keys(gleam@dict:dict(DAA, any())) -> list(DAA). +keys(Map) -> + gleam@dict:keys(Map). + +-spec values(gleam@dict:dict(any(), DAD)) -> list(DAD). +values(Map) -> + gleam@dict:values(Map). + +-spec filter(gleam@dict:dict(DAG, DAH), fun((DAG, DAH) -> boolean())) -> gleam@dict:dict(DAG, DAH). +filter(Map, Predicate) -> + gleam@dict:filter(Map, Predicate). + +-spec take(gleam@dict:dict(DAK, DCE), list(DAK)) -> gleam@dict:dict(DAK, DCE). +take(Map, Desired_keys) -> + gleam@dict:take(Map, Desired_keys). + +-spec merge(gleam@dict:dict(DCF, DCG), gleam@dict:dict(DCF, DCG)) -> gleam@dict:dict(DCF, DCG). +merge(Map, New_entries) -> + gleam@dict:merge(Map, New_entries). + +-spec delete(gleam@dict:dict(DAR, DCI), DAR) -> gleam@dict:dict(DAR, DCI). +delete(Map, Key) -> + gleam@dict:delete(Map, Key). + +-spec drop(gleam@dict:dict(DAU, DCK), list(DAU)) -> gleam@dict:dict(DAU, DCK). +drop(Map, Disallowed_keys) -> + gleam@dict:drop(Map, Disallowed_keys). + +-spec update( + gleam@dict:dict(DAY, DAZ), + DAY, + fun((gleam@option:option(DAZ)) -> DAZ) +) -> gleam@dict:dict(DAY, DAZ). +update(Map, Key, Fun) -> + gleam@dict:update(Map, Key, Fun). + +-spec fold(gleam@dict:dict(DBE, DBF), DBD, fun((DBD, DBE, DBF) -> DBD)) -> DBD. +fold(Map, Initial, Fun) -> + gleam@dict:fold(Map, Initial, Fun). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache Binary files differnew file mode 100644 index 0000000..7ac8412 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta Binary files differnew file mode 100644 index 0000000..ff8f8df --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.erl new file mode 100644 index 0000000..6c9768c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@option.erl @@ -0,0 +1,147 @@ +-module(gleam@option). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([all/1, is_some/1, is_none/1, to_result/2, from_result/1, unwrap/2, lazy_unwrap/2, map/2, flatten/1, then/2, 'or'/2, lazy_or/2, values/1]). +-export_type([option/1]). + +-type option(GB) :: {some, GB} | none. + +-spec do_all(list(option(GC)), list(GC)) -> option(list(GC)). +do_all(List, Acc) -> + case List of + [] -> + {some, Acc}; + + [X | Rest] -> + Accumulate = fun(Acc@1, Item) -> case {Acc@1, Item} of + {{some, Values}, {some, Value}} -> + {some, [Value | Values]}; + + {_, _} -> + none + end end, + Accumulate(do_all(Rest, Acc), X) + end. + +-spec all(list(option(GI))) -> option(list(GI)). +all(List) -> + do_all(List, []). + +-spec is_some(option(any())) -> boolean(). +is_some(Option) -> + Option /= none. + +-spec is_none(option(any())) -> boolean(). +is_none(Option) -> + Option =:= none. + +-spec to_result(option(GR), GU) -> {ok, GR} | {error, GU}. +to_result(Option, E) -> + case Option of + {some, A} -> + {ok, A}; + + _ -> + {error, E} + end. + +-spec from_result({ok, GX} | {error, any()}) -> option(GX). +from_result(Result) -> + case Result of + {ok, A} -> + {some, A}; + + _ -> + none + end. + +-spec unwrap(option(HC), HC) -> HC. +unwrap(Option, Default) -> + case Option of + {some, X} -> + X; + + none -> + Default + end. + +-spec lazy_unwrap(option(HE), fun(() -> HE)) -> HE. +lazy_unwrap(Option, Default) -> + case Option of + {some, X} -> + X; + + none -> + Default() + end. + +-spec map(option(HG), fun((HG) -> HI)) -> option(HI). +map(Option, Fun) -> + case Option of + {some, X} -> + {some, Fun(X)}; + + none -> + none + end. + +-spec flatten(option(option(HK))) -> option(HK). +flatten(Option) -> + case Option of + {some, X} -> + X; + + none -> + none + end. + +-spec then(option(HO), fun((HO) -> option(HQ))) -> option(HQ). +then(Option, Fun) -> + case Option of + {some, X} -> + Fun(X); + + none -> + none + end. + +-spec 'or'(option(HT), option(HT)) -> option(HT). +'or'(First, Second) -> + case First of + {some, _} -> + First; + + none -> + Second + end. + +-spec lazy_or(option(HX), fun(() -> option(HX))) -> option(HX). +lazy_or(First, Second) -> + case First of + {some, _} -> + First; + + none -> + Second() + end. + +-spec do_values(list(option(IB)), list(IB)) -> list(IB). +do_values(List, Acc) -> + case List of + [] -> + Acc; + + [X | Xs] -> + Accumulate = fun(Acc@1, Item) -> case Item of + {some, Value} -> + [Value | Acc@1]; + + none -> + Acc@1 + end end, + Accumulate(do_values(Xs, Acc), X) + end. + +-spec values(list(option(IG))) -> list(IG). +values(Options) -> + do_values(Options, []). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache Binary files differnew file mode 100644 index 0000000..42e5822 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta Binary files differnew file mode 100644 index 0000000..c304185 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.erl new file mode 100644 index 0000000..d4b225c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@order.erl @@ -0,0 +1,79 @@ +-module(gleam@order). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([negate/1, to_int/1, compare/2, max/2, min/2, reverse/1]). +-export_type([order/0]). + +-type order() :: lt | eq | gt. + +-spec negate(order()) -> order(). +negate(Order) -> + case Order of + lt -> + gt; + + eq -> + eq; + + gt -> + lt + end. + +-spec to_int(order()) -> integer(). +to_int(Order) -> + case Order of + lt -> + -1; + + eq -> + 0; + + gt -> + 1 + end. + +-spec compare(order(), order()) -> order(). +compare(A, B) -> + case {A, B} of + {X, Y} when X =:= Y -> + eq; + + {lt, _} -> + lt; + + {eq, gt} -> + lt; + + {_, _} -> + gt + end. + +-spec max(order(), order()) -> order(). +max(A, B) -> + case {A, B} of + {gt, _} -> + gt; + + {eq, lt} -> + eq; + + {_, _} -> + B + end. + +-spec min(order(), order()) -> order(). +min(A, B) -> + case {A, B} of + {lt, _} -> + lt; + + {eq, gt} -> + eq; + + {_, _} -> + B + end. + +-spec reverse(fun((I, I) -> order())) -> fun((I, I) -> order()). +reverse(Orderer) -> + fun(A, B) -> Orderer(B, A) end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache Binary files differnew file mode 100644 index 0000000..891b8cd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta Binary files differnew file mode 100644 index 0000000..8ee3fd8 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.erl new file mode 100644 index 0000000..8e5d10f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@pair.erl @@ -0,0 +1,33 @@ +-module(gleam@pair). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([first/1, second/1, swap/1, map_first/2, map_second/2, new/2]). + +-spec first({FM, any()}) -> FM. +first(Pair) -> + {A, _} = Pair, + A. + +-spec second({any(), FP}) -> FP. +second(Pair) -> + {_, A} = Pair, + A. + +-spec swap({FQ, FR}) -> {FR, FQ}. +swap(Pair) -> + {A, B} = Pair, + {B, A}. + +-spec map_first({FS, FT}, fun((FS) -> FU)) -> {FU, FT}. +map_first(Pair, Fun) -> + {A, B} = Pair, + {Fun(A), B}. + +-spec map_second({FV, FW}, fun((FW) -> FX)) -> {FV, FX}. +map_second(Pair, Fun) -> + {A, B} = Pair, + {A, Fun(B)}. + +-spec new(FY, FZ) -> {FY, FZ}. +new(First, Second) -> + {First, Second}. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache Binary files differnew file mode 100644 index 0000000..c7b14d2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache_meta Binary files differnew file mode 100644 index 0000000..26ea872 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.erl new file mode 100644 index 0000000..1f763d0 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@queue.erl @@ -0,0 +1,121 @@ +-module(gleam@queue). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/0, from_list/1, to_list/1, is_empty/1, length/1, push_back/2, push_front/2, pop_back/1, pop_front/1, reverse/1, is_logically_equal/3, is_equal/2]). +-export_type([queue/1]). + +-opaque queue(DNJ) :: {queue, list(DNJ), list(DNJ)}. + +-spec new() -> queue(any()). +new() -> + {queue, [], []}. + +-spec from_list(list(DNM)) -> queue(DNM). +from_list(List) -> + {queue, [], List}. + +-spec to_list(queue(DNP)) -> list(DNP). +to_list(Queue) -> + _pipe = erlang:element(3, Queue), + gleam@list:append(_pipe, gleam@list:reverse(erlang:element(2, Queue))). + +-spec is_empty(queue(any())) -> boolean(). +is_empty(Queue) -> + (erlang:element(2, Queue) =:= []) andalso (erlang:element(3, Queue) =:= []). + +-spec length(queue(any())) -> integer(). +length(Queue) -> + gleam@list:length(erlang:element(2, Queue)) + gleam@list:length( + erlang:element(3, Queue) + ). + +-spec push_back(queue(DNW), DNW) -> queue(DNW). +push_back(Queue, Item) -> + {queue, [Item | erlang:element(2, Queue)], erlang:element(3, Queue)}. + +-spec push_front(queue(DNZ), DNZ) -> queue(DNZ). +push_front(Queue, Item) -> + {queue, erlang:element(2, Queue), [Item | erlang:element(3, Queue)]}. + +-spec pop_back(queue(DOC)) -> {ok, {DOC, queue(DOC)}} | {error, nil}. +pop_back(Queue) -> + case Queue of + {queue, [], []} -> + {error, nil}; + + {queue, [], Out} -> + pop_back({queue, gleam@list:reverse(Out), []}); + + {queue, [First | Rest], Out@1} -> + Queue@1 = {queue, Rest, Out@1}, + {ok, {First, Queue@1}} + end. + +-spec pop_front(queue(DOH)) -> {ok, {DOH, queue(DOH)}} | {error, nil}. +pop_front(Queue) -> + case Queue of + {queue, [], []} -> + {error, nil}; + + {queue, In, []} -> + pop_front({queue, [], gleam@list:reverse(In)}); + + {queue, In@1, [First | Rest]} -> + Queue@1 = {queue, In@1, Rest}, + {ok, {First, Queue@1}} + end. + +-spec reverse(queue(DOM)) -> queue(DOM). +reverse(Queue) -> + {queue, erlang:element(3, Queue), erlang:element(2, Queue)}. + +-spec check_equal( + list(DOP), + list(DOP), + list(DOP), + list(DOP), + fun((DOP, DOP) -> boolean()) +) -> boolean(). +check_equal(Xs, X_tail, Ys, Y_tail, Eq) -> + case {Xs, X_tail, Ys, Y_tail} of + {[], [], [], []} -> + true; + + {[X | Xs@1], _, [Y | Ys@1], _} -> + case Eq(X, Y) of + false -> + false; + + true -> + check_equal(Xs@1, X_tail, Ys@1, Y_tail, Eq) + end; + + {[], [_ | _], _, _} -> + check_equal(gleam@list:reverse(X_tail), [], Ys, Y_tail, Eq); + + {_, _, [], [_ | _]} -> + check_equal(Xs, X_tail, gleam@list:reverse(Y_tail), [], Eq); + + {_, _, _, _} -> + false + end. + +-spec is_logically_equal(queue(DOU), queue(DOU), fun((DOU, DOU) -> boolean())) -> boolean(). +is_logically_equal(A, B, Element_is_equal) -> + check_equal( + erlang:element(3, A), + erlang:element(2, A), + erlang:element(3, B), + erlang:element(2, B), + Element_is_equal + ). + +-spec is_equal(queue(DOX), queue(DOX)) -> boolean(). +is_equal(A, B) -> + check_equal( + erlang:element(3, A), + erlang:element(2, A), + erlang:element(3, B), + erlang:element(2, B), + fun(A@1, B@1) -> A@1 =:= B@1 end + ). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache Binary files differnew file mode 100644 index 0000000..ba8d28b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache_meta Binary files differnew file mode 100644 index 0000000..ab416af --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.erl new file mode 100644 index 0000000..f49cc28 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@regex.erl @@ -0,0 +1,33 @@ +-module(gleam@regex). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([compile/2, from_string/1, check/2, split/2, scan/2]). +-export_type([regex/0, match/0, compile_error/0, options/0]). + +-type regex() :: any(). + +-type match() :: {match, binary(), list(gleam@option:option(binary()))}. + +-type compile_error() :: {compile_error, binary(), integer()}. + +-type options() :: {options, boolean(), boolean()}. + +-spec compile(binary(), options()) -> {ok, regex()} | {error, compile_error()}. +compile(Pattern, Options) -> + gleam_stdlib:compile_regex(Pattern, Options). + +-spec from_string(binary()) -> {ok, regex()} | {error, compile_error()}. +from_string(Pattern) -> + compile(Pattern, {options, false, false}). + +-spec check(regex(), binary()) -> boolean(). +check(Regex, Content) -> + gleam_stdlib:regex_check(Regex, Content). + +-spec split(regex(), binary()) -> list(binary()). +split(Regex, String) -> + gleam_stdlib:regex_split(Regex, String). + +-spec scan(regex(), binary()) -> list(match()). +scan(Regex, String) -> + gleam_stdlib:regex_scan(Regex, String). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache Binary files differnew file mode 100644 index 0000000..1d77445 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta Binary files differnew file mode 100644 index 0000000..732654a --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.erl new file mode 100644 index 0000000..564982f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@result.erl @@ -0,0 +1,201 @@ +-module(gleam@result). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([is_ok/1, is_error/1, map/2, map_error/2, flatten/1, 'try'/2, then/2, unwrap/2, lazy_unwrap/2, unwrap_error/2, unwrap_both/1, nil_error/1, 'or'/2, lazy_or/2, all/1, partition/1, replace/2, replace_error/2, values/1, try_recover/2]). + +-spec is_ok({ok, any()} | {error, any()}) -> boolean(). +is_ok(Result) -> + case Result of + {error, _} -> + false; + + {ok, _} -> + true + end. + +-spec is_error({ok, any()} | {error, any()}) -> boolean(). +is_error(Result) -> + case Result of + {ok, _} -> + false; + + {error, _} -> + true + end. + +-spec map({ok, BFM} | {error, BFN}, fun((BFM) -> BFQ)) -> {ok, BFQ} | + {error, BFN}. +map(Result, Fun) -> + case Result of + {ok, X} -> + {ok, Fun(X)}; + + {error, E} -> + {error, E} + end. + +-spec map_error({ok, BFT} | {error, BFU}, fun((BFU) -> BFX)) -> {ok, BFT} | + {error, BFX}. +map_error(Result, Fun) -> + case Result of + {ok, X} -> + {ok, X}; + + {error, Error} -> + {error, Fun(Error)} + end. + +-spec flatten({ok, {ok, BGA} | {error, BGB}} | {error, BGB}) -> {ok, BGA} | + {error, BGB}. +flatten(Result) -> + case Result of + {ok, X} -> + X; + + {error, Error} -> + {error, Error} + end. + +-spec 'try'({ok, BGI} | {error, BGJ}, fun((BGI) -> {ok, BGM} | {error, BGJ})) -> {ok, + BGM} | + {error, BGJ}. +'try'(Result, Fun) -> + case Result of + {ok, X} -> + Fun(X); + + {error, E} -> + {error, E} + end. + +-spec then({ok, BGR} | {error, BGS}, fun((BGR) -> {ok, BGV} | {error, BGS})) -> {ok, + BGV} | + {error, BGS}. +then(Result, Fun) -> + 'try'(Result, Fun). + +-spec unwrap({ok, BHA} | {error, any()}, BHA) -> BHA. +unwrap(Result, Default) -> + case Result of + {ok, V} -> + V; + + {error, _} -> + Default + end. + +-spec lazy_unwrap({ok, BHE} | {error, any()}, fun(() -> BHE)) -> BHE. +lazy_unwrap(Result, Default) -> + case Result of + {ok, V} -> + V; + + {error, _} -> + Default() + end. + +-spec unwrap_error({ok, any()} | {error, BHJ}, BHJ) -> BHJ. +unwrap_error(Result, Default) -> + case Result of + {ok, _} -> + Default; + + {error, E} -> + E + end. + +-spec unwrap_both({ok, BHM} | {error, BHM}) -> BHM. +unwrap_both(Result) -> + case Result of + {ok, A} -> + A; + + {error, A@1} -> + A@1 + end. + +-spec nil_error({ok, BHP} | {error, any()}) -> {ok, BHP} | {error, nil}. +nil_error(Result) -> + map_error(Result, fun(_) -> nil end). + +-spec 'or'({ok, BHV} | {error, BHW}, {ok, BHV} | {error, BHW}) -> {ok, BHV} | + {error, BHW}. +'or'(First, Second) -> + case First of + {ok, _} -> + First; + + {error, _} -> + Second + end. + +-spec lazy_or({ok, BID} | {error, BIE}, fun(() -> {ok, BID} | {error, BIE})) -> {ok, + BID} | + {error, BIE}. +lazy_or(First, Second) -> + case First of + {ok, _} -> + First; + + {error, _} -> + Second() + end. + +-spec all(list({ok, BIL} | {error, BIM})) -> {ok, list(BIL)} | {error, BIM}. +all(Results) -> + gleam@list:try_map(Results, fun(X) -> X end). + +-spec do_partition(list({ok, BJA} | {error, BJB}), list(BJA), list(BJB)) -> {list(BJA), + list(BJB)}. +do_partition(Results, Oks, Errors) -> + case Results of + [] -> + {Oks, Errors}; + + [{ok, A} | Rest] -> + do_partition(Rest, [A | Oks], Errors); + + [{error, E} | Rest@1] -> + do_partition(Rest@1, Oks, [E | Errors]) + end. + +-spec partition(list({ok, BIT} | {error, BIU})) -> {list(BIT), list(BIU)}. +partition(Results) -> + do_partition(Results, [], []). + +-spec replace({ok, any()} | {error, BJJ}, BJM) -> {ok, BJM} | {error, BJJ}. +replace(Result, Value) -> + case Result of + {ok, _} -> + {ok, Value}; + + {error, Error} -> + {error, Error} + end. + +-spec replace_error({ok, BJP} | {error, any()}, BJT) -> {ok, BJP} | {error, BJT}. +replace_error(Result, Error) -> + case Result of + {ok, X} -> + {ok, X}; + + {error, _} -> + {error, Error} + end. + +-spec values(list({ok, BJW} | {error, any()})) -> list(BJW). +values(Results) -> + gleam@list:filter_map(Results, fun(R) -> R end). + +-spec try_recover( + {ok, BKC} | {error, BKD}, + fun((BKD) -> {ok, BKC} | {error, BKG}) +) -> {ok, BKC} | {error, BKG}. +try_recover(Result, Fun) -> + case Result of + {ok, Value} -> + {ok, Value}; + + {error, Error} -> + Fun(Error) + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache Binary files differnew file mode 100644 index 0000000..c86e73f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta Binary files differnew file mode 100644 index 0000000..ee9607b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.erl new file mode 100644 index 0000000..1ccd4b1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@set.erl @@ -0,0 +1,85 @@ +-module(gleam@set). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/0, size/1, contains/2, delete/2, to_list/1, fold/3, filter/2, drop/2, take/2, intersection/2, insert/2, from_list/1, union/2]). +-export_type([set/1]). + +-opaque set(DIS) :: {set, gleam@dict:dict(DIS, list(nil))}. + +-spec new() -> set(any()). +new() -> + {set, gleam@dict:new()}. + +-spec size(set(any())) -> integer(). +size(Set) -> + gleam@dict:size(erlang:element(2, Set)). + +-spec contains(set(DJB), DJB) -> boolean(). +contains(Set, Member) -> + _pipe = erlang:element(2, Set), + _pipe@1 = gleam@dict:get(_pipe, Member), + gleam@result:is_ok(_pipe@1). + +-spec delete(set(DJD), DJD) -> set(DJD). +delete(Set, Member) -> + {set, gleam@dict:delete(erlang:element(2, Set), Member)}. + +-spec to_list(set(DJG)) -> list(DJG). +to_list(Set) -> + gleam@dict:keys(erlang:element(2, Set)). + +-spec fold(set(DJM), DJO, fun((DJO, DJM) -> DJO)) -> DJO. +fold(Set, Initial, Reducer) -> + gleam@dict:fold( + erlang:element(2, Set), + Initial, + fun(A, K, _) -> Reducer(A, K) end + ). + +-spec filter(set(DJP), fun((DJP) -> boolean())) -> set(DJP). +filter(Set, Predicate) -> + {set, + gleam@dict:filter(erlang:element(2, Set), fun(M, _) -> Predicate(M) end)}. + +-spec drop(set(DJS), list(DJS)) -> set(DJS). +drop(Set, Disallowed) -> + gleam@list:fold(Disallowed, Set, fun delete/2). + +-spec take(set(DJW), list(DJW)) -> set(DJW). +take(Set, Desired) -> + {set, gleam@dict:take(erlang:element(2, Set), Desired)}. + +-spec order(set(DKA), set(DKA)) -> {set(DKA), set(DKA)}. +order(First, Second) -> + case gleam@dict:size(erlang:element(2, First)) > gleam@dict:size( + erlang:element(2, Second) + ) of + true -> + {First, Second}; + + false -> + {Second, First} + end. + +-spec intersection(set(DKJ), set(DKJ)) -> set(DKJ). +intersection(First, Second) -> + {Larger, Smaller} = order(First, Second), + take(Larger, to_list(Smaller)). + +-spec insert(set(DIY), DIY) -> set(DIY). +insert(Set, Member) -> + {set, gleam@dict:insert(erlang:element(2, Set), Member, [])}. + +-spec from_list(list(DJJ)) -> set(DJJ). +from_list(Members) -> + Map = gleam@list:fold( + Members, + gleam@dict:new(), + fun(M, K) -> gleam@dict:insert(M, K, []) end + ), + {set, Map}. + +-spec union(set(DKF), set(DKF)) -> set(DKF). +union(First, Second) -> + {Larger, Smaller} = order(First, Second), + fold(Smaller, Larger, fun insert/2). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache Binary files differnew file mode 100644 index 0000000..580f9e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta Binary files differnew file mode 100644 index 0000000..300d752 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.erl new file mode 100644 index 0000000..6df406b --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string.erl @@ -0,0 +1,352 @@ +-module(gleam@string). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([is_empty/1, length/1, reverse/1, replace/3, lowercase/1, uppercase/1, compare/2, slice/3, crop/2, drop_left/2, drop_right/2, contains/2, starts_with/2, ends_with/2, split_once/2, append/2, concat/1, repeat/2, join/2, pad_left/3, pad_right/3, trim/1, trim_left/1, trim_right/1, pop_grapheme/1, to_graphemes/1, split/2, to_utf_codepoints/1, from_utf_codepoints/1, utf_codepoint/1, utf_codepoint_to_int/1, to_option/1, first/1, last/1, capitalise/1, inspect/1, byte_size/1]). +-export_type([direction/0]). + +-type direction() :: leading | trailing | both. + +-spec is_empty(binary()) -> boolean(). +is_empty(Str) -> + Str =:= <<""/utf8>>. + +-spec length(binary()) -> integer(). +length(String) -> + string:length(String). + +-spec do_reverse(binary()) -> binary(). +do_reverse(String) -> + _pipe = String, + _pipe@1 = gleam@string_builder:from_string(_pipe), + _pipe@2 = gleam@string_builder:reverse(_pipe@1), + gleam@string_builder:to_string(_pipe@2). + +-spec reverse(binary()) -> binary(). +reverse(String) -> + do_reverse(String). + +-spec replace(binary(), binary(), binary()) -> binary(). +replace(String, Pattern, Substitute) -> + _pipe = String, + _pipe@1 = gleam@string_builder:from_string(_pipe), + _pipe@2 = gleam@string_builder:replace(_pipe@1, Pattern, Substitute), + gleam@string_builder:to_string(_pipe@2). + +-spec lowercase(binary()) -> binary(). +lowercase(String) -> + string:lowercase(String). + +-spec uppercase(binary()) -> binary(). +uppercase(String) -> + string:uppercase(String). + +-spec compare(binary(), binary()) -> gleam@order:order(). +compare(A, B) -> + case A =:= B of + true -> + eq; + + _ -> + case gleam_stdlib:less_than(A, B) of + true -> + lt; + + _ -> + gt + end + end. + +-spec slice(binary(), integer(), integer()) -> binary(). +slice(String, Idx, Len) -> + case Len < 0 of + true -> + <<""/utf8>>; + + false -> + case Idx < 0 of + true -> + Translated_idx = length(String) + Idx, + case Translated_idx < 0 of + true -> + <<""/utf8>>; + + false -> + string:slice(String, Translated_idx, Len) + end; + + false -> + string:slice(String, Idx, Len) + end + end. + +-spec crop(binary(), binary()) -> binary(). +crop(String, Substring) -> + gleam_stdlib:crop_string(String, Substring). + +-spec drop_left(binary(), integer()) -> binary(). +drop_left(String, Num_graphemes) -> + case Num_graphemes < 0 of + true -> + String; + + false -> + slice(String, Num_graphemes, length(String) - Num_graphemes) + end. + +-spec drop_right(binary(), integer()) -> binary(). +drop_right(String, Num_graphemes) -> + case Num_graphemes < 0 of + true -> + String; + + false -> + slice(String, 0, length(String) - Num_graphemes) + end. + +-spec contains(binary(), binary()) -> boolean(). +contains(Haystack, Needle) -> + gleam_stdlib:contains_string(Haystack, Needle). + +-spec starts_with(binary(), binary()) -> boolean(). +starts_with(String, Prefix) -> + gleam_stdlib:string_starts_with(String, Prefix). + +-spec ends_with(binary(), binary()) -> boolean(). +ends_with(String, Suffix) -> + gleam_stdlib:string_ends_with(String, Suffix). + +-spec do_split_once(binary(), binary()) -> {ok, {binary(), binary()}} | + {error, nil}. +do_split_once(X, Substring) -> + case string:split(X, Substring) of + [First, Rest] -> + {ok, {First, Rest}}; + + _ -> + {error, nil} + end. + +-spec split_once(binary(), binary()) -> {ok, {binary(), binary()}} | + {error, nil}. +split_once(X, Substring) -> + do_split_once(X, Substring). + +-spec append(binary(), binary()) -> binary(). +append(First, Second) -> + _pipe = First, + _pipe@1 = gleam@string_builder:from_string(_pipe), + _pipe@2 = gleam@string_builder:append(_pipe@1, Second), + gleam@string_builder:to_string(_pipe@2). + +-spec concat(list(binary())) -> binary(). +concat(Strings) -> + _pipe = Strings, + _pipe@1 = gleam@string_builder:from_strings(_pipe), + gleam@string_builder:to_string(_pipe@1). + +-spec repeat(binary(), integer()) -> binary(). +repeat(String, Times) -> + _pipe = gleam@iterator:repeat(String), + _pipe@1 = gleam@iterator:take(_pipe, Times), + _pipe@2 = gleam@iterator:to_list(_pipe@1), + concat(_pipe@2). + +-spec do_join(list(binary()), binary()) -> binary(). +do_join(Strings, Separator) -> + _pipe = Strings, + _pipe@1 = gleam@list:intersperse(_pipe, Separator), + concat(_pipe@1). + +-spec join(list(binary()), binary()) -> binary(). +join(Strings, Separator) -> + do_join(Strings, Separator). + +-spec padding(integer(), binary()) -> gleam@iterator:iterator(binary()). +padding(Size, Pad_string) -> + Pad_length = length(Pad_string), + Num_pads = case Pad_length of + 0 -> 0; + Gleam@denominator -> Size div Gleam@denominator + end, + Extra = case Pad_length of + 0 -> 0; + Gleam@denominator@1 -> Size rem Gleam@denominator@1 + end, + _pipe = gleam@iterator:repeat(Pad_string), + _pipe@1 = gleam@iterator:take(_pipe, Num_pads), + gleam@iterator:append( + _pipe@1, + gleam@iterator:single(slice(Pad_string, 0, Extra)) + ). + +-spec pad_left(binary(), integer(), binary()) -> binary(). +pad_left(String, Desired_length, Pad_string) -> + Current_length = length(String), + To_pad_length = Desired_length - Current_length, + _pipe = padding(To_pad_length, Pad_string), + _pipe@1 = gleam@iterator:append(_pipe, gleam@iterator:single(String)), + _pipe@2 = gleam@iterator:to_list(_pipe@1), + concat(_pipe@2). + +-spec pad_right(binary(), integer(), binary()) -> binary(). +pad_right(String, Desired_length, Pad_string) -> + Current_length = length(String), + To_pad_length = Desired_length - Current_length, + _pipe = gleam@iterator:single(String), + _pipe@1 = gleam@iterator:append(_pipe, padding(To_pad_length, Pad_string)), + _pipe@2 = gleam@iterator:to_list(_pipe@1), + concat(_pipe@2). + +-spec do_trim(binary()) -> binary(). +do_trim(String) -> + string:trim(String, both). + +-spec trim(binary()) -> binary(). +trim(String) -> + do_trim(String). + +-spec do_trim_left(binary()) -> binary(). +do_trim_left(String) -> + string:trim(String, leading). + +-spec trim_left(binary()) -> binary(). +trim_left(String) -> + do_trim_left(String). + +-spec do_trim_right(binary()) -> binary(). +do_trim_right(String) -> + string:trim(String, trailing). + +-spec trim_right(binary()) -> binary(). +trim_right(String) -> + do_trim_right(String). + +-spec pop_grapheme(binary()) -> {ok, {binary(), binary()}} | {error, nil}. +pop_grapheme(String) -> + gleam_stdlib:string_pop_grapheme(String). + +-spec do_to_graphemes(binary(), list(binary())) -> list(binary()). +do_to_graphemes(String, Acc) -> + case pop_grapheme(String) of + {ok, {Grapheme, Rest}} -> + do_to_graphemes(Rest, [Grapheme | Acc]); + + _ -> + Acc + end. + +-spec to_graphemes(binary()) -> list(binary()). +to_graphemes(String) -> + _pipe = do_to_graphemes(String, []), + gleam@list:reverse(_pipe). + +-spec split(binary(), binary()) -> list(binary()). +split(X, Substring) -> + case Substring of + <<""/utf8>> -> + to_graphemes(X); + + _ -> + _pipe = X, + _pipe@1 = gleam@string_builder:from_string(_pipe), + _pipe@2 = gleam@string_builder:split(_pipe@1, Substring), + gleam@list:map(_pipe@2, fun gleam@string_builder:to_string/1) + end. + +-spec do_to_utf_codepoints_impl(bitstring(), list(integer())) -> list(integer()). +do_to_utf_codepoints_impl(Bit_array, Acc) -> + case Bit_array of + <<First/utf8, Rest/binary>> -> + do_to_utf_codepoints_impl(Rest, [First | Acc]); + + _ -> + Acc + end. + +-spec do_to_utf_codepoints(binary()) -> list(integer()). +do_to_utf_codepoints(String) -> + _pipe = do_to_utf_codepoints_impl(<<String/binary>>, []), + gleam@list:reverse(_pipe). + +-spec to_utf_codepoints(binary()) -> list(integer()). +to_utf_codepoints(String) -> + do_to_utf_codepoints(String). + +-spec from_utf_codepoints(list(integer())) -> binary(). +from_utf_codepoints(Utf_codepoints) -> + gleam_stdlib:utf_codepoint_list_to_string(Utf_codepoints). + +-spec utf_codepoint(integer()) -> {ok, integer()} | {error, nil}. +utf_codepoint(Value) -> + case Value of + I when I > 1114111 -> + {error, nil}; + + 65534 -> + {error, nil}; + + 65535 -> + {error, nil}; + + I@1 when (I@1 >= 55296) andalso (I@1 =< 57343) -> + {error, nil}; + + I@2 -> + {ok, gleam_stdlib:identity(I@2)} + end. + +-spec utf_codepoint_to_int(integer()) -> integer(). +utf_codepoint_to_int(Cp) -> + gleam_stdlib:identity(Cp). + +-spec to_option(binary()) -> gleam@option:option(binary()). +to_option(S) -> + case S of + <<""/utf8>> -> + none; + + _ -> + {some, S} + end. + +-spec first(binary()) -> {ok, binary()} | {error, nil}. +first(S) -> + case pop_grapheme(S) of + {ok, {First, _}} -> + {ok, First}; + + {error, E} -> + {error, E} + end. + +-spec last(binary()) -> {ok, binary()} | {error, nil}. +last(S) -> + case pop_grapheme(S) of + {ok, {First, <<""/utf8>>}} -> + {ok, First}; + + {ok, {_, Rest}} -> + {ok, slice(Rest, -1, 1)}; + + {error, E} -> + {error, E} + end. + +-spec capitalise(binary()) -> binary(). +capitalise(S) -> + case pop_grapheme(S) of + {ok, {First, Rest}} -> + append(uppercase(First), lowercase(Rest)); + + _ -> + <<""/utf8>> + end. + +-spec inspect(any()) -> binary(). +inspect(Term) -> + _pipe = gleam_stdlib:inspect(Term), + gleam@string_builder:to_string(_pipe). + +-spec byte_size(binary()) -> integer(). +byte_size(String) -> + erlang:byte_size(String). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache Binary files differnew file mode 100644 index 0000000..a92f14c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache_meta Binary files differnew file mode 100644 index 0000000..2ef42cf --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.erl new file mode 100644 index 0000000..068bcc1 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@string_builder.erl @@ -0,0 +1,91 @@ +-module(gleam@string_builder). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([prepend_builder/2, append_builder/2, new/0, from_strings/1, concat/1, from_string/1, prepend/2, append/2, to_string/1, byte_size/1, join/2, lowercase/1, uppercase/1, reverse/1, split/2, replace/3, is_equal/2, is_empty/1]). +-export_type([string_builder/0, direction/0]). + +-type string_builder() :: any(). + +-type direction() :: all. + +-spec prepend_builder(string_builder(), string_builder()) -> string_builder(). +prepend_builder(Builder, Prefix) -> + gleam_stdlib:iodata_append(Prefix, Builder). + +-spec append_builder(string_builder(), string_builder()) -> string_builder(). +append_builder(Builder, Suffix) -> + gleam_stdlib:iodata_append(Builder, Suffix). + +-spec new() -> string_builder(). +new() -> + gleam_stdlib:identity([]). + +-spec from_strings(list(binary())) -> string_builder(). +from_strings(Strings) -> + gleam_stdlib:identity(Strings). + +-spec concat(list(string_builder())) -> string_builder(). +concat(Builders) -> + gleam_stdlib:identity(Builders). + +-spec from_string(binary()) -> string_builder(). +from_string(String) -> + gleam_stdlib:identity(String). + +-spec prepend(string_builder(), binary()) -> string_builder(). +prepend(Builder, Prefix) -> + append_builder(from_string(Prefix), Builder). + +-spec append(string_builder(), binary()) -> string_builder(). +append(Builder, Second) -> + append_builder(Builder, from_string(Second)). + +-spec to_string(string_builder()) -> binary(). +to_string(Builder) -> + unicode:characters_to_binary(Builder). + +-spec byte_size(string_builder()) -> integer(). +byte_size(Builder) -> + erlang:iolist_size(Builder). + +-spec join(list(string_builder()), binary()) -> string_builder(). +join(Builders, Sep) -> + _pipe = Builders, + _pipe@1 = gleam@list:intersperse(_pipe, from_string(Sep)), + concat(_pipe@1). + +-spec lowercase(string_builder()) -> string_builder(). +lowercase(Builder) -> + string:lowercase(Builder). + +-spec uppercase(string_builder()) -> string_builder(). +uppercase(Builder) -> + string:uppercase(Builder). + +-spec reverse(string_builder()) -> string_builder(). +reverse(Builder) -> + string:reverse(Builder). + +-spec do_split(string_builder(), binary()) -> list(string_builder()). +do_split(Iodata, Pattern) -> + string:split(Iodata, Pattern, all). + +-spec split(string_builder(), binary()) -> list(string_builder()). +split(Iodata, Pattern) -> + do_split(Iodata, Pattern). + +-spec do_replace(string_builder(), binary(), binary()) -> string_builder(). +do_replace(Iodata, Pattern, Substitute) -> + string:replace(Iodata, Pattern, Substitute, all). + +-spec replace(string_builder(), binary(), binary()) -> string_builder(). +replace(Builder, Pattern, Substitute) -> + do_replace(Builder, Pattern, Substitute). + +-spec is_equal(string_builder(), string_builder()) -> boolean(). +is_equal(A, B) -> + string:equal(A, B). + +-spec is_empty(string_builder()) -> boolean(). +is_empty(Builder) -> + string:is_empty(Builder). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache Binary files differnew file mode 100644 index 0000000..f3328fc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta Binary files differnew file mode 100644 index 0000000..a8195fc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.cache_meta diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.erl new file mode 100644 index 0000000..c66ac2e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam@uri.erl @@ -0,0 +1,252 @@ +-module(gleam@uri). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([parse/1, parse_query/1, percent_encode/1, query_to_string/1, percent_decode/1, path_segments/1, to_string/1, origin/1, merge/2]). +-export_type([uri/0]). + +-type uri() :: {uri, + gleam@option:option(binary()), + gleam@option:option(binary()), + gleam@option:option(binary()), + gleam@option:option(integer()), + binary(), + gleam@option:option(binary()), + gleam@option:option(binary())}. + +-spec parse(binary()) -> {ok, uri()} | {error, nil}. +parse(Uri_string) -> + gleam_stdlib:uri_parse(Uri_string). + +-spec parse_query(binary()) -> {ok, list({binary(), binary()})} | {error, nil}. +parse_query(Query) -> + gleam_stdlib:parse_query(Query). + +-spec percent_encode(binary()) -> binary(). +percent_encode(Value) -> + gleam_stdlib:percent_encode(Value). + +-spec query_pair({binary(), binary()}) -> gleam@string_builder:string_builder(). +query_pair(Pair) -> + gleam@string_builder:from_strings( + [percent_encode(erlang:element(1, Pair)), + <<"="/utf8>>, + percent_encode(erlang:element(2, Pair))] + ). + +-spec query_to_string(list({binary(), binary()})) -> binary(). +query_to_string(Query) -> + _pipe = Query, + _pipe@1 = gleam@list:map(_pipe, fun query_pair/1), + _pipe@2 = gleam@list:intersperse( + _pipe@1, + gleam@string_builder:from_string(<<"&"/utf8>>) + ), + _pipe@3 = gleam@string_builder:concat(_pipe@2), + gleam@string_builder:to_string(_pipe@3). + +-spec percent_decode(binary()) -> {ok, binary()} | {error, nil}. +percent_decode(Value) -> + gleam_stdlib:percent_decode(Value). + +-spec do_remove_dot_segments(list(binary()), list(binary())) -> list(binary()). +do_remove_dot_segments(Input, Accumulator) -> + case Input of + [] -> + gleam@list:reverse(Accumulator); + + [Segment | Rest] -> + Accumulator@5 = case {Segment, Accumulator} of + {<<""/utf8>>, Accumulator@1} -> + Accumulator@1; + + {<<"."/utf8>>, Accumulator@2} -> + Accumulator@2; + + {<<".."/utf8>>, []} -> + []; + + {<<".."/utf8>>, [_ | Accumulator@3]} -> + Accumulator@3; + + {Segment@1, Accumulator@4} -> + [Segment@1 | Accumulator@4] + end, + do_remove_dot_segments(Rest, Accumulator@5) + end. + +-spec remove_dot_segments(list(binary())) -> list(binary()). +remove_dot_segments(Input) -> + do_remove_dot_segments(Input, []). + +-spec path_segments(binary()) -> list(binary()). +path_segments(Path) -> + remove_dot_segments(gleam@string:split(Path, <<"/"/utf8>>)). + +-spec to_string(uri()) -> binary(). +to_string(Uri) -> + Parts = case erlang:element(8, Uri) of + {some, Fragment} -> + [<<"#"/utf8>>, Fragment]; + + _ -> + [] + end, + Parts@1 = case erlang:element(7, Uri) of + {some, Query} -> + [<<"?"/utf8>>, Query | Parts]; + + _ -> + Parts + end, + Parts@2 = [erlang:element(6, Uri) | Parts@1], + Parts@3 = case {erlang:element(4, Uri), + gleam@string:starts_with(erlang:element(6, Uri), <<"/"/utf8>>)} of + {{some, Host}, false} when Host =/= <<""/utf8>> -> + [<<"/"/utf8>> | Parts@2]; + + {_, _} -> + Parts@2 + end, + Parts@4 = case {erlang:element(4, Uri), erlang:element(5, Uri)} of + {{some, _}, {some, Port}} -> + [<<":"/utf8>>, gleam@int:to_string(Port) | Parts@3]; + + {_, _} -> + Parts@3 + end, + Parts@5 = case {erlang:element(2, Uri), + erlang:element(3, Uri), + erlang:element(4, Uri)} of + {{some, S}, {some, U}, {some, H}} -> + [S, <<"://"/utf8>>, U, <<"@"/utf8>>, H | Parts@4]; + + {{some, S@1}, none, {some, H@1}} -> + [S@1, <<"://"/utf8>>, H@1 | Parts@4]; + + {{some, S@2}, {some, _}, none} -> + [S@2, <<":"/utf8>> | Parts@4]; + + {{some, S@2}, none, none} -> + [S@2, <<":"/utf8>> | Parts@4]; + + {none, none, {some, H@2}} -> + [<<"//"/utf8>>, H@2 | Parts@4]; + + {_, _, _} -> + Parts@4 + end, + gleam@string:concat(Parts@5). + +-spec origin(uri()) -> {ok, binary()} | {error, nil}. +origin(Uri) -> + {uri, Scheme, _, Host, Port, _, _, _} = Uri, + case Scheme of + {some, <<"https"/utf8>>} when Port =:= {some, 443} -> + Origin = {uri, Scheme, none, Host, none, <<""/utf8>>, none, none}, + {ok, to_string(Origin)}; + + {some, <<"http"/utf8>>} when Port =:= {some, 80} -> + Origin@1 = {uri, Scheme, none, Host, none, <<""/utf8>>, none, none}, + {ok, to_string(Origin@1)}; + + {some, S} when (S =:= <<"http"/utf8>>) orelse (S =:= <<"https"/utf8>>) -> + Origin@2 = {uri, Scheme, none, Host, Port, <<""/utf8>>, none, none}, + {ok, to_string(Origin@2)}; + + _ -> + {error, nil} + end. + +-spec drop_last(list(FDC)) -> list(FDC). +drop_last(Elements) -> + gleam@list:take(Elements, gleam@list:length(Elements) - 1). + +-spec join_segments(list(binary())) -> binary(). +join_segments(Segments) -> + gleam@string:join([<<""/utf8>> | Segments], <<"/"/utf8>>). + +-spec merge(uri(), uri()) -> {ok, uri()} | {error, nil}. +merge(Base, Relative) -> + case Base of + {uri, {some, _}, _, {some, _}, _, _, _, _} -> + case Relative of + {uri, _, _, {some, _}, _, _, _, _} -> + Path = begin + _pipe = gleam@string:split( + erlang:element(6, Relative), + <<"/"/utf8>> + ), + _pipe@1 = remove_dot_segments(_pipe), + join_segments(_pipe@1) + end, + Resolved = {uri, + gleam@option:'or'( + erlang:element(2, Relative), + erlang:element(2, Base) + ), + none, + erlang:element(4, Relative), + gleam@option:'or'( + erlang:element(5, Relative), + erlang:element(5, Base) + ), + Path, + erlang:element(7, Relative), + erlang:element(8, Relative)}, + {ok, Resolved}; + + _ -> + {New_path, New_query} = case erlang:element(6, Relative) of + <<""/utf8>> -> + {erlang:element(6, Base), + gleam@option:'or'( + erlang:element(7, Relative), + erlang:element(7, Base) + )}; + + _ -> + Path_segments = case gleam@string:starts_with( + erlang:element(6, Relative), + <<"/"/utf8>> + ) of + true -> + gleam@string:split( + erlang:element(6, Relative), + <<"/"/utf8>> + ); + + false -> + _pipe@2 = gleam@string:split( + erlang:element(6, Base), + <<"/"/utf8>> + ), + _pipe@3 = drop_last(_pipe@2), + gleam@list:append( + _pipe@3, + gleam@string:split( + erlang:element(6, Relative), + <<"/"/utf8>> + ) + ) + end, + Path@1 = begin + _pipe@4 = Path_segments, + _pipe@5 = remove_dot_segments(_pipe@4), + join_segments(_pipe@5) + end, + {Path@1, erlang:element(7, Relative)} + end, + Resolved@1 = {uri, + erlang:element(2, Base), + none, + erlang:element(4, Base), + erlang:element(5, Base), + New_path, + New_query, + erlang:element(8, Relative)}, + {ok, Resolved@1} + end; + + _ -> + {error, nil} + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.erl b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.erl new file mode 100644 index 0000000..c6ea125 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.erl @@ -0,0 +1,529 @@ +-module(gleam_stdlib). + +-export([ + map_get/2, iodata_append/2, identity/1, decode_int/1, decode_bool/1, + decode_float/1, decode_list/1, decode_option/2, decode_field/2, parse_int/1, + parse_float/1, less_than/2, string_pop_grapheme/1, string_starts_with/2, + wrap_list/1, string_ends_with/2, string_pad/4, decode_map/1, uri_parse/1, + bit_array_int_to_u32/1, bit_array_int_from_u32/1, decode_result/1, + bit_array_slice/3, decode_bit_array/1, compile_regex/2, regex_scan/2, + percent_encode/1, percent_decode/1, regex_check/2, regex_split/2, + base_decode64/1, parse_query/1, bit_array_concat/1, size_of_tuple/1, + decode_tuple/1, decode_tuple2/1, decode_tuple3/1, decode_tuple4/1, + decode_tuple5/1, decode_tuple6/1, tuple_get/2, classify_dynamic/1, print/1, + println/1, print_error/1, println_error/1, inspect/1, float_to_string/1, + int_from_base_string/2, utf_codepoint_list_to_string/1, contains_string/2, + crop_string/2, base16_decode/1 +]). + +%% Taken from OTP's uri_string module +-define(DEC2HEX(X), + if ((X) >= 0) andalso ((X) =< 9) -> (X) + $0; + ((X) >= 10) andalso ((X) =< 15) -> (X) + $A - 10 + end). + +%% Taken from OTP's uri_string module +-define(HEX2DEC(X), + if ((X) >= $0) andalso ((X) =< $9) -> (X) - $0; + ((X) >= $A) andalso ((X) =< $F) -> (X) - $A + 10; + ((X) >= $a) andalso ((X) =< $f) -> (X) - $a + 10 + end). + +-define(is_lowercase_char(X), (X > 96 andalso X < 123)). +-define(is_underscore_char(X), (X == 95)). +-define(is_digit_char(X), (X > 47 andalso X < 58)). + +uppercase(X) -> X - 32. + +map_get(Map, Key) -> + case maps:find(Key, Map) of + error -> {error, nil}; + OkFound -> OkFound + end. + +iodata_append(Iodata, String) -> [Iodata, String]. + +identity(X) -> X. + +decode_error_msg(Expected, Data) when is_binary(Expected) -> + decode_error(Expected, classify_dynamic(Data)). +decode_error(Expected, Got) when is_binary(Expected) andalso is_binary(Got) -> + {error, [{decode_error, Expected, Got, []}]}. + +classify_dynamic(nil) -> <<"Nil">>; +classify_dynamic(X) when is_atom(X) -> <<"Atom">>; +classify_dynamic(X) when is_binary(X) -> <<"String">>; +classify_dynamic(X) when is_bitstring(X) -> <<"BitArray">>; +classify_dynamic(X) when is_integer(X) -> <<"Int">>; +classify_dynamic(X) when is_float(X) -> <<"Float">>; +classify_dynamic(X) when is_list(X) -> <<"List">>; +classify_dynamic(X) when is_boolean(X) -> <<"Bool">>; +classify_dynamic(X) when is_map(X) -> <<"Map">>; +classify_dynamic(X) when is_tuple(X) -> + iolist_to_binary(["Tuple of ", integer_to_list(tuple_size(X)), " elements"]); +classify_dynamic(X) when + is_function(X, 0) orelse is_function(X, 1) orelse is_function(X, 2) orelse + is_function(X, 3) orelse is_function(X, 4) orelse is_function(X, 5) orelse + is_function(X, 6) orelse is_function(X, 7) orelse is_function(X, 8) orelse + is_function(X, 9) orelse is_function(X, 10) orelse is_function(X, 11) orelse + is_function(X, 12) -> <<"Function">>; +classify_dynamic(_) -> <<"Some other type">>. + +decode_map(Data) when is_map(Data) -> {ok, Data}; +decode_map(Data) -> decode_error_msg(<<"Map">>, Data). + +decode_bit_array(Data) when is_bitstring(Data) -> {ok, Data}; +decode_bit_array(Data) -> decode_error_msg(<<"BitArray">>, Data). + +decode_int(Data) when is_integer(Data) -> {ok, Data}; +decode_int(Data) -> decode_error_msg(<<"Int">>, Data). + +decode_float(Data) when is_float(Data) -> {ok, Data}; +decode_float(Data) -> decode_error_msg(<<"Float">>, Data). + +decode_bool(Data) when is_boolean(Data) -> {ok, Data}; +decode_bool(Data) -> decode_error_msg(<<"Bool">>, Data). + +decode_list(Data) when is_list(Data) -> {ok, Data}; +decode_list(Data) -> decode_error_msg(<<"List">>, Data). + +decode_field(Data, Key) when is_map(Data) -> + case Data of + #{Key := Value} -> {ok, {some, Value}}; + _ -> + {ok, none} + end; +decode_field(Data, _) -> + decode_error_msg(<<"Map">>, Data). + +size_of_tuple(Data) -> tuple_size(Data). + +tuple_get(_tup, Index) when Index < 0 -> {error, nil}; +tuple_get(Data, Index) when Index >= tuple_size(Data) -> {error, nil}; +tuple_get(Data, Index) -> {ok, element(Index + 1, Data)}. + +decode_tuple(Data) when is_tuple(Data) -> {ok, Data}; +decode_tuple(Data) -> decode_error_msg(<<"Tuple">>, Data). + +decode_tuple2({_,_} = A) -> {ok, A}; +decode_tuple2([A,B]) -> {ok, {A,B}}; +decode_tuple2(Data) -> decode_error_msg(<<"Tuple of 2 elements">>, Data). + +decode_tuple3({_,_,_} = A) -> {ok, A}; +decode_tuple3([A,B,C]) -> {ok, {A,B,C}}; +decode_tuple3(Data) -> decode_error_msg(<<"Tuple of 3 elements">>, Data). + +decode_tuple4({_,_,_,_} = A) -> {ok, A}; +decode_tuple4([A,B,C,D]) -> {ok, {A,B,C,D}}; +decode_tuple4(Data) -> decode_error_msg(<<"Tuple of 4 elements">>, Data). + +decode_tuple5({_,_,_,_,_} = A) -> {ok, A}; +decode_tuple5([A,B,C,D,E]) -> {ok, {A,B,C,D,E}}; +decode_tuple5(Data) -> decode_error_msg(<<"Tuple of 5 elements">>, Data). + +decode_tuple6({_,_,_,_,_,_} = A) -> {ok, A}; +decode_tuple6([A,B,C,D,E,F]) -> {ok, {A,B,C,D,E,F}}; +decode_tuple6(Data) -> decode_error_msg(<<"Tuple of 6 elements">>, Data). + +decode_option(Term, F) -> + Decode = fun(Inner) -> + case F(Inner) of + {ok, Decoded} -> {ok, {some, Decoded}}; + Error -> Error + end + end, + case Term of + undefined -> {ok, none}; + error -> {ok, none}; + null -> {ok, none}; + none -> {ok, none}; + nil -> {ok, none}; + {some, Inner} -> Decode(Inner); + _ -> Decode(Term) + end. + +decode_result(Term) -> + case Term of + {ok, Inner} -> {ok, {ok, Inner}}; + ok -> {ok, {ok, nil}}; + {error, Inner} -> {ok, {error, Inner}}; + error -> {ok, {error, nil}}; + _ -> decode_error_msg(<<"Result">>, Term) + end. + +int_from_base_string(String, Base) -> + case catch binary_to_integer(String, Base) of + Int when is_integer(Int) -> {ok, Int}; + _ -> {error, nil} + end. + +parse_int(String) -> + case catch binary_to_integer(String) of + Int when is_integer(Int) -> {ok, Int}; + _ -> {error, nil} + end. + +parse_float(String) -> + case catch binary_to_float(String) of + Float when is_float(Float) -> {ok, Float}; + _ -> {error, nil} + end. + +less_than(Lhs, Rhs) -> + Lhs < Rhs. + +string_starts_with(_, <<>>) -> true; +string_starts_with(String, Prefix) when byte_size(Prefix) > byte_size(String) -> false; +string_starts_with(String, Prefix) -> + PrefixSize = byte_size(Prefix), + Prefix == binary_part(String, 0, PrefixSize). + +string_ends_with(_, <<>>) -> true; +string_ends_with(String, Suffix) when byte_size(Suffix) > byte_size(String) -> false; +string_ends_with(String, Suffix) -> + SuffixSize = byte_size(Suffix), + Suffix == binary_part(String, byte_size(String) - SuffixSize, SuffixSize). + +string_pad(String, Length, Dir, PadString) -> + Chars = string:pad(String, Length, Dir, binary_to_list(PadString)), + case unicode:characters_to_binary(Chars) of + Bin when is_binary(Bin) -> Bin; + Error -> erlang:error({gleam_error, {string_invalid_utf8, Error}}) + end. + +string_pop_grapheme(String) -> + case string:next_grapheme(String) of + [ Next | Rest ] -> + {ok, {unicode:characters_to_binary([Next]), unicode:characters_to_binary(Rest)}}; + _ -> {error, nil} + end. + +bit_array_concat(BitArrays) -> + list_to_bitstring(BitArrays). + +bit_array_slice(Bin, Pos, Len) -> + try {ok, binary:part(Bin, Pos, Len)} + catch error:badarg -> {error, nil} + end. + +bit_array_int_to_u32(I) when 0 =< I, I < 4294967296 -> + {ok, <<I:32>>}; +bit_array_int_to_u32(_) -> + {error, nil}. + +bit_array_int_from_u32(<<I:32>>) -> + {ok, I}; +bit_array_int_from_u32(_) -> + {error, nil}. + +compile_regex(String, Options) -> + {options, Caseless, Multiline} = Options, + OptionsList = [ + unicode, + ucp, + Caseless andalso caseless, + Multiline andalso multiline + ], + FilteredOptions = [Option || Option <- OptionsList, Option /= false], + case re:compile(String, FilteredOptions) of + {ok, MP} -> {ok, MP}; + {error, {Str, Pos}} -> + {error, {compile_error, unicode:characters_to_binary(Str), Pos}} + end. + +regex_check(Regex, String) -> + re:run(String, Regex) /= nomatch. + +regex_split(Regex, String) -> + re:split(String, Regex). + +regex_submatches(_, {-1, 0}) -> none; +regex_submatches(String, {Start, Length}) -> + BinarySlice = binary:part(String, {Start, Length}), + case string:is_empty(binary_to_list(BinarySlice)) of + true -> none; + false -> {some, BinarySlice} + end. + +regex_matches(String, [{Start, Length} | Submatches]) -> + Submatches1 = lists:map(fun(X) -> regex_submatches(String, X) end, Submatches), + {match, binary:part(String, Start, Length), Submatches1}. + +regex_scan(Regex, String) -> + case re:run(String, Regex, [global]) of + {match, Captured} -> lists:map(fun(X) -> regex_matches(String, X) end, Captured); + nomatch -> [] + end. + +base_decode64(S) -> + try {ok, base64:decode(S)} + catch error:_ -> {error, nil} + end. + +wrap_list(X) when is_list(X) -> X; +wrap_list(X) -> [X]. + +parse_query(Query) -> + case uri_string:dissect_query(Query) of + {error, _, _} -> {error, nil}; + Pairs -> + Pairs1 = lists:map(fun + ({K, true}) -> {K, <<"">>}; + (Pair) -> Pair + end, Pairs), + {ok, Pairs1} + end. + +percent_encode(B) -> percent_encode(B, <<>>). +percent_encode(<<>>, Acc) -> + Acc; +percent_encode(<<H,T/binary>>, Acc) -> + case percent_ok(H) of + true -> + percent_encode(T, <<Acc/binary,H>>); + false -> + <<A:4,B:4>> = <<H>>, + percent_encode(T, <<Acc/binary,$%,(?DEC2HEX(A)),(?DEC2HEX(B))>>) + end. + +percent_decode(Cs) -> percent_decode(Cs, <<>>). +percent_decode(<<$%, C0, C1, Cs/binary>>, Acc) -> + case is_hex_digit(C0) andalso is_hex_digit(C1) of + true -> + B = ?HEX2DEC(C0)*16+?HEX2DEC(C1), + percent_decode(Cs, <<Acc/binary, B>>); + false -> + {error, nil} + end; +percent_decode(<<C,Cs/binary>>, Acc) -> + percent_decode(Cs, <<Acc/binary, C>>); +percent_decode(<<>>, Acc) -> + check_utf8(Acc). + +percent_ok($!) -> true; +percent_ok($$) -> true; +percent_ok($') -> true; +percent_ok($() -> true; +percent_ok($)) -> true; +percent_ok($*) -> true; +percent_ok($+) -> true; +percent_ok($-) -> true; +percent_ok($.) -> true; +percent_ok($_) -> true; +percent_ok($~) -> true; +percent_ok(C) when $0 =< C, C =< $9 -> true; +percent_ok(C) when $A =< C, C =< $Z -> true; +percent_ok(C) when $a =< C, C =< $z -> true; +percent_ok(_) -> false. + +is_hex_digit(C) -> + ($0 =< C andalso C =< $9) orelse ($a =< C andalso C =< $f) orelse ($A =< C andalso C =< $F). + +check_utf8(Cs) -> + case unicode:characters_to_list(Cs) of + {incomplete, _, _} -> {error, nil}; + {error, _, _} -> {error, nil}; + _ -> {ok, Cs} + end. + +uri_parse(String) -> + case uri_string:parse(String) of + {error, _, _} -> {error, nil}; + Uri -> + {ok, {uri, + maps_get_optional(Uri, scheme), + maps_get_optional(Uri, userinfo), + maps_get_optional(Uri, host), + maps_get_optional(Uri, port), + maps_get_or(Uri, path, <<>>), + maps_get_optional(Uri, query), + maps_get_optional(Uri, fragment) + }} + end. + +maps_get_optional(Map, Key) -> + try {some, maps:get(Key, Map)} + catch _:_ -> none + end. + +maps_get_or(Map, Key, Default) -> + try maps:get(Key, Map) + catch _:_ -> Default + end. + +print(String) -> + io:put_chars(String), + nil. + +println(String) -> + io:put_chars([String, $\n]), + nil. + +print_error(String) -> + io:put_chars(standard_error, String), + nil. + +println_error(String) -> + io:put_chars(standard_error, [String, $\n]), + nil. + +inspect(true) -> + "True"; +inspect(false) -> + "False"; +inspect(nil) -> + "Nil"; +inspect(Data) when is_map(Data) -> + Fields = [ + [<<"#(">>, inspect(Key), <<", ">>, inspect(Value), <<")">>] + || {Key, Value} <- maps:to_list(Data) + ], + ["dict.from_list([", lists:join(", ", Fields), "])"]; +inspect(Atom) when is_atom(Atom) -> + Binary = erlang:atom_to_binary(Atom), + case inspect_maybe_gleam_atom(Binary, none, <<>>) of + {ok, Inspected} -> Inspected; + {error, _} -> ["atom.create_from_string(\"", Binary, "\")"] + end; +inspect(Any) when is_integer(Any) -> + erlang:integer_to_list(Any); +inspect(Any) when is_float(Any) -> + io_lib_format:fwrite_g(Any); +inspect(Binary) when is_binary(Binary) -> + case inspect_maybe_utf8_string(Binary, <<>>) of + {ok, InspectedUtf8String} -> InspectedUtf8String; + {error, not_a_utf8_string} -> + Segments = [erlang:integer_to_list(X) || <<X>> <= Binary], + ["<<", lists:join(", ", Segments), ">>"] + end; +inspect(Bits) when is_bitstring(Bits) -> + inspect_bit_array(Bits); +inspect(List) when is_list(List) -> + case inspect_list(List) of + {proper, Elements} -> ["[", Elements, "]"]; + {improper, Elements} -> ["//erl([", Elements, "])"] + end; +inspect(Any) when is_tuple(Any) % Record constructors + andalso is_atom(element(1, Any)) + andalso element(1, Any) =/= false + andalso element(1, Any) =/= true + andalso element(1, Any) =/= nil +-> + [Atom | ArgsList] = erlang:tuple_to_list(Any), + Args = lists:join(<<", ">>, + lists:map(fun inspect/1, ArgsList) + ), + [inspect(Atom), "(", Args, ")"]; +inspect(Tuple) when is_tuple(Tuple) -> + Elements = lists:map(fun inspect/1, erlang:tuple_to_list(Tuple)), + ["#(", lists:join(", ", Elements), ")"]; +inspect(Any) when is_function(Any) -> + {arity, Arity} = erlang:fun_info(Any, arity), + ArgsAsciiCodes = lists:seq($a, $a + Arity - 1), + Args = lists:join(<<", ">>, + lists:map(fun(Arg) -> <<Arg>> end, ArgsAsciiCodes) + ), + ["//fn(", Args, ") { ... }"]; +inspect(Any) -> + ["//erl(", io_lib:format("~p", [Any]), ")"]. + + +inspect_maybe_gleam_atom(<<>>, none, _) -> + {error, nil}; +inspect_maybe_gleam_atom(<<First, _Rest/binary>>, none, _) when ?is_digit_char(First) -> + {error, nil}; +inspect_maybe_gleam_atom(<<"_", _Rest/binary>>, none, _) -> + {error, nil}; +inspect_maybe_gleam_atom(<<"_">>, _PrevChar, _Acc) -> + {error, nil}; +inspect_maybe_gleam_atom(<<"_", _Rest/binary>>, $_, _Acc) -> + {error, nil}; +inspect_maybe_gleam_atom(<<First, _Rest/binary>>, _PrevChar, _Acc) + when not (?is_lowercase_char(First) orelse ?is_underscore_char(First) orelse ?is_digit_char(First)) -> + {error, nil}; +inspect_maybe_gleam_atom(<<First, Rest/binary>>, none, Acc) -> + inspect_maybe_gleam_atom(Rest, First, <<Acc/binary, (uppercase(First))>>); +inspect_maybe_gleam_atom(<<"_", Rest/binary>>, _PrevChar, Acc) -> + inspect_maybe_gleam_atom(Rest, $_, Acc); +inspect_maybe_gleam_atom(<<First, Rest/binary>>, $_, Acc) -> + inspect_maybe_gleam_atom(Rest, First, <<Acc/binary, (uppercase(First))>>); +inspect_maybe_gleam_atom(<<First, Rest/binary>>, _PrevChar, Acc) -> + inspect_maybe_gleam_atom(Rest, First, <<Acc/binary, First>>); +inspect_maybe_gleam_atom(<<>>, _PrevChar, Acc) -> + {ok, Acc}; +inspect_maybe_gleam_atom(A, B, C) -> + erlang:display({A, B, C}), + throw({gleam_error, A, B, C}). + +inspect_list([]) -> + {proper, []}; +inspect_list([First]) -> + {proper, [inspect(First)]}; +inspect_list([First | Rest]) when is_list(Rest) -> + {Kind, Inspected} = inspect_list(Rest), + {Kind, [inspect(First), <<", ">> | Inspected]}; +inspect_list([First | ImproperTail]) -> + {improper, [inspect(First), <<" | ">>, inspect(ImproperTail)]}. + +inspect_bit_array(Bits) -> + Text = inspect_bit_array(Bits, <<"<<">>), + <<Text/binary, ">>">>. + +inspect_bit_array(<<>>, Acc) -> + Acc; +inspect_bit_array(<<X, Rest/bitstring>>, Acc) -> + inspect_bit_array(Rest, append_segment(Acc, erlang:integer_to_binary(X))); +inspect_bit_array(Rest, Acc) -> + Size = bit_size(Rest), + <<X:Size>> = Rest, + X1 = erlang:integer_to_binary(X), + Size1 = erlang:integer_to_binary(Size), + Segment = <<X1/binary, ":size(", Size1/binary, ")">>, + inspect_bit_array(<<>>, append_segment(Acc, Segment)). + +append_segment(<<"<<">>, Segment) -> + <<"<<", Segment/binary>>; +append_segment(Acc, Segment) -> + <<Acc/binary, ", ", Segment/binary>>. + + +inspect_maybe_utf8_string(Binary, Acc) -> + case Binary of + <<>> -> {ok, <<$", Acc/binary, $">>}; + <<First/utf8, Rest/binary>> -> + Escaped = case First of + $" -> <<$\\, $">>; + $\\ -> <<$\\, $\\>>; + $\r -> <<$\\, $r>>; + $\n -> <<$\\, $n>>; + $\t -> <<$\\, $t>>; + Other -> <<Other/utf8>> + end, + inspect_maybe_utf8_string(Rest, <<Acc/binary, Escaped/binary>>); + _ -> {error, not_a_utf8_string} + end. + +float_to_string(Float) when is_float(Float) -> + erlang:iolist_to_binary(io_lib_format:fwrite_g(Float)). + +utf_codepoint_list_to_string(List) -> + case unicode:characters_to_binary(List) of + {error, _} -> erlang:error({gleam_error, {string_invalid_utf8, List}}); + Binary -> Binary + end. + +crop_string(String, Prefix) -> + case string:find(String, Prefix) of + nomatch -> String; + New -> New + end. + +contains_string(String, Substring) -> + is_bitstring(string:find(String, Substring)). + +base16_decode(String) -> + try + {ok, binary:decode_hex(String)} + catch + _:_ -> {error, nil} + end. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.mjs b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.mjs new file mode 100644 index 0000000..a908b23 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/_gleam_artefacts/gleam_stdlib.mjs @@ -0,0 +1,875 @@ +import { + BitArray, + Error, + List, + Ok, + Result, + UtfCodepoint, + stringBits, + toBitArray, + NonEmpty, + CustomType, +} from "./gleam.mjs"; +import { + CompileError as RegexCompileError, + Match as RegexMatch, +} from "./gleam/regex.mjs"; +import { DecodeError } from "./gleam/dynamic.mjs"; +import { Some, None } from "./gleam/option.mjs"; +import Dict from "./dict.mjs"; + +const Nil = undefined; +const NOT_FOUND = {}; + +export function identity(x) { + return x; +} + +export function parse_int(value) { + if (/^[-+]?(\d+)$/.test(value)) { + return new Ok(parseInt(value)); + } else { + return new Error(Nil); + } +} + +export function parse_float(value) { + if (/^[-+]?(\d+)\.(\d+)$/.test(value)) { + return new Ok(parseFloat(value)); + } else { + return new Error(Nil); + } +} + +export function to_string(term) { + return term.toString(); +} + +export function float_to_string(float) { + const string = float.toString(); + if (string.indexOf(".") >= 0) { + return string; + } else { + return string + ".0"; + } +} + +export function int_to_base_string(int, base) { + return int.toString(base).toUpperCase(); +} + +const int_base_patterns = { + 2: /[^0-1]/, + 3: /[^0-2]/, + 4: /[^0-3]/, + 5: /[^0-4]/, + 6: /[^0-5]/, + 7: /[^0-6]/, + 8: /[^0-7]/, + 9: /[^0-8]/, + 10: /[^0-9]/, + 11: /[^0-9a]/, + 12: /[^0-9a-b]/, + 13: /[^0-9a-c]/, + 14: /[^0-9a-d]/, + 15: /[^0-9a-e]/, + 16: /[^0-9a-f]/, + 17: /[^0-9a-g]/, + 18: /[^0-9a-h]/, + 19: /[^0-9a-i]/, + 20: /[^0-9a-j]/, + 21: /[^0-9a-k]/, + 22: /[^0-9a-l]/, + 23: /[^0-9a-m]/, + 24: /[^0-9a-n]/, + 25: /[^0-9a-o]/, + 26: /[^0-9a-p]/, + 27: /[^0-9a-q]/, + 28: /[^0-9a-r]/, + 29: /[^0-9a-s]/, + 30: /[^0-9a-t]/, + 31: /[^0-9a-u]/, + 32: /[^0-9a-v]/, + 33: /[^0-9a-w]/, + 34: /[^0-9a-x]/, + 35: /[^0-9a-y]/, + 36: /[^0-9a-z]/, +}; + +export function int_from_base_string(string, base) { + if (int_base_patterns[base].test(string.replace(/^-/, "").toLowerCase())) { + return new Error(Nil); + } + + const result = parseInt(string, base); + + if (isNaN(result)) { + return new Error(Nil); + } + + return new Ok(result); +} + +export function string_replace(string, target, substitute) { + if (typeof string.replaceAll !== "undefined") { + return string.replaceAll(target, substitute); + } + // Fallback for older Node.js versions: + // 1. <https://stackoverflow.com/a/1144788> + // 2. <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping> + // TODO: This fallback could be remove once Node.js 14 is EOL + // aka <https://nodejs.org/en/about/releases/> on or after 2024-04-30 + return string.replace( + // $& means the whole matched string + new RegExp(target.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), + substitute + ); +} + +export function string_reverse(string) { + return [...string].reverse().join(""); +} + +export function string_length(string) { + if (string === "") { + return 0; + } + const iterator = graphemes_iterator(string); + if (iterator) { + let i = 0; + for (const _ of iterator) { + i++; + } + return i; + } else { + return string.match(/./gsu).length; + } +} + +export function graphemes(string) { + return List.fromArray( + Array.from(graphemes_iterator(string)).map((item) => item.segment) + ); +} + +function graphemes_iterator(string) { + if (Intl && Intl.Segmenter) { + return new Intl.Segmenter().segment(string)[Symbol.iterator](); + } +} + +export function pop_grapheme(string) { + let first; + const iterator = graphemes_iterator(string); + if (iterator) { + first = iterator.next().value?.segment; + } else { + first = string.match(/./su)?.[0]; + } + if (first) { + return new Ok([first, string.slice(first.length)]); + } else { + return new Error(Nil); + } +} + +export function lowercase(string) { + return string.toLowerCase(); +} + +export function uppercase(string) { + return string.toUpperCase(); +} + +export function less_than(a, b) { + return a < b; +} + +export function add(a, b) { + return a + b; +} + +export function equal(a, b) { + return a === b; +} + +export function split(xs, pattern) { + return List.fromArray(xs.split(pattern)); +} + +export function join(xs, separator) { + const iterator = xs[Symbol.iterator](); + let result = iterator.next().value || ""; + let current = iterator.next(); + while (!current.done) { + result = result + separator + current.value; + current = iterator.next(); + } + return result; +} + +export function concat(xs) { + let result = ""; + for (const x of xs) { + result = result + x; + } + return result; +} + +export function length(data) { + return data.length; +} + +export function crop_string(string, substring) { + return string.substring(string.indexOf(substring)); +} + +export function contains_string(haystack, needle) { + return haystack.indexOf(needle) >= 0; +} + +export function starts_with(haystack, needle) { + return haystack.startsWith(needle); +} + +export function ends_with(haystack, needle) { + return haystack.endsWith(needle); +} + +export function split_once(haystack, needle) { + const index = haystack.indexOf(needle); + if (index >= 0) { + const before = haystack.slice(0, index); + const after = haystack.slice(index + needle.length); + return new Ok([before, after]); + } else { + return new Error(Nil); + } +} + +export function trim(string) { + return string.trim(); +} + +export function trim_left(string) { + return string.trimLeft(); +} + +export function trim_right(string) { + return string.trimRight(); +} + +export function bit_array_from_string(string) { + return toBitArray([stringBits(string)]); +} + +export function bit_array_concat(bit_arrays) { + return toBitArray(bit_arrays.toArray().map((b) => b.buffer)); +} + +export function console_log(term) { + console.log(term); +} + +export function console_error(term) { + console.error(term); +} + +export function crash(message) { + throw new globalThis.Error(message); +} + +export function bit_array_to_string(bit_array) { + try { + const decoder = new TextDecoder("utf-8", { fatal: true }); + return new Ok(decoder.decode(bit_array.buffer)); + } catch (_error) { + return new Error(Nil); + } +} + +export function print(string) { + if (typeof process === "object") { + process.stdout.write(string); // We can write without a trailing newline + } else if (typeof Deno === "object") { + Deno.stdout.writeSync(new TextEncoder().encode(string)); // We can write without a trailing newline + } else { + console.log(string); // We're in a browser. Newlines are mandated + } +} + +export function print_error(string) { + if (typeof process === "object" && process.stderr?.write) { + process.stderr.write(string); // We can write without a trailing newline + } else if (typeof Deno === "object") { + Deno.stderr.writeSync(new TextEncoder().encode(string)); // We can write without a trailing newline + } else { + console.error(string); // We're in a browser. Newlines are mandated + } +} + +export function print_debug(string) { + if (typeof process === "object" && process.stderr?.write) { + process.stderr.write(string + "\n"); // If we're in Node.js, use `stderr` + } else if (typeof Deno === "object") { + Deno.stderr.writeSync(new TextEncoder().encode(string + "\n")); // If we're in Deno, use `stderr` + } else { + console.log(string); // Otherwise, use `console.log` (so that it doesn't look like an error) + } +} + +export function ceiling(float) { + return Math.ceil(float); +} + +export function floor(float) { + return Math.floor(float); +} + +export function round(float) { + return Math.round(float); +} + +export function truncate(float) { + return Math.trunc(float); +} + +export function power(base, exponent) { + // It is checked in Gleam that: + // - The base is non-negative and that the exponent is not fractional. + // - The base is non-zero and the exponent is non-negative (otherwise + // the result will essentially be division by zero). + // It can thus be assumed that valid input is passed to the Math.pow + // function and a NaN or Infinity value will not be produced. + return Math.pow(base, exponent); +} + +export function random_uniform() { + const random_uniform_result = Math.random(); + // With round-to-nearest-even behavior, the ranges claimed for the functions below + // (excluding the one for Math.random() itself) aren't exact. + // If extremely large bounds are chosen (2^53 or higher), + // it's possible in extremely rare cases to calculate the usually-excluded upper bound. + // Note that as numbers in JavaScript are IEEE 754 floating point numbers + // See: <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random> + // Because of this, we just loop 'until' we get a valid result where 0.0 <= x < 1.0: + if (random_uniform_result === 1.0) { + return random_uniform(); + } + return random_uniform_result; +} + +export function bit_array_slice(bits, position, length) { + const start = Math.min(position, position + length); + const end = Math.max(position, position + length); + if (start < 0 || end > bits.length) return new Error(Nil); + const buffer = new Uint8Array(bits.buffer.buffer, start, Math.abs(length)); + return new Ok(new BitArray(buffer)); +} + +export function codepoint(int) { + return new UtfCodepoint(int); +} + +export function string_to_codepoint_integer_list(string) { + return List.fromArray(Array.from(string).map((item) => item.codePointAt(0))); +} + +export function utf_codepoint_list_to_string(utf_codepoint_integer_list) { + return utf_codepoint_integer_list + .toArray() + .map((x) => String.fromCodePoint(x.value)) + .join(""); +} + +export function utf_codepoint_to_int(utf_codepoint) { + return utf_codepoint.value; +} + +export function regex_check(regex, string) { + regex.lastIndex = 0; + return regex.test(string); +} + +export function compile_regex(pattern, options) { + try { + let flags = "gu"; + if (options.case_insensitive) flags += "i"; + if (options.multi_line) flags += "m"; + return new Ok(new RegExp(pattern, flags)); + } catch (error) { + const number = (error.columnNumber || 0) | 0; + return new Error(new RegexCompileError(error.message, number)); + } +} + +export function regex_scan(regex, string) { + const matches = Array.from(string.matchAll(regex)).map((match) => { + const content = match[0]; + const submatches = []; + for (let n = match.length - 1; n > 0; n--) { + if (match[n]) { + submatches[n - 1] = new Some(match[n]); + continue; + } + if (submatches.length > 0) { + submatches[n - 1] = new None(); + } + } + return new RegexMatch(content, List.fromArray(submatches)); + }); + return List.fromArray(matches); +} + +export function new_map() { + return Dict.new(); +} + +export function map_size(map) { + return map.size; +} + +export function map_to_list(map) { + return List.fromArray(map.entries()); +} + +export function map_remove(key, map) { + return map.delete(key); +} + +export function map_get(map, key) { + const value = map.get(key, NOT_FOUND); + if (value === NOT_FOUND) { + return new Error(Nil); + } + return new Ok(value); +} + +export function map_insert(key, value, map) { + return map.set(key, value); +} + +function unsafe_percent_decode(string) { + return decodeURIComponent((string || "").replace("+", " ")); +} + +export function percent_decode(string) { + try { + return new Ok(unsafe_percent_decode(string)); + } catch (_error) { + return new Error(Nil); + } +} + +export function percent_encode(string) { + return encodeURIComponent(string); +} + +export function parse_query(query) { + try { + const pairs = []; + for (const section of query.split("&")) { + const [key, value] = section.split("="); + if (!key) continue; + pairs.push([unsafe_percent_decode(key), unsafe_percent_decode(value)]); + } + return new Ok(List.fromArray(pairs)); + } catch (_error) { + return new Error(Nil); + } +} + +// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8 +export function encode64(bit_array) { + const aBytes = bit_array.buffer; + let nMod3 = 2; + let sB64Enc = ""; + + for (let nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) { + nMod3 = nIdx % 3; + if (nIdx > 0 && ((nIdx * 4) / 3) % 76 === 0) { + sB64Enc += "\r\n"; + } + nUint24 |= aBytes[nIdx] << ((16 >>> nMod3) & 24); + if (nMod3 === 2 || aBytes.length - nIdx === 1) { + sB64Enc += String.fromCharCode( + uint6ToB64((nUint24 >>> 18) & 63), + uint6ToB64((nUint24 >>> 12) & 63), + uint6ToB64((nUint24 >>> 6) & 63), + uint6ToB64(nUint24 & 63) + ); + nUint24 = 0; + } + } + + return ( + sB64Enc.substr(0, sB64Enc.length - 2 + nMod3) + + (nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==") + ); +} + +// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8 +function uint6ToB64(nUint6) { + return nUint6 < 26 + ? nUint6 + 65 + : nUint6 < 52 + ? nUint6 + 71 + : nUint6 < 62 + ? nUint6 - 4 + : nUint6 === 62 + ? 43 + : nUint6 === 63 + ? 47 + : 65; +} + +// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8 +function b64ToUint6(nChr) { + return nChr > 64 && nChr < 91 + ? nChr - 65 + : nChr > 96 && nChr < 123 + ? nChr - 71 + : nChr > 47 && nChr < 58 + ? nChr + 4 + : nChr === 43 + ? 62 + : nChr === 47 + ? 63 + : 0; +} + +// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8 +export function decode64(sBase64) { + if (sBase64.match(/[^A-Za-z0-9\+\/=]/g)) return new Error(Nil); + const sB64Enc = sBase64.replace(/=/g, ""); + const nInLen = sB64Enc.length; + const nOutLen = (nInLen * 3 + 1) >> 2; + const taBytes = new Uint8Array(nOutLen); + + for ( + let nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; + nInIdx < nInLen; + nInIdx++ + ) { + nMod4 = nInIdx & 3; + nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (6 * (3 - nMod4)); + if (nMod4 === 3 || nInLen - nInIdx === 1) { + for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) { + taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255; + } + nUint24 = 0; + } + } + + return new Ok(new BitArray(taBytes)); +} + +export function classify_dynamic(data) { + if (typeof data === "string") { + return "String"; + } else if (data instanceof Result) { + return "Result"; + } else if (data instanceof List) { + return "List"; + } else if (data instanceof BitArray) { + return "BitArray"; + } else if (data instanceof Dict) { + return "Map"; + } else if (Number.isInteger(data)) { + return "Int"; + } else if (Array.isArray(data)) { + return `Tuple of ${data.length} elements`; + } else if (typeof data === "number") { + return "Float"; + } else if (data === null) { + return "Null"; + } else if (data === undefined) { + return "Nil"; + } else { + const type = typeof data; + return type.charAt(0).toUpperCase() + type.slice(1); + } +} + +function decoder_error(expected, got) { + return decoder_error_no_classify(expected, classify_dynamic(got)); +} + +function decoder_error_no_classify(expected, got) { + return new Error( + List.fromArray([new DecodeError(expected, got, List.fromArray([]))]) + ); +} + +export function decode_string(data) { + return typeof data === "string" + ? new Ok(data) + : decoder_error("String", data); +} + +export function decode_int(data) { + return Number.isInteger(data) ? new Ok(data) : decoder_error("Int", data); +} + +export function decode_float(data) { + return typeof data === "number" ? new Ok(data) : decoder_error("Float", data); +} + +export function decode_bool(data) { + return typeof data === "boolean" ? new Ok(data) : decoder_error("Bool", data); +} + +export function decode_bit_array(data) { + if (data instanceof BitArray) { + return new Ok(data); + } + if (data instanceof Uint8Array) { + return new Ok(new BitArray(data)); + } + return decoder_error("BitArray", data); +} + +export function decode_tuple(data) { + return Array.isArray(data) ? new Ok(data) : decoder_error("Tuple", data); +} + +export function decode_tuple2(data) { + return decode_tupleN(data, 2); +} + +export function decode_tuple3(data) { + return decode_tupleN(data, 3); +} + +export function decode_tuple4(data) { + return decode_tupleN(data, 4); +} + +export function decode_tuple5(data) { + return decode_tupleN(data, 5); +} + +export function decode_tuple6(data) { + return decode_tupleN(data, 6); +} + +function decode_tupleN(data, n) { + if (Array.isArray(data) && data.length == n) { + return new Ok(data); + } + + const list = decode_exact_length_list(data, n); + if (list) return new Ok(list); + + return decoder_error(`Tuple of ${n} elements`, data); +} + +function decode_exact_length_list(data, n) { + if (!(data instanceof List)) return; + + const elements = []; + let current = data; + + for (let i = 0; i < n; i++) { + if (!(current instanceof NonEmpty)) break; + elements.push(current.head); + current = current.tail; + } + + if (elements.length === n && !(current instanceof NonEmpty)) return elements; +} + +export function tuple_get(data, index) { + return index >= 0 && data.length > index + ? new Ok(data[index]) + : new Error(Nil); +} + +export function decode_list(data) { + if (Array.isArray(data)) { + return new Ok(List.fromArray(data)); + } + return data instanceof List ? new Ok(data) : decoder_error("List", data); +} + +export function decode_result(data) { + return data instanceof Result ? new Ok(data) : decoder_error("Result", data); +} + +export function decode_map(data) { + if (data instanceof Dict) { + return new Ok(Dict.fromMap(data)); + } + if (data == null) { + return decoder_error("Map", data); + } + if (typeof data !== "object") { + return decoder_error("Map", data); + } + const proto = Object.getPrototypeOf(data); + if (proto === Object.prototype || proto === null) { + return new Ok(Dict.fromObject(data)); + } + return decoder_error("Map", data); +} + +export function decode_option(data, decoder) { + if (data === null || data === undefined || data instanceof None) + return new Ok(new None()); + if (data instanceof Some) data = data[0]; + const result = decoder(data); + if (result.isOk()) { + return new Ok(new Some(result[0])); + } else { + return result; + } +} + +export function decode_field(value, name) { + const not_a_map_error = () => decoder_error("Map", value); + + if ( + value instanceof Dict || + value instanceof WeakMap || + value instanceof Map + ) { + const entry = map_get(value, name); + return new Ok(entry.isOk() ? new Some(entry[0]) : new None()); + } else if (Object.getPrototypeOf(value) == Object.prototype) { + return try_get_field(value, name, () => new Ok(new None())); + } else { + return try_get_field(value, name, not_a_map_error); + } +} + +function try_get_field(value, field, or_else) { + try { + return field in value ? new Ok(new Some(value[field])) : or_else(); + } catch { + return or_else(); + } +} + +export function byte_size(string) { + return new TextEncoder().encode(string).length; +} + +// In Javascript bitwise operations convert numbers to a sequence of 32 bits +// while Erlang uses arbitrary precision. +// To get around this problem and get consistent results use BigInt and then +// downcast the value back to a Number value. + +export function bitwise_and(x, y) { + return Number(BigInt(x) & BigInt(y)); +} + +export function bitwise_not(x) { + return Number(~BigInt(x)); +} + +export function bitwise_or(x, y) { + return Number(BigInt(x) | BigInt(y)); +} + +export function bitwise_exclusive_or(x, y) { + return Number(BigInt(x) ^ BigInt(y)); +} + +export function bitwise_shift_left(x, y) { + return Number(BigInt(x) << BigInt(y)); +} + +export function bitwise_shift_right(x, y) { + return Number(BigInt(x) >> BigInt(y)); +} + +export function inspect(v) { + const t = typeof v; + if (v === true) return "True"; + if (v === false) return "False"; + if (v === null) return "//js(null)"; + if (v === undefined) return "Nil"; + if (t === "string") return JSON.stringify(v); + if (t === "bigint" || t === "number") return v.toString(); + if (Array.isArray(v)) return `#(${v.map(inspect).join(", ")})`; + if (v instanceof List) return inspectList(v); + if (v instanceof UtfCodepoint) return inspectUtfCodepoint(v); + if (v instanceof BitArray) return inspectBitArray(v); + if (v instanceof CustomType) return inspectCustomType(v); + if (v instanceof Dict) return inspectDict(v); + if (v instanceof Set) return `//js(Set(${[...v].map(inspect).join(", ")}))`; + if (v instanceof RegExp) return `//js(${v})`; + if (v instanceof Date) return `//js(Date("${v.toISOString()}"))`; + if (v instanceof Function) { + const args = []; + for (const i of Array(v.length).keys()) + args.push(String.fromCharCode(i + 97)); + return `//fn(${args.join(", ")}) { ... }`; + } + return inspectObject(v); +} + +function inspectDict(map) { + let body = "dict.from_list(["; + let first = true; + map.forEach((value, key) => { + if (!first) body = body + ", "; + body = body + "#(" + inspect(key) + ", " + inspect(value) + ")"; + first = false; + }); + return body + "])"; +} + +function inspectObject(v) { + const name = Object.getPrototypeOf(v)?.constructor?.name || "Object"; + const props = []; + for (const k of Object.keys(v)) { + props.push(`${inspect(k)}: ${inspect(v[k])}`); + } + const body = props.length ? " " + props.join(", ") + " " : ""; + const head = name === "Object" ? "" : name + " "; + return `//js(${head}{${body}})`; +} + +function inspectCustomType(record) { + const props = Object.keys(record) + .map((label) => { + const value = inspect(record[label]); + return isNaN(parseInt(label)) ? `${label}: ${value}` : value; + }) + .join(", "); + return props + ? `${record.constructor.name}(${props})` + : record.constructor.name; +} + +export function inspectList(list) { + return `[${list.toArray().map(inspect).join(", ")}]`; +} + +export function inspectBitArray(bits) { + return `<<${Array.from(bits.buffer).join(", ")}>>`; +} + +export function inspectUtfCodepoint(codepoint) { + return `//utfcodepoint(${String.fromCodePoint(codepoint.value)})`; +} + +export function base16_encode(bit_array) { + let result = ""; + for (const byte of bit_array.buffer) { + result += byte.toString(16).padStart(2, "0").toUpperCase(); + } + return result; +} + +export function base16_decode(string) { + const bytes = new Uint8Array(string.length / 2); + for (let i = 0; i < string.length; i += 2) { + const a = parseInt(string[i], 16); + const b = parseInt(string[i + 1], 16); + if (isNaN(a) || isNaN(b)) return new Error(Nil); + bytes[i / 2] = a * 16 + b; + } + return new Ok(new BitArray(bytes)); +} diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@base.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@base.beam Binary files differnew file mode 100644 index 0000000..1dc5df2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@base.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_array.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_array.beam Binary files differnew file mode 100644 index 0000000..53dc014 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_array.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_builder.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_builder.beam Binary files differnew file mode 100644 index 0000000..bb8b7ad --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_builder.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_string.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_string.beam Binary files differnew file mode 100644 index 0000000..529dcbf --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bit_string.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bool.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bool.beam Binary files differnew file mode 100644 index 0000000..1c09889 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bool.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bytes_builder.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bytes_builder.beam Binary files differnew file mode 100644 index 0000000..5909435 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@bytes_builder.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dict.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dict.beam Binary files differnew file mode 100644 index 0000000..4e29e67 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dict.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dynamic.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dynamic.beam Binary files differnew file mode 100644 index 0000000..04a6ff4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@dynamic.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@float.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@float.beam Binary files differnew file mode 100644 index 0000000..4e514dd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@float.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@function.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@function.beam Binary files differnew file mode 100644 index 0000000..26efa09 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@function.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@int.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@int.beam Binary files differnew file mode 100644 index 0000000..fdbc861 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@int.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@io.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@io.beam Binary files differnew file mode 100644 index 0000000..e26d173 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@io.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@iterator.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@iterator.beam Binary files differnew file mode 100644 index 0000000..27305e5 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@iterator.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@list.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@list.beam Binary files differnew file mode 100644 index 0000000..3bc877f --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@list.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@map.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@map.beam Binary files differnew file mode 100644 index 0000000..da9fae6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@map.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@option.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@option.beam Binary files differnew file mode 100644 index 0000000..fc1c866 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@option.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@order.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@order.beam Binary files differnew file mode 100644 index 0000000..d2211bd --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@order.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@pair.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@pair.beam Binary files differnew file mode 100644 index 0000000..c54cf50 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@pair.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@queue.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@queue.beam Binary files differnew file mode 100644 index 0000000..f9bb77e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@queue.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@regex.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@regex.beam Binary files differnew file mode 100644 index 0000000..9f9f430 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@regex.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@result.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@result.beam Binary files differnew file mode 100644 index 0000000..fffb063 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@result.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@set.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@set.beam Binary files differnew file mode 100644 index 0000000..3f4118e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@set.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string.beam Binary files differnew file mode 100644 index 0000000..9febebb --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string_builder.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string_builder.beam Binary files differnew file mode 100644 index 0000000..4dee8d6 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@string_builder.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@uri.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@uri.beam Binary files differnew file mode 100644 index 0000000..91e2a9c --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam@uri.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.app b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.app new file mode 100644 index 0000000..8231979 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.app @@ -0,0 +1,7 @@ +{application, gleam_stdlib, [ + {vsn, "0.33.0"}, + {applications, []}, + {description, "A standard library for the Gleam programming language"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.beam b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.beam Binary files differnew file mode 100644 index 0000000..7022f4d --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/ebin/gleam_stdlib.beam diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@dynamic_DecodeError.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@dynamic_DecodeError.hrl new file mode 100644 index 0000000..b1135f2 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@dynamic_DecodeError.hrl @@ -0,0 +1,5 @@ +-record(decode_error, { + expected :: binary(), + found :: binary(), + path :: list(binary()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Iterator.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Iterator.hrl new file mode 100644 index 0000000..b0d08dc --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Iterator.hrl @@ -0,0 +1 @@ +-record(iterator, {continuation :: fun(() -> gleam@iterator:action(any()))}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Next.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Next.hrl new file mode 100644 index 0000000..1f61922 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@iterator_Next.hrl @@ -0,0 +1 @@ +-record(next, {element :: any(), accumulator :: any()}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@queue_Queue.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@queue_Queue.hrl new file mode 100644 index 0000000..88ac25e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@queue_Queue.hrl @@ -0,0 +1 @@ +-record(queue, {in :: list(any()), out :: list(any())}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_CompileError.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_CompileError.hrl new file mode 100644 index 0000000..ad5511e --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_CompileError.hrl @@ -0,0 +1 @@ +-record(compile_error, {error :: binary(), byte_index :: integer()}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Match.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Match.hrl new file mode 100644 index 0000000..4216619 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Match.hrl @@ -0,0 +1,4 @@ +-record(match, { + content :: binary(), + submatches :: list(gleam@option:option(binary())) +}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Options.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Options.hrl new file mode 100644 index 0000000..0074603 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@regex_Options.hrl @@ -0,0 +1 @@ +-record(options, {case_insensitive :: boolean(), multi_line :: boolean()}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@set_Set.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@set_Set.hrl new file mode 100644 index 0000000..6e1e226 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@set_Set.hrl @@ -0,0 +1 @@ +-record(set, {map :: gleam@dict:dict(any(), list(nil))}). diff --git a/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@uri_Uri.hrl b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@uri_Uri.hrl new file mode 100644 index 0000000..50150f4 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_stdlib/include/gleam@uri_Uri.hrl @@ -0,0 +1,9 @@ +-record(uri, { + scheme :: gleam@option:option(binary()), + userinfo :: gleam@option:option(binary()), + host :: gleam@option:option(binary()), + port :: gleam@option:option(integer()), + path :: binary(), + 'query' :: gleam@option:option(binary()), + fragment :: gleam@option:option(binary()) +}). diff --git a/aoc2023/build/dev/erlang/gleam_version b/aoc2023/build/dev/erlang/gleam_version new file mode 100644 index 0000000..e13b3d9 --- /dev/null +++ b/aoc2023/build/dev/erlang/gleam_version @@ -0,0 +1 @@ +0.34.0-rc1
\ No newline at end of file diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache Binary files differnew file mode 100644 index 0000000..2174df9 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache_meta b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache_meta Binary files differnew file mode 100644 index 0000000..23d66d7 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.cache_meta diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.erl b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.erl new file mode 100644 index 0000000..76f7f3b --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint.erl @@ -0,0 +1,513 @@ +-module(glint). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([with_config/2, with_pretty_help/2, without_pretty_help/1, with_name/2, command/1, description/2, flag/3, flag_tuple/2, flags/2, global_flag/3, global_flag_tuple/2, global_flags/2, default_pretty_help/0, add/3, add_command_from_stub/2, new/0, help_flag/0, execute/2, run_and_handle/3, run/2]). +-export_type([config/0, pretty_help/0, glint/1, command/1, command_input/0, command_node/1, out/1, stub/1]). + +-type config() :: {config, + gleam@option:option(pretty_help()), + gleam@option:option(binary())}. + +-type pretty_help() :: {pretty_help, + gleam_community@colour:colour(), + gleam_community@colour:colour(), + gleam_community@colour:colour()}. + +-opaque glint(KWB) :: {glint, + config(), + command_node(KWB), + gleam@dict:dict(binary(), glint@flag:flag())}. + +-opaque command(KWC) :: {command, + fun((command_input()) -> KWC), + gleam@dict:dict(binary(), glint@flag:flag()), + binary()}. + +-type command_input() :: {command_input, + list(binary()), + gleam@dict:dict(binary(), glint@flag:flag())}. + +-type command_node(KWD) :: {command_node, + gleam@option:option(command(KWD)), + gleam@dict:dict(binary(), command_node(KWD))}. + +-type out(KWE) :: {out, KWE} | {help, binary()}. + +-type stub(KWF) :: {stub, + list(binary()), + fun((command_input()) -> KWF), + list({binary(), glint@flag:flag()}), + binary()}. + +-spec with_config(glint(KWK), config()) -> glint(KWK). +with_config(Glint, Config) -> + erlang:setelement(2, Glint, Config). + +-spec with_pretty_help(glint(KWN), pretty_help()) -> glint(KWN). +with_pretty_help(Glint, Pretty) -> + _pipe = erlang:setelement(2, erlang:element(2, Glint), {some, Pretty}), + with_config(Glint, _pipe). + +-spec without_pretty_help(glint(KWQ)) -> glint(KWQ). +without_pretty_help(Glint) -> + _pipe = erlang:setelement(2, erlang:element(2, Glint), none), + with_config(Glint, _pipe). + +-spec with_name(glint(KWT), binary()) -> glint(KWT). +with_name(Glint, Name) -> + _pipe = erlang:setelement(3, erlang:element(2, Glint), {some, Name}), + with_config(Glint, _pipe). + +-spec empty_command() -> command_node(any()). +empty_command() -> + {command_node, none, gleam@map:new()}. + +-spec do_add(command_node(KXD), list(binary()), command(KXD)) -> command_node(KXD). +do_add(Root, Path, Contents) -> + case Path of + [] -> + erlang:setelement(2, Root, {some, Contents}); + + [X | Xs] -> + erlang:setelement( + 3, + Root, + (gleam@map:update( + erlang:element(3, Root), + X, + fun(Node) -> _pipe = Node, + _pipe@1 = gleam@option:lazy_unwrap( + _pipe, + fun empty_command/0 + ), + do_add(_pipe@1, Xs, Contents) end + )) + ) + end. + +-spec command(fun((command_input()) -> KXM)) -> command(KXM). +command(Runner) -> + {command, Runner, gleam@map:new(), <<""/utf8>>}. + +-spec description(command(KXP), binary()) -> command(KXP). +description(Cmd, Description) -> + erlang:setelement(4, Cmd, Description). + +-spec flag(command(KXS), binary(), glint@flag:flag_builder(any())) -> command(KXS). +flag(Cmd, Key, Flag) -> + erlang:setelement( + 3, + Cmd, + gleam@map:insert(erlang:element(3, Cmd), Key, glint@flag:build(Flag)) + ). + +-spec flag_tuple(command(KXX), {binary(), glint@flag:flag_builder(any())}) -> command(KXX). +flag_tuple(Cmd, Tup) -> + flag(Cmd, erlang:element(1, Tup), erlang:element(2, Tup)). + +-spec flags(command(KYC), list({binary(), glint@flag:flag()})) -> command(KYC). +flags(Cmd, Flags) -> + gleam@list:fold( + Flags, + Cmd, + fun(Cmd@1, _use1) -> + {Key, Flag} = _use1, + erlang:setelement( + 3, + Cmd@1, + gleam@map:insert(erlang:element(3, Cmd@1), Key, Flag) + ) + end + ). + +-spec global_flag(glint(KYG), binary(), glint@flag:flag_builder(any())) -> glint(KYG). +global_flag(Glint, Key, Flag) -> + erlang:setelement( + 4, + Glint, + gleam@map:insert(erlang:element(4, Glint), Key, glint@flag:build(Flag)) + ). + +-spec global_flag_tuple(glint(KYL), {binary(), glint@flag:flag_builder(any())}) -> glint(KYL). +global_flag_tuple(Glint, Tup) -> + global_flag(Glint, erlang:element(1, Tup), erlang:element(2, Tup)). + +-spec global_flags(glint(KYQ), list({binary(), glint@flag:flag()})) -> glint(KYQ). +global_flags(Glint, Flags) -> + erlang:setelement( + 4, + Glint, + (gleam@list:fold( + Flags, + erlang:element(4, Glint), + fun(Acc, Tup) -> + gleam@map:insert( + Acc, + erlang:element(1, Tup), + erlang:element(2, Tup) + ) + end + )) + ). + +-spec execute_root( + command_node(KZE), + gleam@dict:dict(binary(), glint@flag:flag()), + list(binary()), + list(binary()) +) -> {ok, out(KZE)} | {error, snag:snag()}. +execute_root(Cmd, Global_flags, Args, Flag_inputs) -> + _pipe@3 = case erlang:element(2, Cmd) of + {some, Contents} -> + gleam@result:'try'( + gleam@list:try_fold( + Flag_inputs, + gleam@map:merge(Global_flags, erlang:element(3, Contents)), + fun glint@flag:update_flags/2 + ), + fun(New_flags) -> _pipe = {command_input, Args, New_flags}, + _pipe@1 = (erlang:element(2, Contents))(_pipe), + _pipe@2 = {out, _pipe@1}, + {ok, _pipe@2} end + ); + + none -> + snag:error(<<"command not found"/utf8>>) + end, + snag:context(_pipe@3, <<"failed to run command"/utf8>>). + +-spec default_pretty_help() -> pretty_help(). +default_pretty_help() -> + _assert_subject = gleam_community@colour:from_rgb255(182, 255, 234), + {ok, Usage_colour} = case _assert_subject of + {ok, _} -> _assert_subject; + _assert_fail -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail, + module => <<"glint"/utf8>>, + function => <<"default_pretty_help"/utf8>>, + line => 404}) + end, + _assert_subject@1 = gleam_community@colour:from_rgb255(255, 175, 243), + {ok, Flags_colour} = case _assert_subject@1 of + {ok, _} -> _assert_subject@1; + _assert_fail@1 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@1, + module => <<"glint"/utf8>>, + function => <<"default_pretty_help"/utf8>>, + line => 405}) + end, + _assert_subject@2 = gleam_community@colour:from_rgb255(252, 226, 174), + {ok, Subcommands_colour} = case _assert_subject@2 of + {ok, _} -> _assert_subject@2; + _assert_fail@2 -> + erlang:error(#{gleam_error => let_assert, + message => <<"Assertion pattern match failed"/utf8>>, + value => _assert_fail@2, + module => <<"glint"/utf8>>, + function => <<"default_pretty_help"/utf8>>, + line => 406}) + end, + {pretty_help, Usage_colour, Flags_colour, Subcommands_colour}. + +-spec is_not_empty(binary()) -> boolean(). +is_not_empty(S) -> + S /= <<""/utf8>>. + +-spec sanitize_path(list(binary())) -> list(binary()). +sanitize_path(Path) -> + _pipe = Path, + _pipe@1 = gleam@list:map(_pipe, fun gleam@string:trim/1), + gleam@list:filter(_pipe@1, fun is_not_empty/1). + +-spec add(glint(KWY), list(binary()), command(KWY)) -> glint(KWY). +add(Glint, Path, Contents) -> + erlang:setelement( + 3, + Glint, + begin + _pipe = Path, + _pipe@1 = sanitize_path(_pipe), + do_add(erlang:element(3, Glint), _pipe@1, Contents) + end + ). + +-spec wrap_with_space(binary()) -> binary(). +wrap_with_space(S) -> + case S of + <<""/utf8>> -> + <<" "/utf8>>; + + _ -> + <<<<" "/utf8, S/binary>>/binary, " "/utf8>> + end. + +-spec subcommand_help(binary(), command_node(any())) -> binary(). +subcommand_help(Name, Cmd) -> + case erlang:element(2, Cmd) of + none -> + Name; + + {some, Contents} -> + <<<<Name/binary, "\t\t"/utf8>>/binary, + (erlang:element(4, Contents))/binary>> + end. + +-spec subcommands_help(gleam@dict:dict(binary(), command_node(any()))) -> binary(). +subcommands_help(Cmds) -> + _pipe = Cmds, + _pipe@1 = gleam@map:map_values(_pipe, fun subcommand_help/2), + _pipe@2 = gleam@map:values(_pipe@1), + _pipe@3 = gleam@list:sort(_pipe@2, fun gleam@string:compare/2), + gleam@string:join(_pipe@3, <<"\n\t"/utf8>>). + +-spec heading_style(binary(), gleam_community@colour:colour()) -> binary(). +heading_style(Heading, Colour) -> + _pipe = Heading, + _pipe@1 = gleam_community@ansi:bold(_pipe), + _pipe@2 = gleam_community@ansi:underline(_pipe@1), + _pipe@3 = gleam_community@ansi:italic(_pipe@2), + _pipe@4 = gleam_community@ansi:hex( + _pipe@3, + gleam_community@colour:to_rgb_hex(Colour) + ), + gleam_community@ansi:reset(_pipe@4). + +-spec add_command_from_stub(glint(KZZ), stub(KZZ)) -> glint(KZZ). +add_command_from_stub(Glint, Stub) -> + add( + Glint, + erlang:element(2, Stub), + begin + _pipe = command(erlang:element(3, Stub)), + _pipe@1 = flags(_pipe, erlang:element(4, Stub)), + description(_pipe@1, erlang:element(5, Stub)) + end + ). + +-spec new() -> glint(any()). +new() -> + {glint, {config, none, none}, empty_command(), gleam@map:new()}. + +-spec usage_help( + binary(), + gleam@dict:dict(binary(), glint@flag:flag()), + config() +) -> binary(). +usage_help(Cmd_name, Flags, Config) -> + App_name = gleam@option:unwrap( + erlang:element(3, Config), + <<"gleam run"/utf8>> + ), + Flags@1 = begin + _pipe = Flags, + _pipe@1 = gleam@map:to_list(_pipe), + _pipe@2 = gleam@list:map(_pipe@1, fun glint@flag:flag_type_help/1), + gleam@list:sort(_pipe@2, fun gleam@string:compare/2) + end, + Flag_sb = case Flags@1 of + [] -> + gleam@string_builder:new(); + + _ -> + _pipe@3 = Flags@1, + _pipe@4 = gleam@list:intersperse(_pipe@3, <<" "/utf8>>), + _pipe@5 = gleam@string_builder:from_strings(_pipe@4), + _pipe@6 = gleam@string_builder:prepend(_pipe@5, <<" [ "/utf8>>), + gleam@string_builder:append(_pipe@6, <<" ]"/utf8>>) + end, + _pipe@7 = [App_name, wrap_with_space(Cmd_name), <<"[ ARGS ]"/utf8>>], + _pipe@8 = gleam@string_builder:from_strings(_pipe@7), + _pipe@9 = gleam@string_builder:append_builder(_pipe@8, Flag_sb), + _pipe@12 = gleam@string_builder:prepend( + _pipe@9, + <<(begin + _pipe@10 = erlang:element(2, Config), + _pipe@11 = gleam@option:map( + _pipe@10, + fun(Styling) -> + heading_style( + <<"USAGE:"/utf8>>, + erlang:element(2, Styling) + ) + end + ), + gleam@option:unwrap(_pipe@11, <<"USAGE:"/utf8>>) + end)/binary, + "\n\t"/utf8>> + ), + gleam@string_builder:to_string(_pipe@12). + +-spec help_flag() -> binary(). +help_flag() -> + <<(<<"--"/utf8>>)/binary, "help"/utf8>>. + +-spec cmd_help( + list(binary()), + command_node(any()), + config(), + gleam@dict:dict(binary(), glint@flag:flag()) +) -> binary(). +cmd_help(Path, Cmd, Config, Global_flags) -> + Name = begin + _pipe = Path, + _pipe@1 = gleam@list:reverse(_pipe), + gleam@string:join(_pipe@1, <<" "/utf8>>) + end, + Flags = begin + _pipe@2 = gleam@option:map( + erlang:element(2, Cmd), + fun(Contents) -> erlang:element(3, Contents) end + ), + _pipe@3 = gleam@option:lazy_unwrap(_pipe@2, fun gleam@map:new/0), + gleam@map:merge(Global_flags, _pipe@3) + end, + Flags_help_body = <<<<(begin + _pipe@4 = erlang:element(2, Config), + _pipe@5 = gleam@option:map( + _pipe@4, + fun(P) -> + heading_style(<<"FLAGS:"/utf8>>, erlang:element(3, P)) + end + ), + gleam@option:unwrap(_pipe@5, <<"FLAGS:"/utf8>>) + end)/binary, + "\n\t"/utf8>>/binary, + (gleam@string:join( + gleam@list:sort( + [<<"--help\t\t\tPrint help information"/utf8>> | + glint@flag:flags_help(Flags)], + fun gleam@string:compare/2 + ), + <<"\n\t"/utf8>> + ))/binary>>, + Usage = usage_help(Name, Flags, Config), + Description = begin + _pipe@6 = erlang:element(2, Cmd), + _pipe@7 = gleam@option:map( + _pipe@6, + fun(Contents@1) -> erlang:element(4, Contents@1) end + ), + gleam@option:unwrap(_pipe@7, <<""/utf8>>) + end, + Header_items = begin + _pipe@8 = [Name, Description], + _pipe@9 = gleam@list:filter(_pipe@8, fun is_not_empty/1), + gleam@string:join(_pipe@9, <<"\n"/utf8>>) + end, + Subcommands = case subcommands_help(erlang:element(3, Cmd)) of + <<""/utf8>> -> + <<""/utf8>>; + + Subcommands_help_body -> + <<<<(begin + _pipe@10 = erlang:element(2, Config), + _pipe@11 = gleam@option:map( + _pipe@10, + fun(P@1) -> + heading_style( + <<"SUBCOMMANDS:"/utf8>>, + erlang:element(4, P@1) + ) + end + ), + gleam@option:unwrap(_pipe@11, <<"SUBCOMMANDS:"/utf8>>) + end)/binary, + "\n\t"/utf8>>/binary, + Subcommands_help_body/binary>> + end, + _pipe@12 = [Header_items, Usage, Flags_help_body, Subcommands], + _pipe@13 = gleam@list:filter(_pipe@12, fun is_not_empty/1), + gleam@string:join(_pipe@13, <<"\n\n"/utf8>>). + +-spec do_execute( + command_node(KYY), + config(), + gleam@dict:dict(binary(), glint@flag:flag()), + list(binary()), + list(binary()), + boolean(), + list(binary()) +) -> {ok, out(KYY)} | {error, snag:snag()}. +do_execute(Cmd, Config, Global_flags, Args, Flags, Help, Command_path) -> + case Args of + [] when Help -> + _pipe = Command_path, + _pipe@1 = cmd_help(_pipe, Cmd, Config, Global_flags), + _pipe@2 = {help, _pipe@1}, + {ok, _pipe@2}; + + [] -> + execute_root(Cmd, Global_flags, [], Flags); + + [Arg | Rest] -> + case gleam@map:get(erlang:element(3, Cmd), Arg) of + {ok, Cmd@1} -> + do_execute( + Cmd@1, + Config, + Global_flags, + Rest, + Flags, + Help, + [Arg | Command_path] + ); + + _ when Help -> + _pipe@3 = Command_path, + _pipe@4 = cmd_help(_pipe@3, Cmd, Config, Global_flags), + _pipe@5 = {help, _pipe@4}, + {ok, _pipe@5}; + + _ -> + execute_root(Cmd, Global_flags, Args, Flags) + end + end. + +-spec execute(glint(KYU), list(binary())) -> {ok, out(KYU)} | + {error, snag:snag()}. +execute(Glint, Args) -> + Help_flag = help_flag(), + {Help, Args@2} = case gleam@list:pop(Args, fun(S) -> S =:= Help_flag end) of + {ok, {_, Args@1}} -> + {true, Args@1}; + + _ -> + {false, Args} + end, + {Flags, Args@3} = gleam@list:partition( + Args@2, + fun(_capture) -> gleam@string:starts_with(_capture, <<"--"/utf8>>) end + ), + do_execute( + erlang:element(3, Glint), + erlang:element(2, Glint), + erlang:element(4, Glint), + Args@3, + Flags, + Help, + [] + ). + +-spec run_and_handle(glint(KZM), list(binary()), fun((KZM) -> any())) -> nil. +run_and_handle(Glint, Args, Handle) -> + case execute(Glint, Args) of + {error, Err} -> + _pipe = Err, + _pipe@1 = snag:pretty_print(_pipe), + gleam@io:println(_pipe@1); + + {ok, {help, Help}} -> + gleam@io:println(Help); + + {ok, {out, Out}} -> + Handle(Out), + nil + end. + +-spec run(glint(any()), list(binary())) -> nil. +run(Glint, Args) -> + run_and_handle(Glint, Args, gleam@function:constant(nil)). diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache Binary files differnew file mode 100644 index 0000000..7570f95 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache_meta b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache_meta Binary files differnew file mode 100644 index 0000000..be367e3 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.cache_meta diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.erl b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.erl new file mode 100644 index 0000000..2b2a8c3 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag.erl @@ -0,0 +1,523 @@ +-module(glint@flag). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([string/0, string_list/0, build/1, constraint/2, description/2, default/2, build_map/1, int/0, int_list/0, float/0, float_list/0, bool/0, get_int_value/1, get_int/2, get_ints_value/1, get_ints/2, get_bool_value/1, get_bool/2, get_string_value/1, get_string/2, get_strings_value/1, get_strings/2, get_float_value/1, get_float/2, get_floats_value/1, get_floats/2, update_flags/2, flag_type_help/1, flags_help/1]). +-export_type([value/0, flag_builder/1, internal/1, flag/0]). + +-type value() :: {b, internal(boolean())} | + {i, internal(integer())} | + {li, internal(list(integer()))} | + {f, internal(float())} | + {lf, internal(list(float()))} | + {s, internal(binary())} | + {ls, internal(list(binary()))}. + +-opaque flag_builder(KIJ) :: {flag_builder, + binary(), + fun((binary()) -> {ok, KIJ} | {error, snag:snag()}), + fun((internal(KIJ)) -> value()), + gleam@option:option(KIJ)}. + +-opaque internal(KIK) :: {internal, + gleam@option:option(KIK), + fun((binary()) -> {ok, KIK} | {error, snag:snag()})}. + +-type flag() :: {flag, value(), binary()}. + +-spec new( + fun((internal(KJB)) -> value()), + fun((binary()) -> {ok, KJB} | {error, snag:snag()}) +) -> flag_builder(KJB). +new(Valuer, P) -> + {flag_builder, <<""/utf8>>, P, Valuer, none}. + +-spec string() -> flag_builder(binary()). +string() -> + new(fun(Field@0) -> {s, Field@0} end, fun(S) -> {ok, S} end). + +-spec string_list() -> flag_builder(list(binary())). +string_list() -> + new(fun(Field@0) -> {ls, Field@0} end, fun(Input) -> _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<","/utf8>>), + {ok, _pipe@1} end). + +-spec build(flag_builder(any())) -> flag(). +build(Fb) -> + {flag, + (erlang:element(4, Fb))( + {internal, erlang:element(5, Fb), erlang:element(3, Fb)} + ), + erlang:element(2, Fb)}. + +-spec attempt( + {ok, KJS} | {error, KJT}, + fun((KJS) -> {ok, any()} | {error, KJT}) +) -> {ok, KJS} | {error, KJT}. +attempt(Val, F) -> + gleam@result:'try'(Val, fun(A) -> gleam@result:replace(F(A), A) end). + +-spec wrap_with_constraint( + fun((binary()) -> {ok, KJM} | {error, snag:snag()}), + fun((KJM) -> {ok, nil} | {error, snag:snag()}) +) -> fun((binary()) -> {ok, KJM} | {error, snag:snag()}). +wrap_with_constraint(P, Constraint) -> + fun(Input) -> attempt(P(Input), Constraint) end. + +-spec constraint( + flag_builder(KJI), + fun((KJI) -> {ok, nil} | {error, snag:snag()}) +) -> flag_builder(KJI). +constraint(Builder, Constraint) -> + erlang:setelement( + 3, + Builder, + wrap_with_constraint(erlang:element(3, Builder), Constraint) + ). + +-spec description(flag_builder(KKB), binary()) -> flag_builder(KKB). +description(Builder, Description) -> + erlang:setelement(2, Builder, Description). + +-spec default(flag_builder(KKE), KKE) -> flag_builder(KKE). +default(Builder, Default) -> + erlang:setelement(5, Builder, {some, Default}). + +-spec build_map(list({binary(), flag()})) -> gleam@dict:dict(binary(), flag()). +build_map(Flags) -> + gleam@map:from_list(Flags). + +-spec access_type_error(binary()) -> {ok, any()} | {error, snag:snag()}. +access_type_error(Flag_type) -> + snag:error(<<"cannot access flag as "/utf8, Flag_type/binary>>). + +-spec flag_not_provided_error() -> {ok, any()} | {error, snag:snag()}. +flag_not_provided_error() -> + snag:error(<<"no value provided"/utf8>>). + +-spec construct_value(binary(), internal(KKO), fun((internal(KKO)) -> value())) -> {ok, + value()} | + {error, snag:snag()}. +construct_value(Input, Internal, Constructor) -> + gleam@result:map( + (erlang:element(3, Internal))(Input), + fun(Val) -> Constructor(erlang:setelement(2, Internal, {some, Val})) end + ). + +-spec compute_flag(binary(), value()) -> {ok, value()} | {error, snag:snag()}. +compute_flag(Input, Current) -> + _pipe = Input, + _pipe@1 = case Current of + {i, Internal} -> + fun(_capture) -> + construct_value( + _capture, + Internal, + fun(Field@0) -> {i, Field@0} end + ) + end; + + {li, Internal@1} -> + fun(_capture@1) -> + construct_value( + _capture@1, + Internal@1, + fun(Field@0) -> {li, Field@0} end + ) + end; + + {f, Internal@2} -> + fun(_capture@2) -> + construct_value( + _capture@2, + Internal@2, + fun(Field@0) -> {f, Field@0} end + ) + end; + + {lf, Internal@3} -> + fun(_capture@3) -> + construct_value( + _capture@3, + Internal@3, + fun(Field@0) -> {lf, Field@0} end + ) + end; + + {s, Internal@4} -> + fun(_capture@4) -> + construct_value( + _capture@4, + Internal@4, + fun(Field@0) -> {s, Field@0} end + ) + end; + + {ls, Internal@5} -> + fun(_capture@5) -> + construct_value( + _capture@5, + Internal@5, + fun(Field@0) -> {ls, Field@0} end + ) + end; + + {b, Internal@6} -> + fun(_capture@6) -> + construct_value( + _capture@6, + Internal@6, + fun(Field@0) -> {b, Field@0} end + ) + end + end(_pipe), + snag:context(_pipe@1, <<"failed to compute value for flag"/utf8>>). + +-spec layer_invalid_flag(snag:snag(), binary()) -> snag:snag(). +layer_invalid_flag(Err, Flag) -> + snag:layer(Err, <<<<"invalid flag '"/utf8, Flag/binary>>/binary, "'"/utf8>>). + +-spec no_value_flag_err(binary()) -> snag:snag(). +no_value_flag_err(Flag_input) -> + _pipe = (<<<<"flag '"/utf8, Flag_input/binary>>/binary, + "' has no assigned value"/utf8>>), + _pipe@1 = snag:new(_pipe), + layer_invalid_flag(_pipe@1, Flag_input). + +-spec undefined_flag_err(binary()) -> snag:snag(). +undefined_flag_err(Key) -> + _pipe = <<"flag provided but not defined"/utf8>>, + _pipe@1 = snag:new(_pipe), + layer_invalid_flag(_pipe@1, Key). + +-spec cannot_parse(binary(), binary()) -> snag:snag(). +cannot_parse(Value, Kind) -> + _pipe = (<<<<<<"cannot parse value '"/utf8, Value/binary>>/binary, + "' as "/utf8>>/binary, + Kind/binary>>), + snag:new(_pipe). + +-spec int() -> flag_builder(integer()). +int() -> + new(fun(Field@0) -> {i, Field@0} end, fun(Input) -> _pipe = Input, + _pipe@1 = gleam@int:parse(_pipe), + gleam@result:replace_error( + _pipe@1, + cannot_parse(Input, <<"int"/utf8>>) + ) end). + +-spec int_list() -> flag_builder(list(integer())). +int_list() -> + new(fun(Field@0) -> {li, Field@0} end, fun(Input) -> _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<","/utf8>>), + _pipe@2 = gleam@list:try_map(_pipe@1, fun gleam@int:parse/1), + gleam@result:replace_error( + _pipe@2, + cannot_parse(Input, <<"int list"/utf8>>) + ) end). + +-spec float() -> flag_builder(float()). +float() -> + new(fun(Field@0) -> {f, Field@0} end, fun(Input) -> _pipe = Input, + _pipe@1 = gleam@float:parse(_pipe), + gleam@result:replace_error( + _pipe@1, + cannot_parse(Input, <<"float"/utf8>>) + ) end). + +-spec float_list() -> flag_builder(list(float())). +float_list() -> + new(fun(Field@0) -> {lf, Field@0} end, fun(Input) -> _pipe = Input, + _pipe@1 = gleam@string:split(_pipe, <<","/utf8>>), + _pipe@2 = gleam@list:try_map(_pipe@1, fun gleam@float:parse/1), + gleam@result:replace_error( + _pipe@2, + cannot_parse(Input, <<"float list"/utf8>>) + ) end). + +-spec bool() -> flag_builder(boolean()). +bool() -> + new( + fun(Field@0) -> {b, Field@0} end, + fun(Input) -> case gleam@string:lowercase(Input) of + <<"true"/utf8>> -> + {ok, true}; + + <<"t"/utf8>> -> + {ok, true}; + + <<"false"/utf8>> -> + {ok, false}; + + <<"f"/utf8>> -> + {ok, false}; + + _ -> + {error, cannot_parse(Input, <<"bool"/utf8>>)} + end end + ). + +-spec access(gleam@dict:dict(binary(), flag()), binary()) -> {ok, flag()} | + {error, snag:snag()}. +access(Flags, Name) -> + _pipe = gleam@map:get(Flags, Name), + gleam@result:replace_error(_pipe, undefined_flag_err(Name)). + +-spec update_flag_value(gleam@dict:dict(binary(), flag()), {binary(), binary()}) -> {ok, + gleam@dict:dict(binary(), flag())} | + {error, snag:snag()}. +update_flag_value(Flags, Data) -> + {Key, Input} = Data, + gleam@result:'try'( + access(Flags, Key), + fun(Contents) -> + gleam@result:map( + begin + _pipe = compute_flag(Input, erlang:element(2, Contents)), + gleam@result:map_error( + _pipe, + fun(_capture) -> layer_invalid_flag(_capture, Key) end + ) + end, + fun(Value) -> + gleam@map:insert( + Flags, + Key, + erlang:setelement(2, Contents, Value) + ) + end + ) + end + ). + +-spec attempt_toggle_flag(gleam@dict:dict(binary(), flag()), binary()) -> {ok, + gleam@dict:dict(binary(), flag())} | + {error, snag:snag()}. +attempt_toggle_flag(Flags, Key) -> + gleam@result:'try'( + access(Flags, Key), + fun(Contents) -> case erlang:element(2, Contents) of + {b, {internal, none, _} = Internal} -> + _pipe = erlang:setelement(2, Internal, {some, true}), + _pipe@1 = {b, _pipe}, + _pipe@2 = (fun(Val) -> + erlang:setelement(2, Contents, Val) + end)(_pipe@1), + _pipe@3 = gleam@map:insert(Flags, Key, _pipe@2), + {ok, _pipe@3}; + + {b, {internal, {some, Val@1}, _} = Internal@1} -> + _pipe@4 = erlang:setelement( + 2, + Internal@1, + {some, not Val@1} + ), + _pipe@5 = {b, _pipe@4}, + _pipe@6 = (fun(Val@2) -> + erlang:setelement(2, Contents, Val@2) + end)(_pipe@5), + _pipe@7 = gleam@map:insert(Flags, Key, _pipe@6), + {ok, _pipe@7}; + + _ -> + {error, no_value_flag_err(Key)} + end end + ). + +-spec get_value( + gleam@dict:dict(binary(), flag()), + binary(), + fun((flag()) -> {ok, KKW} | {error, snag:snag()}) +) -> {ok, KKW} | {error, snag:snag()}. +get_value(Flags, Key, Kind) -> + _pipe = access(Flags, Key), + _pipe@1 = gleam@result:'try'(_pipe, Kind), + snag:context( + _pipe@1, + <<<<"failed to retrieve value for flag '"/utf8, Key/binary>>/binary, + "'"/utf8>> + ). + +-spec get_int_value(flag()) -> {ok, integer()} | {error, snag:snag()}. +get_int_value(Flag) -> + case erlang:element(2, Flag) of + {i, {internal, {some, Val}, _}} -> + {ok, Val}; + + {i, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"int"/utf8>>) + end. + +-spec get_int(gleam@dict:dict(binary(), flag()), binary()) -> {ok, integer()} | + {error, snag:snag()}. +get_int(Flags, Name) -> + get_value(Flags, Name, fun get_int_value/1). + +-spec get_ints_value(flag()) -> {ok, list(integer())} | {error, snag:snag()}. +get_ints_value(Flag) -> + case erlang:element(2, Flag) of + {li, {internal, {some, Val}, _}} -> + {ok, Val}; + + {li, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"int list"/utf8>>) + end. + +-spec get_ints(gleam@dict:dict(binary(), flag()), binary()) -> {ok, + list(integer())} | + {error, snag:snag()}. +get_ints(Flags, Name) -> + get_value(Flags, Name, fun get_ints_value/1). + +-spec get_bool_value(flag()) -> {ok, boolean()} | {error, snag:snag()}. +get_bool_value(Flag) -> + case erlang:element(2, Flag) of + {b, {internal, {some, Val}, _}} -> + {ok, Val}; + + {b, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"bool"/utf8>>) + end. + +-spec get_bool(gleam@dict:dict(binary(), flag()), binary()) -> {ok, boolean()} | + {error, snag:snag()}. +get_bool(Flags, Name) -> + get_value(Flags, Name, fun get_bool_value/1). + +-spec get_string_value(flag()) -> {ok, binary()} | {error, snag:snag()}. +get_string_value(Flag) -> + case erlang:element(2, Flag) of + {s, {internal, {some, Val}, _}} -> + {ok, Val}; + + {s, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"string"/utf8>>) + end. + +-spec get_string(gleam@dict:dict(binary(), flag()), binary()) -> {ok, binary()} | + {error, snag:snag()}. +get_string(Flags, Name) -> + get_value(Flags, Name, fun get_string_value/1). + +-spec get_strings_value(flag()) -> {ok, list(binary())} | {error, snag:snag()}. +get_strings_value(Flag) -> + case erlang:element(2, Flag) of + {ls, {internal, {some, Val}, _}} -> + {ok, Val}; + + {ls, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"string list"/utf8>>) + end. + +-spec get_strings(gleam@dict:dict(binary(), flag()), binary()) -> {ok, + list(binary())} | + {error, snag:snag()}. +get_strings(Flags, Name) -> + get_value(Flags, Name, fun get_strings_value/1). + +-spec get_float_value(flag()) -> {ok, float()} | {error, snag:snag()}. +get_float_value(Flag) -> + case erlang:element(2, Flag) of + {f, {internal, {some, Val}, _}} -> + {ok, Val}; + + {f, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"float"/utf8>>) + end. + +-spec get_float(gleam@dict:dict(binary(), flag()), binary()) -> {ok, float()} | + {error, snag:snag()}. +get_float(Flags, Name) -> + get_value(Flags, Name, fun get_float_value/1). + +-spec get_floats_value(flag()) -> {ok, list(float())} | {error, snag:snag()}. +get_floats_value(Flag) -> + case erlang:element(2, Flag) of + {lf, {internal, {some, Val}, _}} -> + {ok, Val}; + + {lf, {internal, none, _}} -> + flag_not_provided_error(); + + _ -> + access_type_error(<<"float list"/utf8>>) + end. + +-spec get_floats(gleam@dict:dict(binary(), flag()), binary()) -> {ok, + list(float())} | + {error, snag:snag()}. +get_floats(Flags, Name) -> + get_value(Flags, Name, fun get_floats_value/1). + +-spec update_flags(gleam@dict:dict(binary(), flag()), binary()) -> {ok, + gleam@dict:dict(binary(), flag())} | + {error, snag:snag()}. +update_flags(Flags, Flag_input) -> + Flag_input@1 = gleam@string:drop_left( + Flag_input, + gleam@string:length(<<"--"/utf8>>) + ), + case gleam@string:split_once(Flag_input@1, <<"="/utf8>>) of + {ok, Data} -> + update_flag_value(Flags, Data); + + {error, _} -> + attempt_toggle_flag(Flags, Flag_input@1) + end. + +-spec flag_type_help({binary(), flag()}) -> binary(). +flag_type_help(Flag) -> + {Name, Contents} = Flag, + Kind = case erlang:element(2, Contents) of + {i, _} -> + <<"INT"/utf8>>; + + {b, _} -> + <<"BOOL"/utf8>>; + + {f, _} -> + <<"FLOAT"/utf8>>; + + {lf, _} -> + <<"FLOAT_LIST"/utf8>>; + + {li, _} -> + <<"INT_LIST"/utf8>>; + + {ls, _} -> + <<"STRING_LIST"/utf8>>; + + {s, _} -> + <<"STRING"/utf8>> + end, + <<<<<<<<<<"--"/utf8, Name/binary>>/binary, "="/utf8>>/binary, "<"/utf8>>/binary, + Kind/binary>>/binary, + ">"/utf8>>. + +-spec flag_help({binary(), flag()}) -> binary(). +flag_help(Flag) -> + <<<<(flag_type_help(Flag))/binary, "\t\t"/utf8>>/binary, + (erlang:element(3, (erlang:element(2, Flag))))/binary>>. + +-spec flags_help(gleam@dict:dict(binary(), flag())) -> list(binary()). +flags_help(Flags) -> + _pipe = Flags, + _pipe@1 = gleam@map:to_list(_pipe), + gleam@list:map(_pipe@1, fun flag_help/1). diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache Binary files differnew file mode 100644 index 0000000..4c08669 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache_meta b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache_meta Binary files differnew file mode 100644 index 0000000..355567d --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.cache_meta diff --git a/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.erl b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.erl new file mode 100644 index 0000000..0e1cc04 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/_gleam_artefacts/glint@flag@constraint.erl @@ -0,0 +1,68 @@ +-module(glint@flag@constraint). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([one_of/1, none_of/1, each/1]). + +-spec one_of(list(KGS)) -> fun((KGS) -> {ok, nil} | {error, snag:snag()}). +one_of(Allowed) -> + Allowed_set = gleam@set:from_list(Allowed), + fun(Val) -> case gleam@set:contains(Allowed_set, Val) of + true -> + {ok, nil}; + + false -> + snag:error( + <<<<<<"invalid value '"/utf8, + (gleam@string:inspect(Val))/binary>>/binary, + "', must be one of: ["/utf8>>/binary, + ((<<(begin + _pipe = Allowed, + _pipe@1 = gleam@list:map( + _pipe, + fun(A) -> + <<<<"'"/utf8, + (gleam@string:inspect(A))/binary>>/binary, + "'"/utf8>> + end + ), + gleam@string:join(_pipe@1, <<", "/utf8>>) + end)/binary, + "]"/utf8>>))/binary>> + ) + end end. + +-spec none_of(list(KGV)) -> fun((KGV) -> {ok, nil} | {error, snag:snag()}). +none_of(Disallowed) -> + Disallowed_set = gleam@set:from_list(Disallowed), + fun(Val) -> case gleam@set:contains(Disallowed_set, Val) of + false -> + {ok, nil}; + + true -> + snag:error( + <<<<<<"invalid value '"/utf8, + (gleam@string:inspect(Val))/binary>>/binary, + "', must not be one of: ["/utf8>>/binary, + (((<<(begin + _pipe = Disallowed, + _pipe@1 = gleam@list:map( + _pipe, + fun(A) -> + <<<<"'"/utf8, + (gleam@string:inspect(A))/binary>>/binary, + "'"/utf8>> + end + ), + gleam@string:join(_pipe@1, <<", "/utf8>>) + end)/binary, + "]"/utf8>>)))/binary>> + ) + end end. + +-spec each(fun((KGY) -> {ok, nil} | {error, snag:snag()})) -> fun((list(KGY)) -> {ok, + nil} | + {error, snag:snag()}). +each(Constraint) -> + fun(L) -> _pipe = L, + _pipe@1 = gleam@list:try_map(_pipe, Constraint), + gleam@result:replace(_pipe@1, nil) end. diff --git a/aoc2023/build/dev/erlang/glint/ebin/glint.app b/aoc2023/build/dev/erlang/glint/ebin/glint.app new file mode 100644 index 0000000..41fba79 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/ebin/glint.app @@ -0,0 +1,10 @@ +{application, glint, [ + {vsn, "0.13.0"}, + {applications, [gleam_community_ansi, + gleam_community_colour, + gleam_stdlib, + snag]}, + {description, "Gleam command line argument parsing with basic flag support."}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/glint/ebin/glint.beam b/aoc2023/build/dev/erlang/glint/ebin/glint.beam Binary files differnew file mode 100644 index 0000000..80ab9b9 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/ebin/glint.beam diff --git a/aoc2023/build/dev/erlang/glint/ebin/glint@flag.beam b/aoc2023/build/dev/erlang/glint/ebin/glint@flag.beam Binary files differnew file mode 100644 index 0000000..66ef4f0 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/ebin/glint@flag.beam diff --git a/aoc2023/build/dev/erlang/glint/ebin/glint@flag@constraint.beam b/aoc2023/build/dev/erlang/glint/ebin/glint@flag@constraint.beam Binary files differnew file mode 100644 index 0000000..c6377ad --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/ebin/glint@flag@constraint.beam diff --git a/aoc2023/build/dev/erlang/glint/include/glint@flag_Flag.hrl b/aoc2023/build/dev/erlang/glint/include/glint@flag_Flag.hrl new file mode 100644 index 0000000..645cb12 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint@flag_Flag.hrl @@ -0,0 +1 @@ +-record(flag, {value :: glint@flag:value(), description :: binary()}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint@flag_FlagBuilder.hrl b/aoc2023/build/dev/erlang/glint/include/glint@flag_FlagBuilder.hrl new file mode 100644 index 0000000..b5e21a2 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint@flag_FlagBuilder.hrl @@ -0,0 +1,6 @@ +-record(flag_builder, { + desc :: binary(), + parser :: fun((binary()) -> {ok, any()} | {error, snag:snag()}), + value :: fun((glint@flag:internal(any())) -> glint@flag:value()), + default :: gleam@option:option(any()) +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint@flag_Internal.hrl b/aoc2023/build/dev/erlang/glint/include/glint@flag_Internal.hrl new file mode 100644 index 0000000..281bbd0 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint@flag_Internal.hrl @@ -0,0 +1,4 @@ +-record(internal, { + value :: gleam@option:option(any()), + parser :: fun((binary()) -> {ok, any()} | {error, snag:snag()}) +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_Command.hrl b/aoc2023/build/dev/erlang/glint/include/glint_Command.hrl new file mode 100644 index 0000000..2761365 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_Command.hrl @@ -0,0 +1,5 @@ +-record(command, { + do :: fun((glint:command_input()) -> any()), + flags :: gleam@dict:dict(binary(), glint@flag:flag()), + description :: binary() +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_CommandInput.hrl b/aoc2023/build/dev/erlang/glint/include/glint_CommandInput.hrl new file mode 100644 index 0000000..e0e1a81 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_CommandInput.hrl @@ -0,0 +1,4 @@ +-record(command_input, { + args :: list(binary()), + flags :: gleam@dict:dict(binary(), glint@flag:flag()) +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_Config.hrl b/aoc2023/build/dev/erlang/glint/include/glint_Config.hrl new file mode 100644 index 0000000..70cf645 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_Config.hrl @@ -0,0 +1,4 @@ +-record(config, { + pretty_help :: gleam@option:option(glint:pretty_help()), + name :: gleam@option:option(binary()) +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_Glint.hrl b/aoc2023/build/dev/erlang/glint/include/glint_Glint.hrl new file mode 100644 index 0000000..f14c34c --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_Glint.hrl @@ -0,0 +1,5 @@ +-record(glint, { + config :: glint:config(), + cmd :: glint:command_node(any()), + global_flags :: gleam@dict:dict(binary(), glint@flag:flag()) +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_PrettyHelp.hrl b/aoc2023/build/dev/erlang/glint/include/glint_PrettyHelp.hrl new file mode 100644 index 0000000..79bd887 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_PrettyHelp.hrl @@ -0,0 +1,5 @@ +-record(pretty_help, { + usage :: gleam_community@colour:colour(), + flags :: gleam_community@colour:colour(), + subcommands :: gleam_community@colour:colour() +}). diff --git a/aoc2023/build/dev/erlang/glint/include/glint_Stub.hrl b/aoc2023/build/dev/erlang/glint/include/glint_Stub.hrl new file mode 100644 index 0000000..5aa5d83 --- /dev/null +++ b/aoc2023/build/dev/erlang/glint/include/glint_Stub.hrl @@ -0,0 +1,6 @@ +-record(stub, { + path :: list(binary()), + run :: fun((glint:command_input()) -> any()), + flags :: list({binary(), glint@flag:flag()}), + description :: binary() +}). diff --git a/aoc2023/build/dev/erlang/pqueue/LICENSE b/aoc2023/build/dev/erlang/pqueue/LICENSE new file mode 100644 index 0000000..5697803 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/LICENSE @@ -0,0 +1,21 @@ +MIT License
+
+Copyright (c) 2011-2023 Michael Truog <mjtruog at protonmail dot com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/aoc2023/build/dev/erlang/pqueue/README.markdown b/aoc2023/build/dev/erlang/pqueue/README.markdown new file mode 100644 index 0000000..77aaf1c --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/README.markdown @@ -0,0 +1,31 @@ +Erlang Priority Queue Implementation +==================================== + +The priority queue implementations implement a subset of the stdlib Erlang queue interface as seen in the implementation used by both [Riak and RabbitMQ](https://github.com/basho/riak_core/blob/master/src/riak_core_priority_queue.erl). + +The implementations: + +* `priority_queue` (fastest for any priorities when only using a single priority at a time) +* `pqueue` (fastest for 41 priorities, -20 (high) to 20 (low), when using 2 or more priorities at the same time) +* `pqueue2` (slower heap implementation) +* `pqueue3` (faster than `pqueue2` and `priority_queue` when using 64 or more priorities at the same time) +* `pqueue4` (slightly slower than `pqueue` but fastest for allowing 257 priorities, -128 (high) to 128 (low), i.e., fastest when using 42 or more priorities at the same time) + +[The latest results are here](http://okeuday.livejournal.com/19539.html), with [the benchmark here](http://github.com/okeuday/erlbench). + +Author +------ + +Michael Truog (mjtruog at protonmail dot com) + +Thanks +------ + +* Jesper Louis andersen (PropEr integration and testing) +* Ulf Wiger (suggestions and insight) + +License +------- + +MIT License + diff --git a/aoc2023/build/dev/erlang/pqueue/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag b/aoc2023/build/dev/erlang/pqueue/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag Binary files differnew file mode 100644 index 0000000..28d7520 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/_build/prod/lib/.rebar3/rebar_compiler_erl/source.dag diff --git a/aoc2023/build/dev/erlang/pqueue/doc/edoc-info b/aoc2023/build/dev/erlang/pqueue/doc/edoc-info new file mode 100644 index 0000000..5e5a8d3 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/edoc-info @@ -0,0 +1,3 @@ +%% encoding: UTF-8 +{application,pqueue}. +{modules,[pqueue,pqueue2,pqueue3,pqueue4]}. diff --git a/aoc2023/build/dev/erlang/pqueue/doc/erlang.png b/aoc2023/build/dev/erlang/pqueue/doc/erlang.png Binary files differnew file mode 100644 index 0000000..987a618 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/erlang.png diff --git a/aoc2023/build/dev/erlang/pqueue/doc/index.html b/aoc2023/build/dev/erlang/pqueue/doc/index.html new file mode 100644 index 0000000..d55b5e6 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/index.html @@ -0,0 +1,17 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<title>The pqueue application</title> +</head> +<frameset cols="20%,80%"> +<frame src="modules-frame.html" name="modulesFrame" title=""> + +<frame src="overview-summary.html" name="overviewFrame" title=""> +<noframes> +<h2>This page uses frames</h2> +<p>Your browser does not accept frames. +<br>You should go to the <a href="overview-summary.html">non-frame version</a> instead. +</p> +</noframes> +</frameset> +</html>
\ No newline at end of file diff --git a/aoc2023/build/dev/erlang/pqueue/doc/modules-frame.html b/aoc2023/build/dev/erlang/pqueue/doc/modules-frame.html new file mode 100644 index 0000000..5a87cc4 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/modules-frame.html @@ -0,0 +1,15 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<title>The pqueue application</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<h2 class="indextitle">Modules</h2> +<table width="100%" border="0" summary="list of modules"> +<tr><td><a href="pqueue.html" target="overviewFrame" class="module">pqueue</a></td></tr> +<tr><td><a href="pqueue2.html" target="overviewFrame" class="module">pqueue2</a></td></tr> +<tr><td><a href="pqueue3.html" target="overviewFrame" class="module">pqueue3</a></td></tr> +<tr><td><a href="pqueue4.html" target="overviewFrame" class="module">pqueue4</a></td></tr></table> +</body> +</html>
\ No newline at end of file diff --git a/aoc2023/build/dev/erlang/pqueue/doc/overview-summary.html b/aoc2023/build/dev/erlang/pqueue/doc/overview-summary.html new file mode 100644 index 0000000..e2f8906 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/overview-summary.html @@ -0,0 +1,16 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>The pqueue application</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<h1>The pqueue application</h1> + +<hr> +<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<p><i>Generated by EDoc</i></p> +</body> +</html> diff --git a/aoc2023/build/dev/erlang/pqueue/doc/pqueue.html b/aoc2023/build/dev/erlang/pqueue/doc/pqueue.html new file mode 100644 index 0000000..40b05ac --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/pqueue.html @@ -0,0 +1,166 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>Module pqueue</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<hr> + +<h1>Module pqueue</h1> +<ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul> + <h3><a name="Static_Priority_Queue.">Static Priority Queue.</a></h3> + This priority queue implementation depends on a static number of priorities + (-20 (high) to 20 (low)) so that tuple access times can be exploited for + quick in/out priority queue operations. +<p>Copyright © 2011-2020 Michael Truog</p> + +<p><b>Version:</b> 2.0.1 Nov 26 2020 14:55:34 + ------------------------------------------------------------------------</p> +<p><b>Authors:</b> Michael Truog (<a href="mailto:mjtruog at protonmail dot com"><tt>mjtruog at protonmail dot com</tt></a>).</p> + +<h2><a name="description">Description</a></h2> + <h3><a name="Static_Priority_Queue.">Static Priority Queue.</a></h3> + This priority queue implementation depends on a static number of priorities + (-20 (high) to 20 (low)) so that tuple access times can be exploited for + quick in/out priority queue operations. This implementation was created to + avoid the slowness within the priority queue used by both RabbitMQ and Riak + (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +<h2><a name="types">Data Types</a></h2> + +<h3 class="typedecl"><a name="type-pqueue">pqueue()</a></h3> +<p><tt>pqueue() = {integer(), {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, <a href="queue.html#type-queue">queue:queue()</a>, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}} | {empty, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, <a href="queue.html#type-queue">queue:queue()</a>, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}, {<a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>, <a href="queue.html#type-queue">queue:queue()</a>}}</tt></p> + + +<h2><a name="index">Function Index</a></h2> +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#in-2">in/2</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#in-3">in/3</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_empty-1">is_empty/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_queue-1">is_queue/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#join-2">join/2</a></td><td> + <h4><a name="Join_two_priority_queues.">Join two priority queues.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#len-1">len/1</a></td><td> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#new-0">new/0</a></td><td> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#out-1">out/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#out-2">out/2</a></td><td> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#pout-1">pout/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value.</td></tr> +<tr><td valign="top"><a href="#test-0">test/0</a></td><td> + <h4><a name="Regression_test.">Regression test.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#to_list-1">to_list/1</a></td><td> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N).</td></tr> +</table> + +<h2><a name="functions">Function Details</a></h2> + +<h3 class="function"><a name="in-2">in/2</a></h3> +<div class="spec"> +<p><tt>in(X::term(), Q::<a href="#type-pqueue">pqueue()</a>) -> <a href="#type-pqueue">pqueue()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="in-3">in/3</a></h3> +<div class="spec"> +<p><tt>in(X::term(), P::integer(), Q::<a href="#type-pqueue">pqueue()</a>) -> <a href="#type-pqueue">pqueue()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_empty-1">is_empty/1</a></h3> +<div class="spec"> +<p><tt>is_empty(X1::<a href="#type-pqueue">pqueue()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_queue-1">is_queue/1</a></h3> +<div class="spec"> +<p><tt>is_queue(X1::<a href="#type-pqueue">pqueue()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1)</p> + +<h3 class="function"><a name="join-2">join/2</a></h3> +<div class="spec"> +<p><tt>join(X1::<a href="#type-pqueue">pqueue()</a>, X2::<a href="#type-pqueue">pqueue()</a>) -> <a href="#type-pqueue">pqueue()</a></tt><br></p> +</div><p> + <h4><a name="Join_two_priority_queues.">Join two priority queues.</a></h4> + O(N)</p> + +<h3 class="function"><a name="len-1">len/1</a></h3> +<div class="spec"> +<p><tt>len(X1::<a href="#type-pqueue">pqueue()</a>) -> non_neg_integer()</tt><br></p> +</div><p> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(N)</p> + +<h3 class="function"><a name="new-0">new/0</a></h3> +<div class="spec"> +<p><tt>new() -> <a href="#type-pqueue">pqueue()</a></tt><br></p> +</div><p> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="out-1">out/1</a></h3> +<div class="spec"> +<p><tt>out(Q::<a href="#type-pqueue">pqueue()</a>) -> {{value, term()}, <a href="#type-pqueue">pqueue()</a>} | {empty, <a href="#type-pqueue">pqueue()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="out-2">out/2</a></h3> +<div class="spec"> +<p><tt>out(P::integer(), Q::<a href="#type-pqueue">pqueue()</a>) -> {{value, term()}, <a href="#type-pqueue">pqueue()</a>} | {empty, <a href="#type-pqueue">pqueue()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="pout-1">pout/1</a></h3> +<div class="spec"> +<p><tt>pout(Q::<a href="#type-pqueue">pqueue()</a>) -> {{value, term(), integer()}, <a href="#type-pqueue">pqueue()</a>} | {empty, <a href="#type-pqueue">pqueue()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value. + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="test-0">test/0</a></h3> +<div class="spec"> +<p><tt>test() -> any()</tt></p> +</div><p> + <h4><a name="Regression_test.">Regression test.</a></h4> +</p> + +<h3 class="function"><a name="to_list-1">to_list/1</a></h3> +<div class="spec"> +<p><tt>to_list(X1::<a href="#type-pqueue">pqueue()</a>) -> [term()]</tt><br></p> +</div><p> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N)</p> +<hr> + +<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<p><i>Generated by EDoc</i></p> +</body> +</html> diff --git a/aoc2023/build/dev/erlang/pqueue/doc/pqueue2.html b/aoc2023/build/dev/erlang/pqueue/doc/pqueue2.html new file mode 100644 index 0000000..2942b84 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/pqueue2.html @@ -0,0 +1,143 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>Module pqueue2</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<hr> + +<h1>Module pqueue2</h1> +<ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul> + <h3><a name="Skew_Heap_Priority_Queue.">Skew Heap Priority Queue.</a></h3> + Ulf Wiger suggested pursuing a skew heap as an optimal Erlang priority + queue implementation. +<p>Copyright © 2011-2020 Michael Truog</p> + +<p><b>Version:</b> 2.0.1 Nov 26 2020 14:55:32 + ------------------------------------------------------------------------</p> +<p><b>Authors:</b> Michael Truog (<a href="mailto:mjtruog at protonmail dot com"><tt>mjtruog at protonmail dot com</tt></a>).</p> + +<h2><a name="description">Description</a></h2> + <h3><a name="Skew_Heap_Priority_Queue.">Skew Heap Priority Queue.</a></h3> + Ulf Wiger suggested pursuing a skew heap as an optimal Erlang priority + queue implementation. Unfortunately, testing has shown this solution to + be more than 2 times slower than pqueue. +<h2><a name="types">Data Types</a></h2> + +<h3 class="typedecl"><a name="type-pqueue2">pqueue2()</a></h3> +<p><tt>pqueue2() = empty | {integer(), <a href="#type-pqueue2">pqueue2()</a>, <a href="#type-pqueue2">pqueue2()</a>, element, term()} | {integer(), <a href="#type-pqueue2">pqueue2()</a>, <a href="#type-pqueue2">pqueue2()</a>, queue, <a href="queue.html#type-queue">queue:queue()</a>}</tt></p> + + +<h2><a name="index">Function Index</a></h2> +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#in-2">in/2</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#in-3">in/3</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#is_empty-1">is_empty/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#is_queue-1">is_queue/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#len-1">len/1</a></td><td> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#new-0">new/0</a></td><td> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#out-1">out/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#out-2">out/2</a></td><td> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#pout-1">pout/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value.</td></tr> +<tr><td valign="top"><a href="#test-0">test/0</a></td><td> + <h4><a name="Regression_test.">Regression test.</a></h4>.</td></tr> +<tr><td valign="top"><a href="#to_list-1">to_list/1</a></td><td> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4>.</td></tr> +</table> + +<h2><a name="functions">Function Details</a></h2> + +<h3 class="function"><a name="in-2">in/2</a></h3> +<div class="spec"> +<p><tt>in(Value::term(), H::<a href="#type-pqueue2">pqueue2()</a>) -> <a href="#type-pqueue2">pqueue2()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> +</p> + +<h3 class="function"><a name="in-3">in/3</a></h3> +<div class="spec"> +<p><tt>in(Value::term(), P::integer(), H::<a href="#type-pqueue2">pqueue2()</a>) -> <a href="#type-pqueue2">pqueue2()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> +</p> + +<h3 class="function"><a name="is_empty-1">is_empty/1</a></h3> +<div class="spec"> +<p><tt>is_empty(X1::<a href="#type-pqueue2">pqueue2()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> +</p> + +<h3 class="function"><a name="is_queue-1">is_queue/1</a></h3> +<div class="spec"> +<p><tt>is_queue(X1::<a href="#type-pqueue2">pqueue2()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> +</p> + +<h3 class="function"><a name="len-1">len/1</a></h3> +<div class="spec"> +<p><tt>len(H::<a href="#type-pqueue2">pqueue2()</a>) -> non_neg_integer()</tt><br></p> +</div><p> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> +</p> + +<h3 class="function"><a name="new-0">new/0</a></h3> +<div class="spec"> +<p><tt>new() -> <a href="#type-pqueue2">pqueue2()</a></tt><br></p> +</div><p> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> +</p> + +<h3 class="function"><a name="out-1">out/1</a></h3> +<div class="spec"> +<p><tt>out(X1::<a href="#type-pqueue2">pqueue2()</a>) -> {{value, term()}, <a href="#type-pqueue2">pqueue2()</a>} | {empty, <a href="#type-pqueue2">pqueue2()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> +</p> + +<h3 class="function"><a name="out-2">out/2</a></h3> +<div class="spec"> +<p><tt>out(P::integer(), H::<a href="#type-pqueue2">pqueue2()</a>) -> {{value, term()}, <a href="#type-pqueue2">pqueue2()</a>} | {empty, <a href="#type-pqueue2">pqueue2()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> +</p> + +<h3 class="function"><a name="pout-1">pout/1</a></h3> +<div class="spec"> +<p><tt>pout(X1::<a href="#type-pqueue2">pqueue2()</a>) -> {{value, term(), integer()}, <a href="#type-pqueue2">pqueue2()</a>} | {empty, <a href="#type-pqueue2">pqueue2()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value.</p> + +<h3 class="function"><a name="test-0">test/0</a></h3> +<div class="spec"> +<p><tt>test() -> any()</tt></p> +</div><p> + <h4><a name="Regression_test.">Regression test.</a></h4> +</p> + +<h3 class="function"><a name="to_list-1">to_list/1</a></h3> +<div class="spec"> +<p><tt>to_list(H::<a href="#type-pqueue2">pqueue2()</a>) -> [term()]</tt><br></p> +</div><p> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> +</p> +<hr> + +<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<p><i>Generated by EDoc</i></p> +</body> +</html> diff --git a/aoc2023/build/dev/erlang/pqueue/doc/pqueue3.html b/aoc2023/build/dev/erlang/pqueue/doc/pqueue3.html new file mode 100644 index 0000000..35f1a7b --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/pqueue3.html @@ -0,0 +1,162 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>Module pqueue3</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<hr> + +<h1>Module pqueue3</h1> +<ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul> + <h3><a name="A_Large_Priority_Queue.">A Large Priority Queue.</a></h3> + This priority queue implementation depends on layered tuples, so that tuple + access times can be exploited for quick in/out priority queue operations + when using 64 or more total priorities. +<p>Copyright © 2011-2020 Michael Truog</p> + +<p><b>Version:</b> 2.0.1 Nov 26 2020 14:55:32 + ------------------------------------------------------------------------</p> +<p><b>Authors:</b> Michael Truog (<a href="mailto:mjtruog at protonmail dot com"><tt>mjtruog at protonmail dot com</tt></a>).</p> + +<h2><a name="description">Description</a></h2> + <h3><a name="A_Large_Priority_Queue.">A Large Priority Queue.</a></h3> + This priority queue implementation depends on layered tuples, so that tuple + access times can be exploited for quick in/out priority queue operations + when using 64 or more total priorities. This implementation was created + to avoid the slowness within the priority queue used by + both RabbitMQ and Riak + (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +<h2><a name="types">Data Types</a></h2> + +<h3 class="typedecl"><a name="type-pqueue3">pqueue3()</a></h3> +<p><tt>pqueue3() = {integer(), integer(), empty | integer(), tuple()}</tt></p> + + +<h3 class="typedecl"><a name="type-pqueue3_empty">pqueue3_empty()</a></h3> +<p><tt>pqueue3_empty() = {integer(), integer(), empty, tuple()}</tt></p> + + +<h2><a name="index">Function Index</a></h2> +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#in-2">in/2</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#in-3">in/3</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_empty-1">is_empty/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_queue-1">is_queue/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#len-1">len/1</a></td><td> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#new-0">new/0</a></td><td> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#new-1">new/1</a></td><td> + <h4><a name="Create_a_new_priority_queue_with_customization_options.">Create a new priority queue with customization options.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#out-1">out/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#out-2">out/2</a></td><td> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#pout-1">pout/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value.</td></tr> +<tr><td valign="top"><a href="#to_list-1">to_list/1</a></td><td> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N).</td></tr> +</table> + +<h2><a name="functions">Function Details</a></h2> + +<h3 class="function"><a name="in-2">in/2</a></h3> +<div class="spec"> +<p><tt>in(Value::term(), Q::<a href="#type-pqueue3">pqueue3()</a>) -> <a href="#type-pqueue3">pqueue3()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="in-3">in/3</a></h3> +<div class="spec"> +<p><tt>in(Value::term(), P::integer(), X3::<a href="#type-pqueue3">pqueue3()</a>) -> <a href="#type-pqueue3">pqueue3()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_empty-1">is_empty/1</a></h3> +<div class="spec"> +<p><tt>is_empty(Q::<a href="#type-pqueue3">pqueue3()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_queue-1">is_queue/1</a></h3> +<div class="spec"> +<p><tt>is_queue(X1::<a href="#type-pqueue3">pqueue3()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1)</p> + +<h3 class="function"><a name="len-1">len/1</a></h3> +<div class="spec"> +<p><tt>len(Q::<a href="#type-pqueue3">pqueue3()</a>) -> non_neg_integer()</tt><br></p> +</div><p> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(N)</p> + +<h3 class="function"><a name="new-0">new/0</a></h3> +<div class="spec"> +<p><tt>new() -> <a href="#type-pqueue3_empty">pqueue3_empty()</a></tt><br></p> +</div><p> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="new-1">new/1</a></h3> +<div class="spec"> +<p><tt>new(Options::[{atom(), term()}]) -> <a href="#type-pqueue3">pqueue3()</a></tt><br></p> +</div><p> + <h4><a name="Create_a_new_priority_queue_with_customization_options.">Create a new priority queue with customization options.</a></h4> + O(1)</p> + +<h3 class="function"><a name="out-1">out/1</a></h3> +<div class="spec"> +<p><tt>out(Q::<a href="#type-pqueue3">pqueue3()</a>) -> {{value, term()}, <a href="#type-pqueue3">pqueue3()</a>} | {empty, <a href="#type-pqueue3">pqueue3()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="out-2">out/2</a></h3> +<div class="spec"> +<p><tt>out(P::integer(), Q::<a href="#type-pqueue3">pqueue3()</a>) -> {{value, term()}, <a href="#type-pqueue3">pqueue3()</a>} | {empty, <a href="#type-pqueue3">pqueue3()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="pout-1">pout/1</a></h3> +<div class="spec"> +<p><tt>pout(Q::<a href="#type-pqueue3">pqueue3()</a>) -> {{value, term(), integer()}, <a href="#type-pqueue3">pqueue3()</a>} | {empty, <a href="#type-pqueue3">pqueue3()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value. + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="to_list-1">to_list/1</a></h3> +<div class="spec"> +<p><tt>to_list(Q::<a href="#type-pqueue3">pqueue3()</a>) -> [term()]</tt><br></p> +</div><p> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N)</p> +<hr> + +<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<p><i>Generated by EDoc</i></p> +</body> +</html> diff --git a/aoc2023/build/dev/erlang/pqueue/doc/pqueue4.html b/aoc2023/build/dev/erlang/pqueue/doc/pqueue4.html new file mode 100644 index 0000000..edcdb6e --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/pqueue4.html @@ -0,0 +1,205 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>Module pqueue4</title> +<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc"> +</head> +<body bgcolor="white"> +<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<hr> + +<h1>Module pqueue4</h1> +<ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul> + <h3><a name="Static_Priority_Queue.">Static Priority Queue.</a></h3> + This priority queue implementation depends on a static number of priorities + (-128 (high) to 128 (low)) so that tuple access times can be exploited for + quick in/out priority queue operations. +<p>Copyright © 2011-2020 Michael Truog</p> + +<p><b>Version:</b> 2.0.1 Nov 26 2020 14:55:34 + ------------------------------------------------------------------------</p> +<p><b>Authors:</b> Michael Truog (<a href="mailto:mjtruog at protonmail dot com"><tt>mjtruog at protonmail dot com</tt></a>).</p> + +<h2><a name="description">Description</a></h2> + <h3><a name="Static_Priority_Queue.">Static Priority Queue.</a></h3> + This priority queue implementation depends on a static number of priorities + (-128 (high) to 128 (low)) so that tuple access times can be exploited for + quick in/out priority queue operations. This implementation was created to + avoid the slowness within the priority queue used by both RabbitMQ and Riak + (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +<h2><a name="types">Data Types</a></h2> + +<h3 class="typedecl"><a name="type-pqueue4">pqueue4()</a></h3> +<p><tt>pqueue4() = <a href="#type-pqueue4">pqueue4</a>(any())</tt></p> + + +<h3 class="typedecl"><a name="type-pqueue4">pqueue4()</a></h3> +<p><tt>pqueue4(T) = {<a href="#type-priority">priority()</a> | empty, non_neg_integer(), {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, <a href="queue.html#type-queue">queue:queue</a>(T), {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}, {<a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T), <a href="queue.html#type-queue">queue:queue</a>(T)}}</tt></p> + + +<h3 class="typedecl"><a name="type-priority">priority()</a></h3> +<p><tt>priority() = -128..128</tt></p> + + +<h2><a name="index">Function Index</a></h2> +<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#filter-2">filter/2</a></td><td> + <h4><a name="Filter_the_priority_queue.">Filter the priority queue.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#filter-3">filter/3</a></td><td> + <h4><a name="Filter_a_specific_priority_within_the_priority_queue.">Filter a specific priority within the priority queue.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#in-2">in/2</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#in-3">in/3</a></td><td> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_empty-1">is_empty/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#is_queue-1">is_queue/1</a></td><td> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#len-1">len/1</a></td><td> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#new-0">new/0</a></td><td> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1).</td></tr> +<tr><td valign="top"><a href="#out-1">out/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#out-2">out/2</a></td><td> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case.</td></tr> +<tr><td valign="top"><a href="#pout-1">pout/1</a></td><td> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value.</td></tr> +<tr><td valign="top"><a href="#remove_unique-2">remove_unique/2</a></td><td> + <h4><a name="Remove_a_unique_value_from_the_priority_queue_with_a_binary_predicate.">Remove a unique value from the priority queue with a binary predicate.</a></h4> + O(N) but smaller constant than filter/2.</td></tr> +<tr><td valign="top"><a href="#remove_unique-3">remove_unique/3</a></td><td> + <h4><a name="Remove_a_unique_value_in_a_specific_priority_within_the_priority_queue_with_a_binary_predicate.">Remove a unique value in a specific priority within the priority queue with a binary predicate.</a></h4> + O(N) but smaller constant than filter/3.</td></tr> +<tr><td valign="top"><a href="#to_list-1">to_list/1</a></td><td> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N).</td></tr> +<tr><td valign="top"><a href="#to_plist-1">to_plist/1</a></td><td> + <h4><a name="Convert_the_priority_queue_to_a_list_with_priorities.">Convert the priority queue to a list with priorities.</a></h4> + O(N).</td></tr> +</table> + +<h2><a name="functions">Function Details</a></h2> + +<h3 class="function"><a name="filter-2">filter/2</a></h3> +<div class="spec"> +<p><tt>filter(F::fun((any()) -> boolean()), Q::<a href="#type-pqueue4">pqueue4()</a>) -> <a href="#type-pqueue4">pqueue4()</a></tt><br></p> +</div><p> + <h4><a name="Filter_the_priority_queue.">Filter the priority queue.</a></h4> + O(N)</p> + +<h3 class="function"><a name="filter-3">filter/3</a></h3> +<div class="spec"> +<p><tt>filter(F::fun((any()) -> boolean()), P::integer(), Q::<a href="#type-pqueue4">pqueue4()</a>) -> <a href="#type-pqueue4">pqueue4()</a></tt><br></p> +</div><p> + <h4><a name="Filter_a_specific_priority_within_the_priority_queue.">Filter a specific priority within the priority queue.</a></h4> + O(N)</p> + +<h3 class="function"><a name="in-2">in/2</a></h3> +<div class="spec"> +<p><tt>in(X::any(), Q::<a href="#type-pqueue4">pqueue4()</a>) -> <a href="#type-pqueue4">pqueue4()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_the_0_priority_queue.">Append an item to the tail of the 0 priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="in-3">in/3</a></h3> +<div class="spec"> +<p><tt>in(X::any(), P::integer(), Q::<a href="#type-pqueue4">pqueue4()</a>) -> <a href="#type-pqueue4">pqueue4()</a></tt><br></p> +</div><p> + <h4><a name="Append_an_item_to_the_tail_of_a_specific_priority_queue.">Append an item to the tail of a specific priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_empty-1">is_empty/1</a></h3> +<div class="spec"> +<p><tt>is_empty(X1::<a href="#type-pqueue4">pqueue4()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_is_empty.">Check if the priority queue is empty.</a></h4> + O(1)</p> + +<h3 class="function"><a name="is_queue-1">is_queue/1</a></h3> +<div class="spec"> +<p><tt>is_queue(X1::<a href="#type-pqueue4">pqueue4()</a>) -> true | false</tt><br></p> +</div><p> + <h4><a name="Check_if_the_priority_queue_type_is_as_expected.">Check if the priority queue type is as expected.</a></h4> + O(1)</p> + +<h3 class="function"><a name="len-1">len/1</a></h3> +<div class="spec"> +<p><tt>len(X1::<a href="#type-pqueue4">pqueue4()</a>) -> non_neg_integer()</tt><br></p> +</div><p> + <h4><a name="Determine_the_length_of_a_priority_queue.">Determine the length of a priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="new-0">new/0</a></h3> +<div class="spec"> +<p><tt>new() -> <a href="#type-pqueue4">pqueue4()</a></tt><br></p> +</div><p> + <h4><a name="Create_a_new_priority_queue.">Create a new priority queue.</a></h4> + O(1)</p> + +<h3 class="function"><a name="out-1">out/1</a></h3> +<div class="spec"> +<p><tt>out(Q::<a href="#type-pqueue4">pqueue4()</a>) -> {{value, any()}, <a href="#type-pqueue4">pqueue4()</a>} | {empty, <a href="#type-pqueue4">pqueue4()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="out-2">out/2</a></h3> +<div class="spec"> +<p><tt>out(P::integer(), Q::<a href="#type-pqueue4">pqueue4()</a>) -> {{value, any()}, <a href="#type-pqueue4">pqueue4()</a>} | {empty, <a href="#type-pqueue4">pqueue4()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_of_a_specific_priority_from_the_head_of_the_queue.">Take an item of a specific priority from the head of the queue.</a></h4> + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="pout-1">pout/1</a></h3> +<div class="spec"> +<p><tt>pout(Q::<a href="#type-pqueue4">pqueue4()</a>) -> {{value, any(), integer()}, <a href="#type-pqueue4">pqueue4()</a>} | {empty, <a href="#type-pqueue4">pqueue4()</a>}</tt><br></p> +</div><p> + <h4><a name="Take_an_item_from_the_head_of_the_priority_queue.">Take an item from the head of the priority queue.</a></h4> + Includes the priority in the return value. + O(1) amortized, O(N) worst case</p> + +<h3 class="function"><a name="remove_unique-2">remove_unique/2</a></h3> +<div class="spec"> +<p><tt>remove_unique(F::fun((any()) -> boolean()), Q::<a href="#type-pqueue4">pqueue4()</a>) -> {boolean(), <a href="#type-pqueue4">pqueue4()</a>}</tt><br></p> +</div><p> + <h4><a name="Remove_a_unique_value_from_the_priority_queue_with_a_binary_predicate.">Remove a unique value from the priority queue with a binary predicate.</a></h4> + O(N) but smaller constant than filter/2</p> + +<h3 class="function"><a name="remove_unique-3">remove_unique/3</a></h3> +<div class="spec"> +<p><tt>remove_unique(F::fun((any()) -> boolean()), P::integer(), Q::<a href="#type-pqueue4">pqueue4()</a>) -> {boolean(), <a href="#type-pqueue4">pqueue4()</a>}</tt><br></p> +</div><p> + <h4><a name="Remove_a_unique_value_in_a_specific_priority_within_the_priority_queue_with_a_binary_predicate.">Remove a unique value in a specific priority within the priority queue with a binary predicate.</a></h4> + O(N) but smaller constant than filter/3</p> + +<h3 class="function"><a name="to_list-1">to_list/1</a></h3> +<div class="spec"> +<p><tt>to_list(Q::<a href="#type-pqueue4">pqueue4()</a>) -> list()</tt><br></p> +</div><p> + <h4><a name="Convert_the_priority_queue_to_a_list.">Convert the priority queue to a list.</a></h4> + O(N)</p> + +<h3 class="function"><a name="to_plist-1">to_plist/1</a></h3> +<div class="spec"> +<p><tt>to_plist(Q::<a href="#type-pqueue4">pqueue4()</a>) -> [{<a href="#type-priority">priority()</a>, list()}]</tt><br></p> +</div><p> + <h4><a name="Convert_the_priority_queue_to_a_list_with_priorities.">Convert the priority queue to a list with priorities.</a></h4> + O(N)</p> +<hr> + +<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div> +<p><i>Generated by EDoc</i></p> +</body> +</html> diff --git a/aoc2023/build/dev/erlang/pqueue/doc/stylesheet.css b/aoc2023/build/dev/erlang/pqueue/doc/stylesheet.css new file mode 100644 index 0000000..ab170c0 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/doc/stylesheet.css @@ -0,0 +1,55 @@ +/* standard EDoc style sheet */ +body { + font-family: Verdana, Arial, Helvetica, sans-serif; + margin-left: .25in; + margin-right: .2in; + margin-top: 0.2in; + margin-bottom: 0.2in; + color: #000000; + background-color: #ffffff; +} +h1,h2 { + margin-left: -0.2in; +} +div.navbar { + background-color: #add8e6; + padding: 0.2em; +} +h2.indextitle { + padding: 0.4em; + background-color: #add8e6; +} +h3.function,h3.typedecl { + background-color: #add8e6; + padding-left: 1em; +} +div.spec { + margin-left: 2em; + background-color: #eeeeee; +} +a.module { + text-decoration:none +} +a.module:hover { + background-color: #eeeeee; +} +ul.definitions { + list-style-type: none; +} +ul.index { + list-style-type: none; + background-color: #eeeeee; +} + +/* + * Minor style tweaks + */ +ul { + list-style-type: square; +} +table { + border-collapse: collapse; +} +td { + padding: 3 +} diff --git a/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.app b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.app new file mode 100644 index 0000000..974098f --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.app @@ -0,0 +1,6 @@ +{application,pqueue, + [{description,"Priority Queue Data Structures"}, + {vsn,"2.0.7"}, + {modules,[pqueue,pqueue2,pqueue3,pqueue4]}, + {registered,[]}, + {applications,[stdlib,kernel]}]}. diff --git a/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.beam b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.beam Binary files differnew file mode 100644 index 0000000..218d67e --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue.beam diff --git a/aoc2023/build/dev/erlang/pqueue/ebin/pqueue2.beam b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue2.beam Binary files differnew file mode 100644 index 0000000..597dc12 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue2.beam diff --git a/aoc2023/build/dev/erlang/pqueue/ebin/pqueue3.beam b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue3.beam Binary files differnew file mode 100644 index 0000000..ecf341a --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue3.beam diff --git a/aoc2023/build/dev/erlang/pqueue/ebin/pqueue4.beam b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue4.beam Binary files differnew file mode 100644 index 0000000..8e575fc --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/ebin/pqueue4.beam diff --git a/aoc2023/build/dev/erlang/pqueue/rebar.config b/aoc2023/build/dev/erlang/pqueue/rebar.config new file mode 100644 index 0000000..f8022f0 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/rebar.config @@ -0,0 +1,14 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: + +{erl_opts, + [{platform_define, "^R16", 'ERLANG_OTP_VERSION_16'}, + {platform_define, "^17\.", 'ERLANG_OTP_VERSION_17'}, + {platform_define, "^18\.", 'ERLANG_OTP_VERSION_18'}, + {platform_define, "^19\.", 'ERLANG_OTP_VERSION_19'}, + {platform_define, "^20\.", 'ERLANG_OTP_VERSION_20'}, + warn_export_vars, + warn_unused_import, + %warn_missing_spec, + warnings_as_errors]}. +{edoc_opts, [{preprocess, true}]}. diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue.app.src b/aoc2023/build/dev/erlang/pqueue/src/pqueue.app.src new file mode 100644 index 0000000..b153ad1 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue.app.src @@ -0,0 +1,10 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: + +{application, pqueue, + [{description, "Priority Queue Data Structures"}, + {vsn, "2.0.7"}, + {modules, [pqueue, pqueue2, pqueue3, pqueue4]}, + {registered, []}, + {applications, [stdlib, kernel]}]}. + diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue.erl b/aoc2023/build/dev/erlang/pqueue/src/pqueue.erl new file mode 100644 index 0000000..2c57fa2 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue.erl @@ -0,0 +1,2246 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: +%%% +%%%------------------------------------------------------------------------ +%%% @doc +%%% ==Static Priority Queue.== +%%% This priority queue implementation depends on a static number of priorities +%%% (-20 (high) to 20 (low)) so that tuple access times can be exploited for +%%% quick in/out priority queue operations. This implementation was created to +%%% avoid the slowness within the priority queue used by both RabbitMQ and Riak +%%% (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +%%% @end +%%% +%%% MIT License +%%% +%%% Copyright (c) 2011-2020 Michael Truog <mjtruog at protonmail dot com> +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a +%%% copy of this software and associated documentation files (the "Software"), +%%% to deal in the Software without restriction, including without limitation +%%% the rights to use, copy, modify, merge, publish, distribute, sublicense, +%%% and/or sell copies of the Software, and to permit persons to whom the +%%% Software is furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in +%%% all copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +%%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +%%% DEALINGS IN THE SOFTWARE. +%%% +%%% @author Michael Truog <mjtruog at protonmail dot com> +%%% @copyright 2011-2020 Michael Truog +%%% @version 2.0.1 {@date} {@time} +%%%------------------------------------------------------------------------ + +-module(pqueue). +-author('mjtruog at protonmail dot com'). + +%% external interface +-export([in/2, % O(1) + in/3, % O(1) + is_empty/1, % O(1) + is_queue/1, % O(1) + join/2, % O(N) typically (?) + len/1, % O(N) + new/0, % O(1) + out/1, % O(1) amortized, O(N) worst case + out/2, % O(1) amortized, O(N) worst case + pout/1, % O(1) amortized, O(N) worst case + to_list/1, % O(N) + test/0]). + +%%%------------------------------------------------------------------------ +%%% External interface functions +%%%------------------------------------------------------------------------ + +-ifdef(ERLANG_OTP_VERSION_16). +-type pqueue() :: + {integer(), + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue()}, + queue(), + {queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}} | + {'empty', + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue()}, + queue(), + {queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue()}}. +-else. +-type pqueue() :: + {integer(), + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue()}, + queue:queue(), + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}} | + {'empty', + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue()}, + queue:queue(), + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}, + {queue:queue(), queue:queue(), queue:queue(), queue:queue(), + queue:queue(), queue:queue(), queue:queue()}}. +-endif. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of the 0 priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), pqueue()) -> pqueue(). + +in(X, Q) -> + in(X, 0, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of a specific priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), integer(), pqueue()) -> pqueue(). + +in(_, P, _) + when P < -20; P > 20 -> + erlang:exit(badarg); +in(X, P, {empty, _, _, _, _, _, _, _} = Q) -> + in_higher(P, Q, X); +in(X, P, {Pc, _, _, _, _, _, _, _} = Q) + when P < Pc -> + in_higher(P, Q, X); +in(X, P, Q) -> + in_lower(P, Q, X). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue is empty.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_empty(pqueue()) -> 'true' | 'false'. + +is_empty({empty, _, _, _, _, _, _, _}) -> + true; +is_empty({_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + queue:is_empty(Qn20) and queue:is_empty(Qn19) and queue:is_empty(Qn18) and + queue:is_empty(Qn17) and queue:is_empty(Qn16) and queue:is_empty(Qn15) and + queue:is_empty(Qn14) and + queue:is_empty(Qn13) and queue:is_empty(Qn12) and queue:is_empty(Qn11) and + queue:is_empty(Qn10) and queue:is_empty(Qn9) and queue:is_empty(Qn8) and + queue:is_empty(Qn7) and + queue:is_empty(Qn6) and queue:is_empty(Qn5) and queue:is_empty(Qn4) and + queue:is_empty(Qn3) and queue:is_empty(Qn2) and queue:is_empty(Qn1) and + queue:is_empty(Q0) and + queue:is_empty(Qp1) and queue:is_empty(Qp2) and queue:is_empty(Qp3) and + queue:is_empty(Qp4) and queue:is_empty(Qp5) and queue:is_empty(Qp6) and + queue:is_empty(Qp7) and queue:is_empty(Qp8) and queue:is_empty(Qp9) and + queue:is_empty(Qp10) and queue:is_empty(Qp11) and queue:is_empty(Qp12) and + queue:is_empty(Qp13) and + queue:is_empty(Qp14) and queue:is_empty(Qp15) and queue:is_empty(Qp16) and + queue:is_empty(Qp17) and queue:is_empty(Qp18) and queue:is_empty(Qp19) and + queue:is_empty(Qp20). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue type is as expected.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_queue(pqueue()) -> 'true' | 'false'. + +is_queue({Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) + when tuple_size(Qsn14) == 7, tuple_size(Qsn7) == 7, tuple_size(Qsn1) == 6, + tuple_size(Qsp14) == 7, tuple_size(Qsp7) == 7, tuple_size(Qsp1) == 6 -> + (((Pc =:= empty) or is_integer(Pc)) and queue:is_queue(Q0)); +is_queue(_) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Join two priority queues.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec join(pqueue(), pqueue()) -> pqueue(). + +join({P1c, + {Q1_n20, Q1_n19, Q1_n18, Q1_n17, Q1_n16, Q1_n15, Q1_n14}, + {Q1_n13, Q1_n12, Q1_n11, Q1_n10, Q1_n9, Q1_n8, Q1_n7}, + {Q1_n6, Q1_n5, Q1_n4, Q1_n3, Q1_n2, Q1_n1}, + Q1_0, + {Q1_p1, Q1_p2, Q1_p3, Q1_p4, Q1_p5, Q1_p6}, + {Q1_p7, Q1_p8, Q1_p9, Q1_p10, Q1_p11, Q1_p12, Q1_p13}, + {Q1_p14, Q1_p15, Q1_p16, Q1_p17, Q1_p18, Q1_p19, Q1_p20}}, + {P2c, + {Q2_n20, Q2_n19, Q2_n18, Q2_n17, Q2_n16, Q2_n15, Q2_n14}, + {Q2_n13, Q2_n12, Q2_n11, Q2_n10, Q2_n9, Q2_n8, Q2_n7}, + {Q2_n6, Q2_n5, Q2_n4, Q2_n3, Q2_n2, Q2_n1}, + Q2_0, + {Q2_p1, Q2_p2, Q2_p3, Q2_p4, Q2_p5, Q2_p6}, + {Q2_p7, Q2_p8, Q2_p9, Q2_p10, Q2_p11, Q2_p12, Q2_p13}, + {Q2_p14, Q2_p15, Q2_p16, Q2_p17, Q2_p18, Q2_p19, Q2_p20}}) -> + {erlang:min(P1c, P2c), + {queue:join(Q1_n20, Q2_n20), queue:join(Q1_n19, Q2_n19), + queue:join(Q1_n18, Q2_n18), queue:join(Q1_n17, Q2_n17), + queue:join(Q1_n16, Q2_n16), queue:join(Q1_n15, Q2_n15), + queue:join(Q1_n14, Q2_n14)}, + {queue:join(Q1_n13, Q2_n13), queue:join(Q1_n12, Q2_n12), + queue:join(Q1_n11, Q2_n11), queue:join(Q1_n10, Q2_n10), + queue:join(Q1_n9, Q2_n9), queue:join(Q1_n8, Q2_n8), + queue:join(Q1_n7, Q2_n7)}, + {queue:join(Q1_n6, Q2_n6), queue:join(Q1_n5, Q2_n5), + queue:join(Q1_n4, Q2_n4), queue:join(Q1_n3, Q2_n3), + queue:join(Q1_n2, Q2_n2), queue:join(Q1_n1, Q2_n1)}, + queue:join(Q1_0, Q2_0), + {queue:join(Q1_p1, Q2_p1), queue:join(Q1_p2, Q2_p2), + queue:join(Q1_p3, Q2_p3), queue:join(Q1_p4, Q2_p4), + queue:join(Q1_p5, Q2_p5), queue:join(Q1_p6, Q2_p6)}, + {queue:join(Q1_p7, Q2_p7), queue:join(Q1_p8, Q2_p8), + queue:join(Q1_p9, Q2_p9), queue:join(Q1_p10, Q2_p10), + queue:join(Q1_p11, Q2_p11), queue:join(Q1_p12, Q2_p12), + queue:join(Q1_p13, Q2_p13)}, + {queue:join(Q1_p14, Q2_p14), queue:join(Q1_p15, Q2_p15), + queue:join(Q1_p16, Q2_p16), queue:join(Q1_p17, Q2_p17), + queue:join(Q1_p18, Q2_p18), queue:join(Q1_p19, Q2_p19), + queue:join(Q1_p20, Q2_p20)}}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Determine the length of a priority queue.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec len(pqueue()) -> non_neg_integer(). + +len({_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + queue:len(Qn20) + queue:len(Qn19) + queue:len(Qn18) + queue:len(Qn17) + + queue:len(Qn16) + queue:len(Qn15) + queue:len(Qn14) + + queue:len(Qn13) + queue:len(Qn12) + queue:len(Qn11) + queue:len(Qn10) + + queue:len(Qn9) + queue:len(Qn8) + queue:len(Qn7) + + queue:len(Qn6) + queue:len(Qn5) + queue:len(Qn4) + queue:len(Qn3) + + queue:len(Qn2) + queue:len(Qn1) + + queue:len(Q0) + + queue:len(Qp1) + queue:len(Qp2) + queue:len(Qp3) + queue:len(Qp4) + + queue:len(Qp5) + queue:len(Qp6) + + queue:len(Qp7) + queue:len(Qp8) + queue:len(Qp9) + queue:len(Qp10) + + queue:len(Qp11) + queue:len(Qp12) + queue:len(Qp13) + + queue:len(Qp14) + queue:len(Qp15) + queue:len(Qp16) + queue:len(Qp17) + + queue:len(Qp18) + queue:len(Qp19) + queue:len(Qp20). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Create a new priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec new() -> pqueue(). + +new() -> + {empty, % current priority + erlang:make_tuple(7, queue:new()), % priority [-20..-14] + erlang:make_tuple(7, queue:new()), % priority [-13.. -7] + erlang:make_tuple(6, queue:new()), % priority [ -6.. -1] + queue:new(), % priority 0 (default) + erlang:make_tuple(6, queue:new()), % priority [ 1.. 6] + erlang:make_tuple(7, queue:new()), % priority [ 7.. 13] + erlang:make_tuple(7, queue:new())}. % priority [ 14.. 20] + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(pqueue()) -> + {{'value', term()}, pqueue()} | {'empty', pqueue()}. + +out({empty, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +out({Pc, _, _, _, _, _, _, _} = Q) -> + out_current(Pc, Q, nopriority). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item of a specific priority from the head of the queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(integer(), pqueue()) -> + {{'value', term()}, pqueue()} | {'empty', pqueue()}. + +out(P, _) + when P < -20; P > 20 -> + erlang:exit(badarg); +out(_, {empty, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +out(P, Q) -> + out_specific(P, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% Includes the priority in the return value. +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec pout(pqueue()) -> + {{'value', term(), integer()}, pqueue()} | {'empty', pqueue()}. + +pout({empty, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +pout({Pc, _, _, _, _, _, _, _} = Q) -> + out_current(Pc, Q, priority). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Convert the priority queue to a list.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec to_list(pqueue()) -> list(term()). + +to_list({_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + queue:to_list(Qn20) ++ queue:to_list(Qn19) ++ queue:to_list(Qn18) ++ + queue:to_list(Qn17) ++ queue:to_list(Qn16) ++ queue:to_list(Qn15) ++ + queue:to_list(Qn14) ++ + queue:to_list(Qn13) ++ queue:to_list(Qn12) ++ queue:to_list(Qn11) ++ + queue:to_list(Qn10) ++ queue:to_list(Qn9) ++ queue:to_list(Qn8) ++ + queue:to_list(Qn7) ++ + queue:to_list(Qn6) ++ queue:to_list(Qn5) ++ queue:to_list(Qn4) ++ + queue:to_list(Qn3) ++ queue:to_list(Qn2) ++ queue:to_list(Qn1) ++ + queue:to_list(Q0) ++ + queue:to_list(Qp1) ++ queue:to_list(Qp2) ++ queue:to_list(Qp3) ++ + queue:to_list(Qp4) ++ queue:to_list(Qp5) ++ queue:to_list(Qp6) ++ + queue:to_list(Qp7) ++ queue:to_list(Qp8) ++ queue:to_list(Qp9) ++ + queue:to_list(Qp10) ++ queue:to_list(Qp11) ++ queue:to_list(Qp12) ++ + queue:to_list(Qp13) ++ + queue:to_list(Qp14) ++ queue:to_list(Qp15) ++ queue:to_list(Qp16) ++ + queue:to_list(Qp17) ++ queue:to_list(Qp18) ++ queue:to_list(Qp19) ++ + queue:to_list(Qp20). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Regression test.=== +%% @end +%%------------------------------------------------------------------------- + +test() -> + Q0 = pqueue:new(), + true = pqueue:is_queue(Q0), + Q1 = pqueue:in(20, 20, Q0), + Q2 = pqueue:in(19, 19, Q1), + Q3 = pqueue:in(18, 18, Q2), + Q4 = pqueue:in(17, 17, Q3), + Q5 = pqueue:in(16, 16, Q4), + Q6 = pqueue:in(15, 15, Q5), + Q7 = pqueue:in(14, 14, Q6), + Q8 = pqueue:in(13, 13, Q7), + Q9 = pqueue:in(12, 12, Q8), + Q10 = pqueue:in(11, 11, Q9), + Q11 = pqueue:in(10, 10, Q10), + Q12 = pqueue:in(9, 9, Q11), + Q13 = pqueue:in(8, 8, Q12), + Q14 = pqueue:in(7, 7, Q13), + Q15 = pqueue:in(6, 6, Q14), + Q16 = pqueue:in(5, 5, Q15), + Q17 = pqueue:in(4, 4, Q16), + Q18 = pqueue:in(3, 3, Q17), + Q19 = pqueue:in(2, 2, Q18), + Q20 = pqueue:in(1, 1, Q19), + Q21 = pqueue:in(0, 0, Q20), + Q22 = pqueue:in(-1, -1, Q21), + Q23 = pqueue:in(-2, -2, Q22), + Q24 = pqueue:in(-3, -3, Q23), + Q25 = pqueue:in(-4, -4, Q24), + Q26 = pqueue:in(-5, -5, Q25), + Q27 = pqueue:in(-6, -6, Q26), + Q28 = pqueue:in(-7, -7, Q27), + Q29 = pqueue:in(-8, -8, Q28), + Q30 = pqueue:in(-9, -9, Q29), + Q31 = pqueue:in(-10, -10, Q30), + Q32 = pqueue:in(-11, -11, Q31), + Q33 = pqueue:in(-12, -12, Q32), + Q34 = pqueue:in(-13, -13, Q33), + Q35 = pqueue:in(-14, -14, Q34), + Q36 = pqueue:in(-15, -15, Q35), + Q37 = pqueue:in(-16, -16, Q36), + Q38 = pqueue:in(-17, -17, Q37), + Q39 = pqueue:in(-18, -18, Q38), + Q40 = pqueue:in(-19, -19, Q39), + Q41 = pqueue:in(-20, -20, Q40), + Q42 = pqueue:in(-20, -20, Q41), + Q43 = pqueue:in(-19, -19, Q42), + Q44 = pqueue:in(-18, -18, Q43), + Q45 = pqueue:in(-17, -17, Q44), + Q46 = pqueue:in(-16, -16, Q45), + Q47 = pqueue:in(-15, -15, Q46), + Q48 = pqueue:in(-14, -14, Q47), + Q49 = pqueue:in(-13, -13, Q48), + Q50 = pqueue:in(-12, -12, Q49), + Q51 = pqueue:in(-11, -11, Q50), + Q52 = pqueue:in(-10, -10, Q51), + Q53 = pqueue:in(-9, -9, Q52), + Q54 = pqueue:in(-8, -8, Q53), + Q55 = pqueue:in(-7, -7, Q54), + Q56 = pqueue:in(-6, -6, Q55), + Q57 = pqueue:in(-5, -5, Q56), + Q58 = pqueue:in(-4, -4, Q57), + Q59 = pqueue:in(-3, -3, Q58), + Q60 = pqueue:in(-2, -2, Q59), + Q61 = pqueue:in(-1, -1, Q60), + Q62 = pqueue:in(0, 0, Q61), + Q63 = pqueue:in(1, 1, Q62), + Q64 = pqueue:in(2, 2, Q63), + Q65 = pqueue:in(3, 3, Q64), + Q66 = pqueue:in(4, 4, Q65), + Q67 = pqueue:in(5, 5, Q66), + Q68 = pqueue:in(6, 6, Q67), + Q69 = pqueue:in(7, 7, Q68), + Q70 = pqueue:in(8, 8, Q69), + Q71 = pqueue:in(9, 9, Q70), + Q72 = pqueue:in(10, 10, Q71), + Q73 = pqueue:in(11, 11, Q72), + Q74 = pqueue:in(12, 12, Q73), + Q75 = pqueue:in(13, 13, Q74), + Q76 = pqueue:in(14, 14, Q75), + Q77 = pqueue:in(15, 15, Q76), + Q78 = pqueue:in(16, 16, Q77), + Q79 = pqueue:in(17, 17, Q78), + Q80 = pqueue:in(18, 18, Q79), + Q81 = pqueue:in(19, 19, Q80), + Q82 = pqueue:in(20, 20, Q81), + true = pqueue:is_queue(Q82), + 82 = pqueue:len(Q82), + [-20, -20, -19, -19, -18, -18, -17, -17, -16, -16, -15, -15, -14, -14, + -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -7, -7, -6, -6, + -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20] = pqueue:to_list(Q82), + {{value, -20}, Q83} = pqueue:out(Q82), + {{value, -20}, Q84} = pqueue:out(Q83), + {{value, -19}, Q85} = pqueue:out(Q84), + {{value, -19}, Q86} = pqueue:out(Q85), + {{value, -18}, Q87} = pqueue:out(Q86), + {{value, -18}, Q88} = pqueue:out(Q87), + {{value, 0}, Q89} = pqueue:out(0, Q88), + {{value, 0}, Q90} = pqueue:out(0, Q89), + {empty, _} = pqueue:out(0, Q90), + {{value, -17, -17}, Q91} = pqueue:pout(Q90), + {{value, -17, -17}, Q92} = pqueue:pout(Q91), + {{value, -16, -16}, Q93} = pqueue:pout(Q92), + {{value, -16, -16}, Q94} = pqueue:pout(Q93), + {{value, -15, -15}, Q95} = pqueue:pout(Q94), + {{value, -15, -15}, Q96} = pqueue:pout(Q95), + {{value, -14, -14}, Q97} = pqueue:pout(Q96), + {{value, -14, -14}, Q98} = pqueue:pout(Q97), + {{value, -13, -13}, Q99} = pqueue:pout(Q98), + {{value, -13, -13}, Q100} = pqueue:pout(Q99), + {{value, -12, -12}, Q101} = pqueue:pout(Q100), + {{value, -12, -12}, Q102} = pqueue:pout(Q101), + {{value, -11, -11}, Q103} = pqueue:pout(Q102), + {{value, -11, -11}, Q104} = pqueue:pout(Q103), + {{value, -10, -10}, Q105} = pqueue:pout(Q104), + {{value, -10, -10}, Q106} = pqueue:pout(Q105), + {{value, -9, -9}, Q107} = pqueue:pout(Q106), + {{value, -9, -9}, Q108} = pqueue:pout(Q107), + {{value, -8, -8}, Q109} = pqueue:pout(Q108), + {{value, -8, -8}, Q110} = pqueue:pout(Q109), + {{value, -7, -7}, Q111} = pqueue:pout(Q110), + {{value, -7, -7}, Q112} = pqueue:pout(Q111), + {{value, -6, -6}, Q113} = pqueue:pout(Q112), + {{value, -6, -6}, Q114} = pqueue:pout(Q113), + {{value, -5, -5}, Q115} = pqueue:pout(Q114), + {{value, -5, -5}, Q116} = pqueue:pout(Q115), + {{value, -4, -4}, Q117} = pqueue:pout(Q116), + {{value, -4, -4}, Q118} = pqueue:pout(Q117), + {{value, -3, -3}, Q119} = pqueue:pout(Q118), + {{value, -3, -3}, Q120} = pqueue:pout(Q119), + {{value, -2, -2}, Q121} = pqueue:pout(Q120), + {{value, -2, -2}, Q122} = pqueue:pout(Q121), + {{value, -1, -1}, Q123} = pqueue:pout(Q122), + {{value, -1, -1}, Q124} = pqueue:pout(Q123), + {{value, 1, 1}, Q125} = pqueue:pout(Q124), + {{value, 1, 1}, Q126} = pqueue:pout(Q125), + {{value, 2, 2}, Q127} = pqueue:pout(Q126), + {{value, 2, 2}, Q128} = pqueue:pout(Q127), + {{value, 3, 3}, Q129} = pqueue:pout(Q128), + {{value, 3, 3}, Q130} = pqueue:pout(Q129), + {{value, 4, 4}, Q131} = pqueue:pout(Q130), + {{value, 4, 4}, Q132} = pqueue:pout(Q131), + {{value, 5, 5}, Q133} = pqueue:pout(Q132), + {{value, 5, 5}, Q134} = pqueue:pout(Q133), + {{value, 6, 6}, Q135} = pqueue:pout(Q134), + {{value, 6, 6}, Q136} = pqueue:pout(Q135), + {{value, 7, 7}, Q137} = pqueue:pout(Q136), + {{value, 7, 7}, Q138} = pqueue:pout(Q137), + {{value, 8, 8}, Q139} = pqueue:pout(Q138), + {{value, 8, 8}, Q140} = pqueue:pout(Q139), + {{value, 9, 9}, Q141} = pqueue:pout(Q140), + {{value, 9, 9}, Q142} = pqueue:pout(Q141), + {{value, 10, 10}, Q143} = pqueue:pout(Q142), + {{value, 10, 10}, Q144} = pqueue:pout(Q143), + {{value, 11, 11}, Q145} = pqueue:pout(Q144), + {{value, 11, 11}, Q146} = pqueue:pout(Q145), + {{value, 12, 12}, Q147} = pqueue:pout(Q146), + {{value, 12, 12}, Q148} = pqueue:pout(Q147), + {{value, 13, 13}, Q149} = pqueue:pout(Q148), + {{value, 13, 13}, Q150} = pqueue:pout(Q149), + {{value, 14, 14}, Q151} = pqueue:pout(Q150), + {{value, 14, 14}, Q152} = pqueue:pout(Q151), + {{value, 15, 15}, Q153} = pqueue:pout(Q152), + {{value, 15, 15}, Q154} = pqueue:pout(Q153), + {{value, 16, 16}, Q155} = pqueue:pout(Q154), + {{value, 16, 16}, Q156} = pqueue:pout(Q155), + {{value, 17, 17}, Q157} = pqueue:pout(Q156), + {{value, 17, 17}, Q158} = pqueue:pout(Q157), + {{value, 18, 18}, Q159} = pqueue:pout(Q158), + {{value, 18, 18}, Q160} = pqueue:pout(Q159), + {{value, 19, 19}, Q161} = pqueue:pout(Q160), + {{value, 19, 19}, Q162} = pqueue:pout(Q161), + {{value, 20, 20}, Q163} = pqueue:pout(Q162), + {{value, 20, 20}, Q164} = pqueue:pout(Q163), + true = pqueue:is_empty(Q164), + {empty, Q165} = pqueue:pout(Q164), + true = pqueue:is_empty(Q165), + ok. + +%%%------------------------------------------------------------------------ +%%% Private functions +%%%------------------------------------------------------------------------ + +in_higher(-20, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-20, + {queue:in(X, Qn20), Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-19, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-19, + {Qn20, queue:in(X, Qn19), Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-18, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-18, + {Qn20, Qn19, queue:in(X, Qn18), Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-17, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-17, + {Qn20, Qn19, Qn18, queue:in(X, Qn17), Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-16, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-16, + {Qn20, Qn19, Qn18, Qn17, queue:in(X, Qn16), Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-15, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-15, + {Qn20, Qn19, Qn18, Qn17, Qn16, queue:in(X, Qn15), Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-14, {_, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-14, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, queue:in(X, Qn14)}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-13, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-13, Qsn14, + {queue:in(X, Qn13), Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-12, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-12, Qsn14, + {Qn13, queue:in(X, Qn12), Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-11, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-11, Qsn14, + {Qn13, Qn12, queue:in(X, Qn11), Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-10, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-10, Qsn14, + {Qn13, Qn12, Qn11, queue:in(X, Qn10), Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-9, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-9, Qsn14, + {Qn13, Qn12, Qn11, Qn10, queue:in(X, Qn9), Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-8, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-8, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, queue:in(X, Qn8), Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-7, {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-7, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, queue:in(X, Qn7)}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-6, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-6, Qsn14, Qsn7, + {queue:in(X, Qn6), Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-5, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-5, Qsn14, Qsn7, + {Qn6, queue:in(X, Qn5), Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-4, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-4, Qsn14, Qsn7, + {Qn6, Qn5, queue:in(X, Qn4), Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-3, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-3, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, queue:in(X, Qn3), Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-2, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-2, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, queue:in(X, Qn2), Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(-1, {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {-1, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, queue:in(X, Qn1)}, + Q0, Qsp1, Qsp7, Qsp14}; +in_higher(0, {_, Qsn14, Qsn7, Qsn1, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {0, Qsn14, Qsn7, Qsn1, + queue:in(X, Q0), + Qsp1, Qsp7, Qsp14}; +in_higher(1, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {1, Qsn14, Qsn7, Qsn1, Q0, + {queue:in(X, Qp1), Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_higher(2, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {2, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, queue:in(X, Qp2), Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_higher(3, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {3, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, queue:in(X, Qp3), Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_higher(4, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {4, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, queue:in(X, Qp4), Qp5, Qp6}, + Qsp7, Qsp14}; +in_higher(5, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {5, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, queue:in(X, Qp5), Qp6}, + Qsp7, Qsp14}; +in_higher(6, {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {6, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, queue:in(X, Qp6)}, + Qsp7, Qsp14}; +in_higher(7, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {7, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {queue:in(X, Qp7), Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_higher(8, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {8, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, queue:in(X, Qp8), Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_higher(9, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {9, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, queue:in(X, Qp9), Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_higher(10, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {10, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, queue:in(X, Qp10), Qp11, Qp12, Qp13}, + Qsp14}; +in_higher(11, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {11, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, queue:in(X, Qp11), Qp12, Qp13}, + Qsp14}; +in_higher(12, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {12, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, queue:in(X, Qp12), Qp13}, + Qsp14}; +in_higher(13, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {13, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, queue:in(X, Qp13)}, + Qsp14}; +in_higher(14, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {14, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {queue:in(X, Qp14), Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}; +in_higher(15, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {15, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, queue:in(X, Qp15), Qp16, Qp17, Qp18, Qp19, Qp20}}; +in_higher(16, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {16, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, queue:in(X, Qp16), Qp17, Qp18, Qp19, Qp20}}; +in_higher(17, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {17, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, queue:in(X, Qp17), Qp18, Qp19, Qp20}}; +in_higher(18, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {18, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, queue:in(X, Qp18), Qp19, Qp20}}; +in_higher(19, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {19, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, queue:in(X, Qp19), Qp20}}; +in_higher(20, {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {20, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, queue:in(X, Qp20)}}. + +in_lower(-20, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {queue:in(X, Qn20), Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-19, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, queue:in(X, Qn19), Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-18, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, Qn19, queue:in(X, Qn18), Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-17, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, Qn19, Qn18, queue:in(X, Qn17), Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-16, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, Qn19, Qn18, Qn17, queue:in(X, Qn16), Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-15, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, queue:in(X, Qn15), Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-14, {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, queue:in(X, Qn14)}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-13, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {queue:in(X, Qn13), Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-12, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, queue:in(X, Qn12), Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-11, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, Qn12, queue:in(X, Qn11), Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-10, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, Qn12, Qn11, queue:in(X, Qn10), Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-9, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, queue:in(X, Qn9), Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-8, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, queue:in(X, Qn8), Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-7, {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, queue:in(X, Qn7)}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-6, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {queue:in(X, Qn6), Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-5, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {Qn6, queue:in(X, Qn5), Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-4, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, queue:in(X, Qn4), Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-3, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, queue:in(X, Qn3), Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-2, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, queue:in(X, Qn2), Qn1}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(-1, {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, queue:in(X, Qn1)}, + Q0, Qsp1, Qsp7, Qsp14}; +in_lower(0, {Pc, Qsn14, Qsn7, Qsn1, + Q0, Qsp1, Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, + queue:in(X, Q0), + Qsp1, Qsp7, Qsp14}; +in_lower(1, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {queue:in(X, Qp1), Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_lower(2, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, queue:in(X, Qp2), Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_lower(3, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, queue:in(X, Qp3), Qp4, Qp5, Qp6}, + Qsp7, Qsp14}; +in_lower(4, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, queue:in(X, Qp4), Qp5, Qp6}, + Qsp7, Qsp14}; +in_lower(5, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, queue:in(X, Qp5), Qp6}, + Qsp7, Qsp14}; +in_lower(6, {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, queue:in(X, Qp6)}, + Qsp7, Qsp14}; +in_lower(7, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {queue:in(X, Qp7), Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_lower(8, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, queue:in(X, Qp8), Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_lower(9, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, queue:in(X, Qp9), Qp10, Qp11, Qp12, Qp13}, + Qsp14}; +in_lower(10, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, queue:in(X, Qp10), Qp11, Qp12, Qp13}, + Qsp14}; +in_lower(11, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, queue:in(X, Qp11), Qp12, Qp13}, + Qsp14}; +in_lower(12, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, queue:in(X, Qp12), Qp13}, + Qsp14}; +in_lower(13, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, queue:in(X, Qp13)}, + Qsp14}; +in_lower(14, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {queue:in(X, Qp14), Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}; +in_lower(15, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, queue:in(X, Qp15), Qp16, Qp17, Qp18, Qp19, Qp20}}; +in_lower(16, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, queue:in(X, Qp16), Qp17, Qp18, Qp19, Qp20}}; +in_lower(17, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, queue:in(X, Qp17), Qp18, Qp19, Qp20}}; +in_lower(18, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, queue:in(X, Qp18), Qp19, Qp20}}; +in_lower(19, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, queue:in(X, Qp19), Qp20}}; +in_lower(20, {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}, X) -> + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, queue:in(X, Qp20)}}. + +out_current(-20, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn20} = queue:out(Qn20), + if + Value =:= empty -> + out_current(-19, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -20}; + true -> + Value + end, + {NewValue, + {-20, + {NewQn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-19, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn19} = queue:out(Qn19), + if + Value =:= empty -> + out_current(-18, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -19}; + true -> + Value + end, + {NewValue, + {-19, + {Qn20, NewQn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-18, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn18} = queue:out(Qn18), + if + Value =:= empty -> + out_current(-17, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -18}; + true -> + Value + end, + {NewValue, + {-18, + {Qn20, Qn19, NewQn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-17, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn17} = queue:out(Qn17), + if + Value =:= empty -> + out_current(-16, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -17}; + true -> + Value + end, + {NewValue, + {-17, + {Qn20, Qn19, Qn18, NewQn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-16, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn16} = queue:out(Qn16), + if + Value =:= empty -> + out_current(-15, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -16}; + true -> + Value + end, + {NewValue, + {-16, + {Qn20, Qn19, Qn18, Qn17, NewQn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-15, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn15} = queue:out(Qn15), + if + Value =:= empty -> + out_current(-14, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -15}; + true -> + Value + end, + {NewValue, + {-15, + {Qn20, Qn19, Qn18, Qn17, Qn16, NewQn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-14, + {_, {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn14} = queue:out(Qn14), + if + Value =:= empty -> + out_current(-13, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -14}; + true -> + Value + end, + {NewValue, + {-14, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, NewQn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-13, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn13} = queue:out(Qn13), + if + Value =:= empty -> + out_current(-12, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -13}; + true -> + Value + end, + {NewValue, + {-13, Qsn14, + {NewQn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-12, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn12} = queue:out(Qn12), + if + Value =:= empty -> + out_current(-11, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -12}; + true -> + Value + end, + {NewValue, + {-12, Qsn14, + {Qn13, NewQn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-11, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn11} = queue:out(Qn11), + if + Value =:= empty -> + out_current(-10, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -11}; + true -> + Value + end, + {NewValue, + {-11, Qsn14, + {Qn13, Qn12, NewQn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-10, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn10} = queue:out(Qn10), + if + Value =:= empty -> + out_current(-9, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -10}; + true -> + Value + end, + {NewValue, + {-10, Qsn14, + {Qn13, Qn12, Qn11, NewQn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-9, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn9} = queue:out(Qn9), + if + Value =:= empty -> + out_current(-8, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -9}; + true -> + Value + end, + {NewValue, + {-9, Qsn14, + {Qn13, Qn12, Qn11, Qn10, NewQn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-8, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn8} = queue:out(Qn8), + if + Value =:= empty -> + out_current(-7, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -8}; + true -> + Value + end, + {NewValue, + {-8, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, NewQn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-7, + {_, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn7} = queue:out(Qn7), + if + Value =:= empty -> + out_current(-6, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -7}; + true -> + Value + end, + {NewValue, + {-7, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, NewQn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-6, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn6} = queue:out(Qn6), + if + Value =:= empty -> + out_current(-5, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -6}; + true -> + Value + end, + {NewValue, + {-6, Qsn14, Qsn7, + {NewQn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-5, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn5} = queue:out(Qn5), + if + Value =:= empty -> + out_current(-4, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -5}; + true -> + Value + end, + {NewValue, + {-5, Qsn14, Qsn7, + {Qn6, NewQn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-4, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn4} = queue:out(Qn4), + if + Value =:= empty -> + out_current(-3, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -4}; + true -> + Value + end, + {NewValue, + {-4, Qsn14, Qsn7, + {Qn6, Qn5, NewQn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-3, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn3} = queue:out(Qn3), + if + Value =:= empty -> + out_current(-2, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -3}; + true -> + Value + end, + {NewValue, + {-3, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, NewQn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-2, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn2} = queue:out(Qn2), + if + Value =:= empty -> + out_current(-1, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -2}; + true -> + Value + end, + {NewValue, + {-2, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, NewQn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(-1, + {_, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQn1} = queue:out(Qn1), + if + Value =:= empty -> + out_current(0, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, -1}; + true -> + Value + end, + {NewValue, + {-1, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, NewQn1}, + Q0, Qsp1, Qsp7, Qsp14}} + end; +out_current(0, + {_, Qsn14, Qsn7, Qsn1, + Q0, Qsp1, Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQ0} = queue:out(Q0), + if + Value =:= empty -> + out_current(1, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 0}; + true -> + Value + end, + {NewValue, + {0, Qsn14, Qsn7, Qsn1, + NewQ0, + Qsp1, Qsp7, Qsp14}} + end; +out_current(1, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp1} = queue:out(Qp1), + if + Value =:= empty -> + out_current(2, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 1}; + true -> + Value + end, + {NewValue, + {1, Qsn14, Qsn7, Qsn1, Q0, + {NewQp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}} + end; +out_current(2, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp2} = queue:out(Qp2), + if + Value =:= empty -> + out_current(3, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 2}; + true -> + Value + end, + {NewValue, + {2, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, NewQp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}} + end; +out_current(3, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp3} = queue:out(Qp3), + if + Value =:= empty -> + out_current(4, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 3}; + true -> + Value + end, + {NewValue, + {3, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, NewQp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}} + end; +out_current(4, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp4} = queue:out(Qp4), + if + Value =:= empty -> + out_current(5, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 4}; + true -> + Value + end, + {NewValue, + {4, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, NewQp4, Qp5, Qp6}, + Qsp7, Qsp14}} + end; +out_current(5, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp5} = queue:out(Qp5), + if + Value =:= empty -> + out_current(6, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 5}; + true -> + Value + end, + {NewValue, + {5, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, NewQp5, Qp6}, + Qsp7, Qsp14}} + end; +out_current(6, + {_, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14} = Q, ReturnType) -> + {Value, NewQp6} = queue:out(Qp6), + if + Value =:= empty -> + out_current(7, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 6}; + true -> + Value + end, + {NewValue, + {6, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, NewQp6}, + Qsp7, Qsp14}} + end; +out_current(7, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp7} = queue:out(Qp7), + if + Value =:= empty -> + out_current(8, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 7}; + true -> + Value + end, + {NewValue, + {7, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {NewQp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}} + end; +out_current(8, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp8} = queue:out(Qp8), + if + Value =:= empty -> + out_current(9, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 8}; + true -> + Value + end, + {NewValue, + {8, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, NewQp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}} + end; +out_current(9, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp9} = queue:out(Qp9), + if + Value =:= empty -> + out_current(10, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 9}; + true -> + Value + end, + {NewValue, + {9, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, NewQp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}} + end; +out_current(10, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp10} = queue:out(Qp10), + if + Value =:= empty -> + out_current(11, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 10}; + true -> + Value + end, + {NewValue, + {10, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, NewQp10, Qp11, Qp12, Qp13}, + Qsp14}} + end; +out_current(11, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp11} = queue:out(Qp11), + if + Value =:= empty -> + out_current(12, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 11}; + true -> + Value + end, + {NewValue, + {11, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, NewQp11, Qp12, Qp13}, + Qsp14}} + end; +out_current(12, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp12} = queue:out(Qp12), + if + Value =:= empty -> + out_current(13, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 12}; + true -> + Value + end, + {NewValue, + {12, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, NewQp12, Qp13}, + Qsp14}} + end; +out_current(13, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14} = Q, ReturnType) -> + {Value, NewQp13} = queue:out(Qp13), + if + Value =:= empty -> + out_current(14, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 13}; + true -> + Value + end, + {NewValue, + {13, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, NewQp13}, + Qsp14}} + end; +out_current(14, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp14} = queue:out(Qp14), + if + Value =:= empty -> + out_current(15, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 14}; + true -> + Value + end, + {NewValue, + {14, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {NewQp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}} + end; +out_current(15, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp15} = queue:out(Qp15), + if + Value =:= empty -> + out_current(16, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 15}; + true -> + Value + end, + {NewValue, + {15, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, NewQp15, Qp16, Qp17, Qp18, Qp19, Qp20}}} + end; +out_current(16, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp16} = queue:out(Qp16), + if + Value =:= empty -> + out_current(17, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 16}; + true -> + Value + end, + {NewValue, + {16, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, NewQp16, Qp17, Qp18, Qp19, Qp20}}} + end; +out_current(17, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp17} = queue:out(Qp17), + if + Value =:= empty -> + out_current(18, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 17}; + true -> + Value + end, + {NewValue, + {17, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, NewQp17, Qp18, Qp19, Qp20}}} + end; +out_current(18, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp18} = queue:out(Qp18), + if + Value =:= empty -> + out_current(19, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 18}; + true -> + Value + end, + {NewValue, + {18, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, NewQp18, Qp19, Qp20}}} + end; +out_current(19, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}} = Q, ReturnType) -> + {Value, NewQp19} = queue:out(Qp19), + if + Value =:= empty -> + out_current(20, Q, ReturnType); + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 19}; + true -> + Value + end, + {NewValue, + {19, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, NewQp19, Qp20}}} + end; +out_current(20, + {_, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20} = Qsp14}, ReturnType) -> + {Value, NewQp20} = queue:out(Qp20), + if + Value =:= empty -> + {empty, {empty, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; + true -> + NewValue = if + ReturnType =:= priority -> + {value, Contents} = Value, + {value, Contents, 20}; + true -> + Value + end, + {NewValue, + {20, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, NewQp20}}} + end. + +out_specific(-20, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn20} = queue:out(Qn20), + {Value, + {Pc, + {NewQn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-19, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn19} = queue:out(Qn19), + {Value, + {Pc, + {Qn20, NewQn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-18, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn18} = queue:out(Qn18), + {Value, + {Pc, + {Qn20, Qn19, NewQn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-17, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn17} = queue:out(Qn17), + {Value, + {Pc, + {Qn20, Qn19, Qn18, NewQn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-16, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn16} = queue:out(Qn16), + {Value, + {Pc, + {Qn20, Qn19, Qn18, Qn17, NewQn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-15, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn15} = queue:out(Qn15), + {Value, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, NewQn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-14, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, Qn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn14} = queue:out(Qn14), + {Value, + {Pc, + {Qn20, Qn19, Qn18, Qn17, Qn16, Qn15, NewQn14}, + Qsn7, Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-13, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn13} = queue:out(Qn13), + {Value, + {Pc, Qsn14, + {NewQn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-12, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn12} = queue:out(Qn12), + {Value, + {Pc, Qsn14, + {Qn13, NewQn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-11, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn11} = queue:out(Qn11), + {Value, + {Pc, Qsn14, + {Qn13, Qn12, NewQn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-10, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn10} = queue:out(Qn10), + {Value, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, NewQn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-9, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn9} = queue:out(Qn9), + {Value, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, NewQn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-8, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn8} = queue:out(Qn8), + {Value, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, NewQn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-7, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, Qn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn7} = queue:out(Qn7), + {Value, + {Pc, Qsn14, + {Qn13, Qn12, Qn11, Qn10, Qn9, Qn8, NewQn7}, + Qsn1, Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-6, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn6} = queue:out(Qn6), + {Value, + {Pc, Qsn14, Qsn7, + {NewQn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-5, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn5} = queue:out(Qn5), + {Value, + {Pc, Qsn14, Qsn7, + {Qn6, NewQn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-4, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn4} = queue:out(Qn4), + {Value, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, NewQn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-3, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn3} = queue:out(Qn3), + {Value, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, NewQn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-2, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn2} = queue:out(Qn2), + {Value, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, NewQn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(-1, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQn1} = queue:out(Qn1), + {Value, + {Pc, Qsn14, Qsn7, + {Qn6, Qn5, Qn4, Qn3, Qn2, NewQn1}, + Q0, Qsp1, Qsp7, Qsp14}}; +out_specific(0, + {Pc, Qsn14, Qsn7, Qsn1, + Q0, Qsp1, Qsp7, Qsp14}) -> + {Value, NewQ0} = queue:out(Q0), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, + NewQ0, + Qsp1, Qsp7, Qsp14}}; +out_specific(1, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp1} = queue:out(Qp1), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {NewQp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}}; +out_specific(2, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp2} = queue:out(Qp2), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, NewQp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}}; +out_specific(3, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp3} = queue:out(Qp3), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, NewQp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}}; +out_specific(4, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp4} = queue:out(Qp4), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, NewQp4, Qp5, Qp6}, + Qsp7, Qsp14}}; +out_specific(5, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp5} = queue:out(Qp5), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, NewQp5, Qp6}, + Qsp7, Qsp14}}; +out_specific(6, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6}, + Qsp7, Qsp14}) -> + {Value, NewQp6} = queue:out(Qp6), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, NewQp6}, + Qsp7, Qsp14}}; +out_specific(7, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp7} = queue:out(Qp7), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {NewQp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}}; +out_specific(8, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp8} = queue:out(Qp8), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, NewQp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}}; +out_specific(9, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp9} = queue:out(Qp9), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, NewQp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}}; +out_specific(10, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp10} = queue:out(Qp10), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, NewQp10, Qp11, Qp12, Qp13}, + Qsp14}}; +out_specific(11, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp11} = queue:out(Qp11), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, NewQp11, Qp12, Qp13}, + Qsp14}}; +out_specific(12, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp12} = queue:out(Qp12), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, NewQp12, Qp13}, + Qsp14}}; +out_specific(13, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, Qp13}, + Qsp14}) -> + {Value, NewQp13} = queue:out(Qp13), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, + {Qp7, Qp8, Qp9, Qp10, Qp11, Qp12, NewQp13}, + Qsp14}}; +out_specific(14, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp14} = queue:out(Qp14), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {NewQp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}}; +out_specific(15, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp15} = queue:out(Qp15), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, NewQp15, Qp16, Qp17, Qp18, Qp19, Qp20}}}; +out_specific(16, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp16} = queue:out(Qp16), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, NewQp16, Qp17, Qp18, Qp19, Qp20}}}; +out_specific(17, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp17} = queue:out(Qp17), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, NewQp17, Qp18, Qp19, Qp20}}}; +out_specific(18, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp18} = queue:out(Qp18), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, NewQp18, Qp19, Qp20}}}; +out_specific(19, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp19} = queue:out(Qp19), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, NewQp19, Qp20}}}; +out_specific(20, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, Qp20}}) -> + {Value, NewQp20} = queue:out(Qp20), + {Value, + {Pc, Qsn14, Qsn7, Qsn1, Q0, Qsp1, Qsp7, + {Qp14, Qp15, Qp16, Qp17, Qp18, Qp19, NewQp20}}}. + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +-include("pqueue_test.hrl"). + +module_test_() -> + {timeout, ?TEST_TIMEOUT, [ + {"internal tests", ?_assertOk(test())} + ]}. + +long_test_() -> + test_condition([ + {"proper tests", ?_assert(pqueue_proper:qc_pq())} + ], ?CLOUDI_LONG_TEST_TIMEOUT). + +-endif. + diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue2.erl b/aoc2023/build/dev/erlang/pqueue/src/pqueue2.erl new file mode 100644 index 0000000..bbdeaaf --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue2.erl @@ -0,0 +1,483 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: +%%% +%%%------------------------------------------------------------------------ +%%% @doc +%%% ==Skew Heap Priority Queue.== +%%% Ulf Wiger suggested pursuing a skew heap as an optimal Erlang priority +%%% queue implementation. Unfortunately, testing has shown this solution to +%%% be more than 2 times slower than pqueue. +%%% @end +%%% +%%% MIT License +%%% +%%% Copyright (c) 2011-2020 Michael Truog <mjtruog at protonmail dot com> +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a +%%% copy of this software and associated documentation files (the "Software"), +%%% to deal in the Software without restriction, including without limitation +%%% the rights to use, copy, modify, merge, publish, distribute, sublicense, +%%% and/or sell copies of the Software, and to permit persons to whom the +%%% Software is furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in +%%% all copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +%%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +%%% DEALINGS IN THE SOFTWARE. +%%% +%%% @author Michael Truog <mjtruog at protonmail dot com> +%%% @copyright 2011-2020 Michael Truog +%%% @version 2.0.1 {@date} {@time} +%%%------------------------------------------------------------------------ + +-module(pqueue2). +-author('mjtruog at protonmail dot com'). + +%% external interface +-export([in/2, + in/3, + is_empty/1, + is_queue/1, + len/1, + new/0, + out/1, + out/2, + pout/1, + to_list/1, + test/0]). + +%%%------------------------------------------------------------------------ +%%% External interface functions +%%%------------------------------------------------------------------------ + +-ifdef(ERLANG_OTP_VERSION_16). +-type pqueue2() :: + empty | + {integer(), pqueue2(), pqueue2(), element, term()} | + {integer(), pqueue2(), pqueue2(), queue, queue()}. +-else. +-type pqueue2() :: + empty | + {integer(), pqueue2(), pqueue2(), element, term()} | + {integer(), pqueue2(), pqueue2(), queue, queue:queue()}. +-endif. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of the 0 priority queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), pqueue2()) -> pqueue2(). + +in(Value, H) -> + in(Value, 0, H). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of a specific priority queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), integer(), pqueue2()) -> pqueue2(). + +in(Value, P, H) -> + merge({P, empty, empty, element, Value}, H). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue is empty.=== +%% @end +%%------------------------------------------------------------------------- + +-spec is_empty(pqueue2()) -> 'true' | 'false'. + +is_empty(empty) -> + true; +is_empty({_, HL, HR, queue, Queue}) -> + is_empty(HL) andalso is_empty(HR) andalso queue:is_empty(Queue); +is_empty(_) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue type is as expected.=== +%% @end +%%------------------------------------------------------------------------- + +-spec is_queue(pqueue2()) -> 'true' | 'false'. + +is_queue(empty) -> + true; +is_queue({P, _, _, element, _}) + when is_integer(P) -> + true; +is_queue({P, _, _, queue, Queue}) + when is_integer(P) -> + queue:is_queue(Queue); +is_queue(_) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Determine the length of a priority queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec len(pqueue2()) -> non_neg_integer(). + +len(H) -> + len(0, out(H)). +len(I, {empty, _}) -> + I; +len(I, {{value, _}, H}) -> + len(I + 1, out(H)). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Create a new priority queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec new() -> pqueue2(). + +new() -> + empty. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec out(pqueue2()) -> + {{'value', term()}, pqueue2()} | {'empty', pqueue2()}. + +out(empty) -> + {empty, empty}; +out({_, HL, HR, element, Value}) -> + {{value, Value}, merge(HL, HR)}; +out({P, HL, HR, queue, Queue}) -> + case queue:out(Queue) of + {{value, _} = Result, NewQueue} -> + {Result, {P, HL, HR, queue, NewQueue}}; + {empty, _} -> + out(merge(HL, HR)) + end. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item of a specific priority from the head of the queue.=== +%% @end +%%------------------------------------------------------------------------- + +-spec out(integer(), pqueue2()) -> + {{'value', term()}, pqueue2()} | {'empty', pqueue2()}. + +out(_, empty) -> + {empty, empty}; +out(P, {P1, _, _, _, _} = H) when P < P1 -> + {empty, H}; +out(P, {P1, HL1, HR1, T, D}) when P > P1 -> + case out(P, HL1) of + {{value, _} = Result, HL2} -> + {Result, {P1, HL2, HR1, T, D}}; + {empty, HL2} -> + case out(P, HR1) of + {{value, _} = Result, HR2} -> + {Result, {P1, HL2, HR2, T, D}}; + {empty, HR2} -> + {empty, {P1, HL2, HR2, T, D}} + end + end; +out(P, {P, HL, HR, element, Value}) -> + {{value, Value}, merge(HL, HR)}; +out(P, {P, HL, HR, queue, Queue}) -> + case queue:out(Queue) of + {{value, _} = Result, NewQueue} -> + {Result, {P, HL, HR, queue, NewQueue}}; + {empty, _} -> + out(P, merge(HL, HR)) + end. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% Includes the priority in the return value. +%% @end +%%------------------------------------------------------------------------- + +-spec pout(pqueue2()) -> + {{'value', term(), integer()}, pqueue2()} | {'empty', pqueue2()}. + +pout(empty) -> + {empty, empty}; +pout({P, HL, HR, element, Value}) -> + {{value, Value, P}, merge(HL, HR)}; +pout({P, HL, HR, queue, Queue}) -> + case queue:out(Queue) of + {{value, Value}, NewQueue} -> + {{value, Value, P}, {P, HL, HR, queue, NewQueue}}; + {empty, _} -> + pout(merge(HL, HR)) + end. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Convert the priority queue to a list.=== +%% @end +%%------------------------------------------------------------------------- + +-spec to_list(pqueue2()) -> list(term()). + +to_list(H) -> + to_list([], out(H)). +to_list(L, {empty, _}) -> + lists:reverse(L); +to_list(L, {{value, Value}, H}) -> + to_list([Value | L], out(H)). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Regression test.=== +%% @end +%%------------------------------------------------------------------------- + +test() -> + Q0 = pqueue2:new(), + true = pqueue2:is_queue(Q0), + Q1 = pqueue2:in(20, 20, Q0), + Q2 = pqueue2:in(19, 19, Q1), + Q3 = pqueue2:in(18, 18, Q2), + Q4 = pqueue2:in(17, 17, Q3), + Q5 = pqueue2:in(16, 16, Q4), + Q6 = pqueue2:in(15, 15, Q5), + Q7 = pqueue2:in(14, 14, Q6), + Q8 = pqueue2:in(13, 13, Q7), + Q9 = pqueue2:in(12, 12, Q8), + Q10 = pqueue2:in(11, 11, Q9), + Q11 = pqueue2:in(10, 10, Q10), + Q12 = pqueue2:in(9, 9, Q11), + Q13 = pqueue2:in(8, 8, Q12), + Q14 = pqueue2:in(7, 7, Q13), + Q15 = pqueue2:in(6, 6, Q14), + Q16 = pqueue2:in(5, 5, Q15), + Q17 = pqueue2:in(4, 4, Q16), + Q18 = pqueue2:in(3, 3, Q17), + Q19 = pqueue2:in(2, 2, Q18), + Q20 = pqueue2:in(1, 1, Q19), + Q21 = pqueue2:in(0, 0, Q20), + Q22 = pqueue2:in(-1, -1, Q21), + Q23 = pqueue2:in(-2, -2, Q22), + Q24 = pqueue2:in(-3, -3, Q23), + Q25 = pqueue2:in(-4, -4, Q24), + Q26 = pqueue2:in(-5, -5, Q25), + Q27 = pqueue2:in(-6, -6, Q26), + Q28 = pqueue2:in(-7, -7, Q27), + Q29 = pqueue2:in(-8, -8, Q28), + Q30 = pqueue2:in(-9, -9, Q29), + Q31 = pqueue2:in(-10, -10, Q30), + Q32 = pqueue2:in(-11, -11, Q31), + Q33 = pqueue2:in(-12, -12, Q32), + Q34 = pqueue2:in(-13, -13, Q33), + Q35 = pqueue2:in(-14, -14, Q34), + Q36 = pqueue2:in(-15, -15, Q35), + Q37 = pqueue2:in(-16, -16, Q36), + Q38 = pqueue2:in(-17, -17, Q37), + Q39 = pqueue2:in(-18, -18, Q38), + Q40 = pqueue2:in(-19, -19, Q39), + Q41 = pqueue2:in(-20, -20, Q40), + Q42 = pqueue2:in(-20, -20, Q41), + Q43 = pqueue2:in(-19, -19, Q42), + Q44 = pqueue2:in(-18, -18, Q43), + Q45 = pqueue2:in(-17, -17, Q44), + Q46 = pqueue2:in(-16, -16, Q45), + Q47 = pqueue2:in(-15, -15, Q46), + Q48 = pqueue2:in(-14, -14, Q47), + Q49 = pqueue2:in(-13, -13, Q48), + Q50 = pqueue2:in(-12, -12, Q49), + Q51 = pqueue2:in(-11, -11, Q50), + Q52 = pqueue2:in(-10, -10, Q51), + Q53 = pqueue2:in(-9, -9, Q52), + Q54 = pqueue2:in(-8, -8, Q53), + Q55 = pqueue2:in(-7, -7, Q54), + Q56 = pqueue2:in(-6, -6, Q55), + Q57 = pqueue2:in(-5, -5, Q56), + Q58 = pqueue2:in(-4, -4, Q57), + Q59 = pqueue2:in(-3, -3, Q58), + Q60 = pqueue2:in(-2, -2, Q59), + Q61 = pqueue2:in(-1, -1, Q60), + Q62 = pqueue2:in(0, 0, Q61), + Q63 = pqueue2:in(1, 1, Q62), + Q64 = pqueue2:in(2, 2, Q63), + Q65 = pqueue2:in(3, 3, Q64), + Q66 = pqueue2:in(4, 4, Q65), + Q67 = pqueue2:in(5, 5, Q66), + Q68 = pqueue2:in(6, 6, Q67), + Q69 = pqueue2:in(7, 7, Q68), + Q70 = pqueue2:in(8, 8, Q69), + Q71 = pqueue2:in(9, 9, Q70), + Q72 = pqueue2:in(10, 10, Q71), + Q73 = pqueue2:in(11, 11, Q72), + Q74 = pqueue2:in(12, 12, Q73), + Q75 = pqueue2:in(13, 13, Q74), + Q76 = pqueue2:in(14, 14, Q75), + Q77 = pqueue2:in(15, 15, Q76), + Q78 = pqueue2:in(16, 16, Q77), + Q79 = pqueue2:in(17, 17, Q78), + Q80 = pqueue2:in(18, 18, Q79), + Q81 = pqueue2:in(19, 19, Q80), + Q82 = pqueue2:in(20, 20, Q81), + true = pqueue2:is_queue(Q82), + 82 = pqueue2:len(Q82), + [-20, -20, -19, -19, -18, -18, -17, -17, -16, -16, -15, -15, -14, -14, + -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -7, -7, -6, -6, + -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20] = pqueue2:to_list(Q82), + {{value, -20}, Q83} = pqueue2:out(Q82), + {{value, -20}, Q84} = pqueue2:out(Q83), + {{value, -19}, Q85} = pqueue2:out(Q84), + {{value, -19}, Q86} = pqueue2:out(Q85), + {{value, -18}, Q87} = pqueue2:out(Q86), + {{value, -18}, Q88} = pqueue2:out(Q87), + {{value, 0}, Q89} = pqueue2:out(0, Q88), + {{value, 0}, Q90} = pqueue2:out(0, Q89), + {empty, _} = pqueue2:out(0, Q90), + {{value, -17, -17}, Q91} = pqueue2:pout(Q90), + {{value, -17, -17}, Q92} = pqueue2:pout(Q91), + {{value, -16, -16}, Q93} = pqueue2:pout(Q92), + {{value, -16, -16}, Q94} = pqueue2:pout(Q93), + {{value, -15, -15}, Q95} = pqueue2:pout(Q94), + {{value, -15, -15}, Q96} = pqueue2:pout(Q95), + {{value, -14, -14}, Q97} = pqueue2:pout(Q96), + {{value, -14, -14}, Q98} = pqueue2:pout(Q97), + {{value, -13, -13}, Q99} = pqueue2:pout(Q98), + {{value, -13, -13}, Q100} = pqueue2:pout(Q99), + {{value, -12, -12}, Q101} = pqueue2:pout(Q100), + {{value, -12, -12}, Q102} = pqueue2:pout(Q101), + {{value, -11, -11}, Q103} = pqueue2:pout(Q102), + {{value, -11, -11}, Q104} = pqueue2:pout(Q103), + {{value, -10, -10}, Q105} = pqueue2:pout(Q104), + {{value, -10, -10}, Q106} = pqueue2:pout(Q105), + {{value, -9, -9}, Q107} = pqueue2:pout(Q106), + {{value, -9, -9}, Q108} = pqueue2:pout(Q107), + {{value, -8, -8}, Q109} = pqueue2:pout(Q108), + {{value, -8, -8}, Q110} = pqueue2:pout(Q109), + {{value, -7, -7}, Q111} = pqueue2:pout(Q110), + {{value, -7, -7}, Q112} = pqueue2:pout(Q111), + {{value, -6, -6}, Q113} = pqueue2:pout(Q112), + {{value, -6, -6}, Q114} = pqueue2:pout(Q113), + {{value, -5, -5}, Q115} = pqueue2:pout(Q114), + {{value, -5, -5}, Q116} = pqueue2:pout(Q115), + {{value, -4, -4}, Q117} = pqueue2:pout(Q116), + {{value, -4, -4}, Q118} = pqueue2:pout(Q117), + {{value, -3, -3}, Q119} = pqueue2:pout(Q118), + {{value, -3, -3}, Q120} = pqueue2:pout(Q119), + {{value, -2, -2}, Q121} = pqueue2:pout(Q120), + {{value, -2, -2}, Q122} = pqueue2:pout(Q121), + {{value, -1, -1}, Q123} = pqueue2:pout(Q122), + {{value, -1, -1}, Q124} = pqueue2:pout(Q123), + {{value, 1, 1}, Q125} = pqueue2:pout(Q124), + {{value, 1, 1}, Q126} = pqueue2:pout(Q125), + {{value, 2, 2}, Q127} = pqueue2:pout(Q126), + {{value, 2, 2}, Q128} = pqueue2:pout(Q127), + {{value, 3, 3}, Q129} = pqueue2:pout(Q128), + {{value, 3, 3}, Q130} = pqueue2:pout(Q129), + {{value, 4, 4}, Q131} = pqueue2:pout(Q130), + {{value, 4, 4}, Q132} = pqueue2:pout(Q131), + {{value, 5, 5}, Q133} = pqueue2:pout(Q132), + {{value, 5, 5}, Q134} = pqueue2:pout(Q133), + {{value, 6, 6}, Q135} = pqueue2:pout(Q134), + {{value, 6, 6}, Q136} = pqueue2:pout(Q135), + {{value, 7, 7}, Q137} = pqueue2:pout(Q136), + {{value, 7, 7}, Q138} = pqueue2:pout(Q137), + {{value, 8, 8}, Q139} = pqueue2:pout(Q138), + {{value, 8, 8}, Q140} = pqueue2:pout(Q139), + {{value, 9, 9}, Q141} = pqueue2:pout(Q140), + {{value, 9, 9}, Q142} = pqueue2:pout(Q141), + {{value, 10, 10}, Q143} = pqueue2:pout(Q142), + {{value, 10, 10}, Q144} = pqueue2:pout(Q143), + {{value, 11, 11}, Q145} = pqueue2:pout(Q144), + {{value, 11, 11}, Q146} = pqueue2:pout(Q145), + {{value, 12, 12}, Q147} = pqueue2:pout(Q146), + {{value, 12, 12}, Q148} = pqueue2:pout(Q147), + {{value, 13, 13}, Q149} = pqueue2:pout(Q148), + {{value, 13, 13}, Q150} = pqueue2:pout(Q149), + {{value, 14, 14}, Q151} = pqueue2:pout(Q150), + {{value, 14, 14}, Q152} = pqueue2:pout(Q151), + {{value, 15, 15}, Q153} = pqueue2:pout(Q152), + {{value, 15, 15}, Q154} = pqueue2:pout(Q153), + {{value, 16, 16}, Q155} = pqueue2:pout(Q154), + {{value, 16, 16}, Q156} = pqueue2:pout(Q155), + {{value, 17, 17}, Q157} = pqueue2:pout(Q156), + {{value, 17, 17}, Q158} = pqueue2:pout(Q157), + {{value, 18, 18}, Q159} = pqueue2:pout(Q158), + {{value, 18, 18}, Q160} = pqueue2:pout(Q159), + {{value, 19, 19}, Q161} = pqueue2:pout(Q160), + {{value, 19, 19}, Q162} = pqueue2:pout(Q161), + {{value, 20, 20}, Q163} = pqueue2:pout(Q162), + {{value, 20, 20}, Q164} = pqueue2:pout(Q163), + true = pqueue2:is_empty(Q164), + {empty, Q165} = pqueue2:pout(Q164), + true = pqueue2:is_empty(Q165), + % test case 1, based on proper testing + C1V0 = pqueue2:in(-18, pqueue2:new()), + C1V1 = pqueue2:in(9, C1V0), + C1V2 = pqueue2:in(-10, -4, C1V1), + C1V3 = pqueue2:in(-29, C1V2), + C1V4 = pqueue2:in(11, C1V3), + 5 = pqueue2:len(C1V4), + [-10, -18, 9, -29, 11] = pqueue2:to_list(C1V4), + % test case 2, based on proper testing + C2V0 = pqueue2:in(-4, -15, pqueue2:new()), + C2V1 = pqueue2:in(13, C2V0), + C2V2 = pqueue2:in(2, C2V1), + [-4, 13, 2] = to_list(C2V2), + ok. + +%%%------------------------------------------------------------------------ +%%% Private functions +%%%------------------------------------------------------------------------ + +merge(empty, empty) -> + empty; +merge(empty, {_, _, _, _, _} = H) -> + H; +merge({_, _, _, _, _} = H, empty) -> + H; +merge({P1, HL1, HR1, T, D}, {P2, _, _, _, _} = H2) when P1 < P2 -> + {P1, HL1, merge(HR1, H2), T, D}; +merge({P1, _, _, _, _} = H1, {P2, HL2, HR2, T, D}) when P1 > P2 -> + {P2, HL2, merge(H1, HR2), T, D}; +merge({P, HL1, HR1, element, Value1}, {P, HL2, HR2, element, Value2}) -> + {P, merge(HL1, HR1), merge(HL2, HR2), queue, + queue:from_list([Value2, Value1])}; +merge({P, HL1, HR1, queue, Queue}, {P, HL2, HR2, element, Value}) -> + {P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:in(Value, Queue)}; +merge({P, HL1, HR1, element, Value}, {P, HL2, HR2, queue, Queue}) -> + {P, merge(HL1, HR1), merge(HL2, HR2), queue, queue:in(Value, Queue)}. + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +-include("pqueue_test.hrl"). + +module_test_() -> + {timeout, ?TEST_TIMEOUT, [ + {"internal tests", ?_assertOk(test())} + ]}. + +long_test_() -> + test_condition([ + {"proper tests", ?_assert(pqueue_proper:qc_pq2())} + ], ?CLOUDI_LONG_TEST_TIMEOUT). + +-endif. + diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue3.erl b/aoc2023/build/dev/erlang/pqueue/src/pqueue3.erl new file mode 100644 index 0000000..03b370a --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue3.erl @@ -0,0 +1,404 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: +%%% +%%%------------------------------------------------------------------------ +%%% @doc +%%% ==A Large Priority Queue.== +%%% This priority queue implementation depends on layered tuples, so that tuple +%%% access times can be exploited for quick in/out priority queue operations +%%% when using 64 or more total priorities. This implementation was created +%%% to avoid the slowness within the priority queue used by +%%% both RabbitMQ and Riak +%%% (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +%%% @end +%%% +%%% MIT License +%%% +%%% Copyright (c) 2011-2020 Michael Truog <mjtruog at protonmail dot com> +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a +%%% copy of this software and associated documentation files (the "Software"), +%%% to deal in the Software without restriction, including without limitation +%%% the rights to use, copy, modify, merge, publish, distribute, sublicense, +%%% and/or sell copies of the Software, and to permit persons to whom the +%%% Software is furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in +%%% all copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +%%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +%%% DEALINGS IN THE SOFTWARE. +%%% +%%% @author Michael Truog <mjtruog at protonmail dot com> +%%% @copyright 2011-2020 Michael Truog +%%% @version 2.0.1 {@date} {@time} +%%%------------------------------------------------------------------------ + +-module(pqueue3). +-author('mjtruog at protonmail dot com'). + +%% external interface +-export([in/2, % O(1) + in/3, % O(1) + is_empty/1, % O(1) + is_queue/1, % O(1) + len/1, % O(N) + new/0, % O(1) + new/1, % O(1) + out/1, % O(1) amortized, O(N) worst case + out/2, % O(1) amortized, O(N) worst case + pout/1, % O(1) amortized, O(N) worst case + to_list/1]). % O(N) + +%%%------------------------------------------------------------------------ +%%% External interface functions +%%%------------------------------------------------------------------------ + +-type pqueue3() :: {integer(), integer(), empty | integer(), tuple()}. +-type pqueue3_empty() :: {integer(), integer(), empty, tuple()}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of the 0 priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), pqueue3()) -> pqueue3(). + +in(Value, Q) -> + in(Value, 0, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of a specific priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(term(), integer(), pqueue3()) -> pqueue3(). + +in(_, P, {Size, Offset, _, _}) + when (P + Offset) < 0; (P + Offset) > Size -> + erlang:exit(badarg); +in(Value, P, {Size, Offset, empty, Bins}) -> + PriorityIndex = P + Offset, + {Size, Offset, PriorityIndex, + in_queue(layer_indexes(Size, PriorityIndex), Value, Bins)}; +in(Value, P, {Size, Offset, I, Bins}) + when (P + Offset) < I -> + PriorityIndex = P + Offset, + {Size, Offset, PriorityIndex, + in_queue(layer_indexes(Size, PriorityIndex), Value, Bins)}; +in(Value, P, {Size, Offset, I, Bins}) -> + {Size, Offset, I, + in_queue(layer_indexes(Size, P + Offset), Value, Bins)}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue is empty.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_empty(pqueue3()) -> 'true' | 'false'. + +is_empty({_, _, empty, _}) -> + true; +is_empty({_, _, _, _} = Q) -> + case out(Q) of + {empty, _} -> + true; + {{value, _}, _} -> + false + end. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue type is as expected.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_queue(pqueue3()) -> 'true' | 'false'. + +is_queue({Size, Offset, I, Bins}) + when is_integer(Size), is_integer(Offset), is_tuple(Bins) -> + (I =:= empty) or is_integer(I); +is_queue(_) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Determine the length of a priority queue.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec len(pqueue3()) -> non_neg_integer(). + +len(Q) -> + len(0, out(Q)). +len(I, {empty, _}) -> + I; +len(I, {{value, _}, Q}) -> + len(I + 1, out(Q)). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Create a new priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec new() -> pqueue3_empty(). + +new() -> + new([]). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Create a new priority queue with customization options.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec new(list({atom(), term()})) -> pqueue3(). + +new(Options) -> + Size = proplists:get_value(priorities, Options, 256), + MiddleZero = proplists:get_value(middle_priority_zero, Options, true), + Offset = if + MiddleZero =:= true -> + erlang:round((Size / 2) + 0.5) - 1; + true -> + 0 + end, + {Size, Offset, empty, create(layer_sizes(Size))}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(pqueue3()) -> + {{'value', term()}, pqueue3()} | {'empty', pqueue3()}. + +out({_, _, empty, _} = Q) -> + {empty, Q}; +out({Size, Offset, I, Bins}) -> + {Result, NewI, NewBins} = out_check( + I, Size, out_queue(layer_indexes(Size, I), Bins) + ), + {Result, {Size, Offset, NewI, NewBins}}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item of a specific priority from the head of the queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(integer(), pqueue3()) -> + {{'value', term()}, pqueue3()} | {'empty', pqueue3()}. + +out(P, {Size, Offset, _, _}) + when (P + Offset) < 0; (P + Offset) > Size -> + erlang:exit(badarg); +out(_, {_, _, empty, _} = Q) -> + {empty, Q}; +out(P, {Size, Offset, I, Bins}) -> + {Result, NewBins} = out_queue(layer_indexes(Size, P + Offset), Bins), + {Result, {Size, Offset, I, NewBins}}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% Includes the priority in the return value. +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec pout(pqueue3()) -> + {{'value', term(), integer()}, pqueue3()} | {'empty', pqueue3()}. + +pout({_, _, empty, _} = Q) -> + {empty, Q}; +pout({Size, Offset, I, Bins}) -> + {Result, NewI, NewBins} = pout_check( + I, Size, Offset, out_queue(layer_indexes(Size, I), Bins) + ), + {Result, {Size, Offset, NewI, NewBins}}. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Convert the priority queue to a list.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec to_list(pqueue3()) -> list(term()). + +to_list(Q) -> + to_list([], out(Q)). +to_list(L, {empty, _}) -> + lists:reverse(L); +to_list(L, {{value, Value}, Q}) -> + to_list([Value | L], out(Q)). + +%%%------------------------------------------------------------------------ +%%% Private functions +%%%------------------------------------------------------------------------ + +create([]) -> + queue:new(); + +create([I | Is]) -> + erlang:make_tuple(I + 1, create(Is)). + +in_queue({I1}, Value, Bins1) -> + erlang:setelement(I1, Bins1, queue:in(Value, erlang:element(I1, Bins1))); + +in_queue({I1, I2}, Value, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, queue:in(Value, erlang:element(I2, Bins2)))); + +in_queue({I1, I2, I3}, Value, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + Bins3 = erlang:element(I2, Bins2), + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, + erlang:setelement(I3, Bins3, queue:in(Value, erlang:element(I3, Bins3))))); + +in_queue({I1, I2, I3, I4}, Value, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + Bins3 = erlang:element(I2, Bins2), + Bins4 = erlang:element(I3, Bins3), + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, + erlang:setelement(I3, Bins3, + erlang:setelement(I4, Bins4, queue:in(Value, erlang:element(I4, Bins4)))))). + +pout_check(Size, Size, _, {empty, Bins}) -> + {empty, empty, Bins}; +pout_check(I, _, Offset, {{value, Value}, Bins}) -> + {{value, Value, I - Offset}, I, Bins}; +pout_check(I, Size, Offset, {empty, Bins}) -> + NewI = I + 1, + pout_check(NewI, Size, Offset, out_queue(layer_indexes(Size, NewI), Bins)). + +out_check(Size, Size, {empty, Bins}) -> + {empty, empty, Bins}; +out_check(I, _, {{value, _} = Result, Bins}) -> + {Result, I, Bins}; +out_check(I, Size, {empty, Bins}) -> + NewI = I + 1, + out_check(NewI, Size, out_queue(layer_indexes(Size, NewI), Bins)). + +out_queue({I1}, Bins1) -> + {Result, NewQueue} = queue:out(erlang:element(I1, Bins1)), + {Result, + erlang:setelement(I1, Bins1, NewQueue)}; + +out_queue({I1, I2}, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + {Result, NewQueue} = queue:out(erlang:element(I2, Bins2)), + {Result, + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, NewQueue))}; + +out_queue({I1, I2, I3}, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + Bins3 = erlang:element(I2, Bins2), + {Result, NewQueue} = queue:out(erlang:element(I3, Bins3)), + {Result, + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, + erlang:setelement(I3, Bins3, NewQueue)))}; + +out_queue({I1, I2, I3, I4}, Bins1) -> + Bins2 = erlang:element(I1, Bins1), + Bins3 = erlang:element(I2, Bins2), + Bins4 = erlang:element(I3, Bins3), + {Result, NewQueue} = queue:out(erlang:element(I4, Bins4)), + {Result, + erlang:setelement(I1, Bins1, + erlang:setelement(I2, Bins2, + erlang:setelement(I3, Bins3, + erlang:setelement(I4, Bins4, NewQueue))))}. + +layer_indexes(Size, PriorityIndex) -> + if + Size =< 127 -> + {PriorityIndex + 1}; + Size =< 255 -> + <<I1:4, I2:4>> = <<PriorityIndex:8>>, + {I1 + 1, I2 + 1}; + Size =< 511 -> + <<I1:4, I2:5>> = <<PriorityIndex:9>>, + {I1 + 1, I2 + 1}; + Size =< 1023 -> + <<I1:3, I2:3, I3:4>> = <<PriorityIndex:10>>, + {I1 + 1, I2 + 1, I3 + 1}; + Size =< 2047 -> + <<I1:3, I2:4, I3:4>> = <<PriorityIndex:11>>, + {I1 + 1, I2 + 1, I3 + 1}; + Size =< 4095 -> + <<I1:4, I2:4, I3:4>> = <<PriorityIndex:12>>, + {I1 + 1, I2 + 1, I3 + 1}; + Size =< 8191 -> + <<I1:4, I2:4, I3:5>> = <<PriorityIndex:13>>, + {I1 + 1, I2 + 1, I3 + 1}; + Size =< 16383 -> + <<I1:4, I2:5, I3:5>> = <<PriorityIndex:14>>, + {I1 + 1, I2 + 1, I3 + 1}; + Size =< 32767 -> + <<I1:3, I2:4, I3:4, I4:4>> = <<PriorityIndex:15>>, + {I1 + 1, I2 + 1, I3 + 1, I4 + 1}; + Size =< 65535 -> + <<I1:4, I2:4, I3:4, I4:4>> = <<PriorityIndex:16>>, + {I1 + 1, I2 + 1, I3 + 1, I4 + 1} + end. + +layer_sizes(Size) -> + if + Size =< 127 -> + <<I1:7>> = <<127:7>>, + [I1]; + Size =< 255 -> + <<I1:4, I2:4>> = <<255:8>>, + [I1, I2]; + Size =< 511 -> + <<I1:4, I2:5>> = <<511:9>>, + [I1, I2]; + Size =< 1023 -> + <<I1:3, I2:3, I3:4>> = <<1023:10>>, + [I1, I2, I3]; + Size =< 2047 -> + <<I1:3, I2:4, I3:4>> = <<2047:11>>, + [I1, I2, I3]; + Size =< 4095 -> + <<I1:4, I2:4, I3:4>> = <<4095:12>>, + [I1, I2, I3]; + Size =< 8191 -> + <<I1:4, I2:4, I3:5>> = <<8191:13>>, + [I1, I2, I3]; + Size =< 16383 -> + <<I1:4, I2:5, I3:5>> = <<16383:14>>, + [I1, I2, I3]; + Size =< 32767 -> + <<I1:3, I2:4, I3:4, I4:4>> = <<32767:15>>, + [I1, I2, I3, I4]; + Size =< 65535 -> + <<I1:4, I2:4, I3:4, I4:4>> = <<65535:16>>, + [I1, I2, I3, I4] + end. + diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue4.erl b/aoc2023/build/dev/erlang/pqueue/src/pqueue4.erl new file mode 100644 index 0000000..30b188d --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue4.erl @@ -0,0 +1,11662 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: +%%% +%%%------------------------------------------------------------------------ +%%% @doc +%%% ==Static Priority Queue.== +%%% This priority queue implementation depends on a static number of priorities +%%% (-128 (high) to 128 (low)) so that tuple access times can be exploited for +%%% quick in/out priority queue operations. This implementation was created to +%%% avoid the slowness within the priority queue used by both RabbitMQ and Riak +%%% (https://github.com/basho/riak_core/blob/master/src/priority_queue.erl). +%%% @end +%%% +%%% MIT License +%%% +%%% Copyright (c) 2011-2020 Michael Truog <mjtruog at protonmail dot com> +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a +%%% copy of this software and associated documentation files (the "Software"), +%%% to deal in the Software without restriction, including without limitation +%%% the rights to use, copy, modify, merge, publish, distribute, sublicense, +%%% and/or sell copies of the Software, and to permit persons to whom the +%%% Software is furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in +%%% all copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +%%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +%%% DEALINGS IN THE SOFTWARE. +%%% +%%% +%%% queue_remove_unique/2 is based on queue:filter/2 +%%% which is under the Apache License 2.0: +%%% +%%% Copyright Ericsson AB 1996-2016. All Rights Reserved. +%%% +%%% Licensed under the Apache License, Version 2.0 (the "License"); +%%% you may not use this file except in compliance with the License. +%%% You may obtain a copy of the License at +%%% +%%% http://www.apache.org/licenses/LICENSE-2.0 +%%% +%%% Unless required by applicable law or agreed to in writing, software +%%% distributed under the License is distributed on an "AS IS" BASIS, +%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%%% See the License for the specific language governing permissions and +%%% limitations under the License. +%%% +%%% @author Michael Truog <mjtruog at protonmail dot com> +%%% @copyright 2011-2020 Michael Truog +%%% @version 2.0.1 {@date} {@time} +%%%------------------------------------------------------------------------ + +-module(pqueue4). +-author('mjtruog at protonmail dot com'). + +%% external interface +-export([filter/2, % O(N) + filter/3, % O(N) + in/2, % O(1) + in/3, % O(1) + is_empty/1, % O(1) + is_queue/1, % O(1) + len/1, % O(1) + new/0, % O(1) + out/1, % O(1) amortized, O(N) worst case + out/2, % O(1) amortized, O(N) worst case + pout/1, % O(1) amortized, O(N) worst case + remove_unique/2, % O(N) but smaller constant than filter/2 + remove_unique/3, % O(N) but smaller constant than filter/3 + to_list/1, % O(N) + to_plist/1, % O(N) + test/0]). + +%%%------------------------------------------------------------------------ +%%% External interface functions +%%%------------------------------------------------------------------------ + +-type priority() :: -128..128. +-ifdef(ERLANG_OTP_VERSION_16). +-type pqueue4(_) :: + {priority() | 'empty', % current priority + non_neg_integer(), % total size + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + queue(), + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}, + {queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue(), + queue(), queue(), queue(), queue(), queue(), queue(), queue(), queue()}}. +-else. +-type pqueue4(T) :: + {priority() | 'empty', % current priority + non_neg_integer(), % total size + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + queue:queue(T), + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}, + {queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T), + queue:queue(T), queue:queue(T), queue:queue(T), queue:queue(T)}}. +-endif. +-type pqueue4() :: pqueue4(any()). +-export_type([pqueue4/0, pqueue4/1]). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Filter the priority queue.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec filter(fun((any()) -> boolean()), pqueue4()) -> pqueue4(). + +filter(F, {empty, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) + when is_function(F, 1) -> + Q; +filter(F, {Pc, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) + when is_function(F, 1) -> + filter_all(Pc, F, Q). + +filter_all(_, _, {_, 0, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _} = Q) -> + Q; +filter_all(128, F, Q) -> + filter_priority(128, F, Q); +filter_all(P, F, Q) when is_integer(P) -> + filter_all(P + 1, F, filter_priority(P, F, Q)). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Filter a specific priority within the priority queue.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec filter(fun((any()) -> boolean()), integer(), pqueue4()) -> pqueue4(). + +filter(_, P, _) + when P < -128; P > 128 -> + erlang:exit(badarg); +filter(F, P, Q) when is_function(F, 1) -> + filter_priority(P, F, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of the 0 priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(any(), pqueue4()) -> pqueue4(). + +in(X, Q) -> + in(X, 0, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Append an item to the tail of a specific priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec in(any(), integer(), pqueue4()) -> pqueue4(). + +in(_, P, _) + when P < -128; P > 128 -> + erlang:exit(badarg); +in(X, P, {empty, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + in_higher(P, Q, X); % (in a higher priority) +in(X, P, {Pc, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) + when P < Pc -> + in_higher(P, Q, X); % (in a higher priority) +in(X, P, Q) -> + in_lower(P, Q, X). % (in a lower priority) + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue is empty.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_empty(pqueue4()) -> 'true' | 'false'. + +is_empty({_, 0, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}) -> + true; +is_empty({_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Check if the priority queue type is as expected.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec is_queue(pqueue4()) -> 'true' | 'false'. + +is_queue({Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) + when is_integer(Size), + tuple_size(Qn128) == 16, tuple_size(Qn112) == 16, + tuple_size(Qn96) == 16, tuple_size(Qn80) == 16, + tuple_size(Qn64) == 16, tuple_size(Qn48) == 16, + tuple_size(Qn32) == 16, tuple_size(Qn16) == 16, + tuple_size(Qp16) == 16, tuple_size(Qp32) == 16, + tuple_size(Qp48) == 16, tuple_size(Qp64) == 16, + tuple_size(Qp80) == 16, tuple_size(Qp96) == 16, + tuple_size(Qp112) == 16, tuple_size(Qp128) == 16 -> + (((Pc =:= empty) or is_integer(Pc)) and queue:is_queue(Q0)); +is_queue(_) -> + false. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Determine the length of a priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec len(pqueue4()) -> non_neg_integer(). + +len({_, Size, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}) -> + Size. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Create a new priority queue.=== +%% O(1) +%% @end +%%------------------------------------------------------------------------- + +-spec new() -> pqueue4(). + +new() -> + {empty, % current priority + 0, % current size + erlang:make_tuple(16, queue:new()), % priority [-128..-113] + erlang:make_tuple(16, queue:new()), % priority [-112.. -97] + erlang:make_tuple(16, queue:new()), % priority [ -96.. -81] + erlang:make_tuple(16, queue:new()), % priority [ -80.. -65] + erlang:make_tuple(16, queue:new()), % priority [ -64.. -49] + erlang:make_tuple(16, queue:new()), % priority [ -48.. -33] + erlang:make_tuple(16, queue:new()), % priority [ -32.. -17] + erlang:make_tuple(16, queue:new()), % priority [ -16.. -1] + queue:new(), % priority 0 (default) + erlang:make_tuple(16, queue:new()), % priority [ 1.. 16] + erlang:make_tuple(16, queue:new()), % priority [ 17.. 32] + erlang:make_tuple(16, queue:new()), % priority [ 33.. 48] + erlang:make_tuple(16, queue:new()), % priority [ 49.. 64] + erlang:make_tuple(16, queue:new()), % priority [ 65.. 80] + erlang:make_tuple(16, queue:new()), % priority [ 81.. 96] + erlang:make_tuple(16, queue:new()), % priority [ 97.. 112] + erlang:make_tuple(16, queue:new())}. % priority [ 113.. 128] + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(pqueue4()) -> + {{'value', any()}, pqueue4()} | {'empty', pqueue4()}. + +out({empty, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +out({Pc, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + out_current(Pc, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item of a specific priority from the head of the queue.=== +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec out(integer(), pqueue4()) -> + {{'value', any()}, pqueue4()} | {'empty', pqueue4()}. + +out(P, _) + when P < -128; P > 128 -> + erlang:exit(badarg); +out(_, {empty, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +out(P, Q) -> + out_specific(P, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Take an item from the head of the priority queue.=== +%% Includes the priority in the return value. +%% O(1) amortized, O(N) worst case +%% @end +%%------------------------------------------------------------------------- + +-spec pout(pqueue4()) -> + {{'value', any(), integer()}, pqueue4()} | {'empty', pqueue4()}. + +pout({empty, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + {empty, Q}; +pout({Pc, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _} = Q) -> + out_current_p(Pc, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Remove a unique value from the priority queue with a binary predicate.=== +%% O(N) but smaller constant than filter/2 +%% @end +%%------------------------------------------------------------------------- + +-spec remove_unique(fun((any()) -> boolean()), pqueue4()) -> + {boolean(), pqueue4()}. + +remove_unique(F, {_, 0, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _} = Q) + when is_function(F, 1) -> + {false, Q}; +remove_unique(F, {Pc, _, _, _, _, _, _, _, _, _, + _, _, _, _, _, _, _, _, _} = Q) + when is_function(F, 1) -> + remove_unique_all(Pc, F, Q). + +remove_unique_all(128, F, Q) -> + remove_unique_p(128, F, Q); +remove_unique_all(P, F, Q) when is_integer(P) -> + case remove_unique_p(P, F, Q) of + {true, _} = Result -> + Result; + {false, Q} -> + remove_unique_all(P + 1, F, Q) + end. + +%%------------------------------------------------------------------------- +%% @doc +%% ===Remove a unique value in a specific priority within the priority queue with a binary predicate.=== +%% O(N) but smaller constant than filter/3 +%% @end +%%------------------------------------------------------------------------- + +-spec remove_unique(fun((any()) -> boolean()), integer(), pqueue4()) -> + {boolean(), pqueue4()}. + +remove_unique(_, P, _) + when P < -128; P > 128 -> + erlang:exit(badarg); +remove_unique(F, P, Q) when is_function(F, 1) -> + remove_unique_p(P, F, Q). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Convert the priority queue to a list.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec to_list(pqueue4()) -> list(). + +to_list(Q) -> + to_list([], out(Q)). +to_list(L, {empty, _}) -> + lists:reverse(L); +to_list(L, {{value, Value}, Q}) -> + to_list([Value | L], out(Q)). + +%%------------------------------------------------------------------------- +%% @doc +%% ===Convert the priority queue to a list with priorities.=== +%% O(N) +%% @end +%%------------------------------------------------------------------------- + +-spec to_plist(pqueue4()) -> list({priority(), list()}). + +to_plist(Q) -> + to_plist([], [], undefined, pout(Q)). +to_plist(L, [], _, {empty, _}) -> + lists:reverse(L); +to_plist(L, Lp, Pc, {empty, _}) -> + lists:reverse([{Pc, lists:reverse(Lp)} | L]); +to_plist(L, Lp, Pc, {{value, Value, Pc}, Q}) -> + to_plist(L, [Value | Lp], Pc, pout(Q)); +to_plist(L, [], _, {{value, Value, Pc}, Q}) -> + to_plist(L, [Value], Pc, pout(Q)); +to_plist(L, Lp, P, {{value, Value, Pc}, Q}) -> + to_plist([{P, lists:reverse(Lp)} | L], [Value], Pc, pout(Q)). + +%%------------------------------------------------------------------------- +%% @private +%% @doc +%% ===Regression test.=== +%% @end +%%------------------------------------------------------------------------- + +test() -> + Q0 = pqueue4:new(), + true = pqueue4:is_queue(Q0), + Q1 = pqueue4:in(20, 20, Q0), + Q2 = pqueue4:in(19, 19, Q1), + Q3 = pqueue4:in(18, 18, Q2), + Q4 = pqueue4:in(17, 17, Q3), + Q5 = pqueue4:in(16, 16, Q4), + Q6 = pqueue4:in(15, 15, Q5), + Q7 = pqueue4:in(14, 14, Q6), + Q8 = pqueue4:in(13, 13, Q7), + Q9 = pqueue4:in(12, 12, Q8), + Q10 = pqueue4:in(11, 11, Q9), + Q11 = pqueue4:in(10, 10, Q10), + Q12 = pqueue4:in(9, 9, Q11), + Q13 = pqueue4:in(8, 8, Q12), + Q14 = pqueue4:in(7, 7, Q13), + Q15 = pqueue4:in(6, 6, Q14), + Q16 = pqueue4:in(5, 5, Q15), + Q17 = pqueue4:in(4, 4, Q16), + Q18 = pqueue4:in(3, 3, Q17), + Q19 = pqueue4:in(2, 2, Q18), + Q20 = pqueue4:in(1, 1, Q19), + Q21 = pqueue4:in(0, 0, Q20), + Q22 = pqueue4:in(-1, -1, Q21), + Q23 = pqueue4:in(-2, -2, Q22), + Q24 = pqueue4:in(-3, -3, Q23), + Q25 = pqueue4:in(-4, -4, Q24), + Q26 = pqueue4:in(-5, -5, Q25), + Q27 = pqueue4:in(-6, -6, Q26), + Q28 = pqueue4:in(-7, -7, Q27), + Q29 = pqueue4:in(-8, -8, Q28), + Q30 = pqueue4:in(-9, -9, Q29), + Q31 = pqueue4:in(-10, -10, Q30), + Q32 = pqueue4:in(-11, -11, Q31), + Q33 = pqueue4:in(-12, -12, Q32), + Q34 = pqueue4:in(-13, -13, Q33), + Q35 = pqueue4:in(-14, -14, Q34), + Q36 = pqueue4:in(-15, -15, Q35), + Q37 = pqueue4:in(-16, -16, Q36), + Q38 = pqueue4:in(-17, -17, Q37), + Q39 = pqueue4:in(-18, -18, Q38), + Q40 = pqueue4:in(-19, -19, Q39), + Q41 = pqueue4:in(-20, -20, Q40), + Q42 = pqueue4:in(-20, -20, Q41), + Q43 = pqueue4:in(-19, -19, Q42), + Q44 = pqueue4:in(-18, -18, Q43), + Q45 = pqueue4:in(-17, -17, Q44), + Q46 = pqueue4:in(-16, -16, Q45), + Q47 = pqueue4:in(-15, -15, Q46), + Q48 = pqueue4:in(-14, -14, Q47), + Q49 = pqueue4:in(-13, -13, Q48), + Q50 = pqueue4:in(-12, -12, Q49), + Q51 = pqueue4:in(-11, -11, Q50), + Q52 = pqueue4:in(-10, -10, Q51), + Q53 = pqueue4:in(-9, -9, Q52), + Q54 = pqueue4:in(-8, -8, Q53), + Q55 = pqueue4:in(-7, -7, Q54), + Q56 = pqueue4:in(-6, -6, Q55), + Q57 = pqueue4:in(-5, -5, Q56), + Q58 = pqueue4:in(-4, -4, Q57), + Q59 = pqueue4:in(-3, -3, Q58), + Q60 = pqueue4:in(-2, -2, Q59), + Q61 = pqueue4:in(-1, -1, Q60), + Q62 = pqueue4:in(0, 0, Q61), + Q63 = pqueue4:in(1, 1, Q62), + Q64 = pqueue4:in(2, 2, Q63), + Q65 = pqueue4:in(3, 3, Q64), + Q66 = pqueue4:in(4, 4, Q65), + Q67 = pqueue4:in(5, 5, Q66), + Q68 = pqueue4:in(6, 6, Q67), + Q69 = pqueue4:in(7, 7, Q68), + Q70 = pqueue4:in(8, 8, Q69), + Q71 = pqueue4:in(9, 9, Q70), + Q72 = pqueue4:in(10, 10, Q71), + Q73 = pqueue4:in(11, 11, Q72), + Q74 = pqueue4:in(12, 12, Q73), + Q75 = pqueue4:in(13, 13, Q74), + Q76 = pqueue4:in(14, 14, Q75), + Q77 = pqueue4:in(15, 15, Q76), + Q78 = pqueue4:in(16, 16, Q77), + Q79 = pqueue4:in(17, 17, Q78), + Q80 = pqueue4:in(18, 18, Q79), + Q81 = pqueue4:in(19, 19, Q80), + Q82 = pqueue4:in(20, 20, Q81), + true = pqueue4:is_queue(Q82), + 82 = pqueue4:len(Q82), + [-20, -20, -19, -19, -18, -18, -17, -17, -16, -16, -15, -15, -14, -14, + -13, -13, -12, -12, -11, -11, -10, -10, -9, -9, -8, -8, -7, -7, -6, -6, + -5, -5, -4, -4, -3, -3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20] = pqueue4:to_list(Q82), + [{-20, [-20, -20]}, {-19, [-19, -19]}, {-18, [-18, -18]}, + {-17, [-17, -17]}, {-16, [-16, -16]}, {-15, [-15, -15]}, + {-14, [-14, -14]}, {-13, [-13, -13]}, {-12, [-12, -12]}, + {-11, [-11, -11]}, {-10, [-10, -10]}, {-9, [-9, -9]}, + {-8, [-8, -8]}, {-7, [-7, -7]}, {-6, [-6, -6]}, + {-5, [-5, -5]}, {-4, [-4, -4]}, {-3, [-3, -3]}, + {-2, [-2, -2]}, {-1, [-1, -1]}, {0, [0, 0]}, + {1, [1, 1]}, {2, [2, 2]}, {3, [3, 3]}, + {4, [4, 4]}, {5, [5, 5]}, {6, [6, 6]}, + {7, [7, 7]}, {8, [8, 8]}, {9, [9, 9]}, + {10, [10, 10]}, {11, [11, 11]}, {12, [12, 12]}, + {13, [13, 13]}, {14, [14, 14]}, {15, [15, 15]}, + {16, [16, 16]}, {17, [17, 17]}, {18, [18, 18]}, + {19, [19, 19]}, {20, [20, 20]}] = pqueue4:to_plist(Q82), + {{value, -20}, Q83} = pqueue4:out(Q82), + {{value, -20}, Q84} = pqueue4:out(Q83), + {{value, -19}, Q85} = pqueue4:out(Q84), + {{value, -19}, Q86} = pqueue4:out(Q85), + {{value, -18}, Q87} = pqueue4:out(Q86), + {{value, -18}, Q88} = pqueue4:out(Q87), + {{value, 0}, Q89} = pqueue4:out(0, Q88), + {{value, 0}, Q90} = pqueue4:out(0, Q89), + {empty, _} = pqueue4:out(0, Q90), + {{value, -17, -17}, Q91} = pqueue4:pout(Q90), + {{value, -17, -17}, Q92} = pqueue4:pout(Q91), + {{value, -16, -16}, Q93} = pqueue4:pout(Q92), + {{value, -16, -16}, Q94} = pqueue4:pout(Q93), + {{value, -15, -15}, Q95} = pqueue4:pout(Q94), + {{value, -15, -15}, Q96} = pqueue4:pout(Q95), + {{value, -14, -14}, Q97} = pqueue4:pout(Q96), + {{value, -14, -14}, Q98} = pqueue4:pout(Q97), + {{value, -13, -13}, Q99} = pqueue4:pout(Q98), + {{value, -13, -13}, Q100} = pqueue4:pout(Q99), + {{value, -12, -12}, Q101} = pqueue4:pout(Q100), + {{value, -12, -12}, Q102} = pqueue4:pout(Q101), + {{value, -11, -11}, Q103} = pqueue4:pout(Q102), + {{value, -11, -11}, Q104} = pqueue4:pout(Q103), + {{value, -10, -10}, Q105} = pqueue4:pout(Q104), + {{value, -10, -10}, Q106} = pqueue4:pout(Q105), + {{value, -9, -9}, Q107} = pqueue4:pout(Q106), + {{value, -9, -9}, Q108} = pqueue4:pout(Q107), + {{value, -8, -8}, Q109} = pqueue4:pout(Q108), + {{value, -8, -8}, Q110} = pqueue4:pout(Q109), + {{value, -7, -7}, Q111} = pqueue4:pout(Q110), + {{value, -7, -7}, Q112} = pqueue4:pout(Q111), + {{value, -6, -6}, Q113} = pqueue4:pout(Q112), + {{value, -6, -6}, Q114} = pqueue4:pout(Q113), + {{value, -5, -5}, Q115} = pqueue4:pout(Q114), + {{value, -5, -5}, Q116} = pqueue4:pout(Q115), + {{value, -4, -4}, Q117} = pqueue4:pout(Q116), + {{value, -4, -4}, Q118} = pqueue4:pout(Q117), + {{value, -3, -3}, Q119} = pqueue4:pout(Q118), + {{value, -3, -3}, Q120} = pqueue4:pout(Q119), + {{value, -2, -2}, Q121} = pqueue4:pout(Q120), + {{value, -2, -2}, Q122} = pqueue4:pout(Q121), + {{value, -1, -1}, Q123} = pqueue4:pout(Q122), + {{value, -1, -1}, Q124} = pqueue4:pout(Q123), + {{value, 1, 1}, Q125} = pqueue4:pout(Q124), + {{value, 1, 1}, Q126} = pqueue4:pout(Q125), + {{value, 2, 2}, Q127} = pqueue4:pout(Q126), + {{value, 2, 2}, Q128} = pqueue4:pout(Q127), + {{value, 3, 3}, Q129} = pqueue4:pout(Q128), + {{value, 3, 3}, Q130} = pqueue4:pout(Q129), + {{value, 4, 4}, Q131} = pqueue4:pout(Q130), + {{value, 4, 4}, Q132} = pqueue4:pout(Q131), + {{value, 5, 5}, Q133} = pqueue4:pout(Q132), + {{value, 5, 5}, Q134} = pqueue4:pout(Q133), + {{value, 6, 6}, Q135} = pqueue4:pout(Q134), + {{value, 6, 6}, Q136} = pqueue4:pout(Q135), + {{value, 7, 7}, Q137} = pqueue4:pout(Q136), + {{value, 7, 7}, Q138} = pqueue4:pout(Q137), + {{value, 8, 8}, Q139} = pqueue4:pout(Q138), + {{value, 8, 8}, Q140} = pqueue4:pout(Q139), + {{value, 9, 9}, Q141} = pqueue4:pout(Q140), + {{value, 9, 9}, Q142} = pqueue4:pout(Q141), + {{value, 10, 10}, Q143} = pqueue4:pout(Q142), + {{value, 10, 10}, Q144} = pqueue4:pout(Q143), + {{value, 11, 11}, Q145} = pqueue4:pout(Q144), + {{value, 11, 11}, Q146} = pqueue4:pout(Q145), + {{value, 12, 12}, Q147} = pqueue4:pout(Q146), + {{value, 12, 12}, Q148} = pqueue4:pout(Q147), + {{value, 13, 13}, Q149} = pqueue4:pout(Q148), + {{value, 13, 13}, Q150} = pqueue4:pout(Q149), + {{value, 14, 14}, Q151} = pqueue4:pout(Q150), + {{value, 14, 14}, Q152} = pqueue4:pout(Q151), + {{value, 15, 15}, Q153} = pqueue4:pout(Q152), + {{value, 15, 15}, Q154} = pqueue4:pout(Q153), + {{value, 16, 16}, Q155} = pqueue4:pout(Q154), + {{value, 16, 16}, Q156} = pqueue4:pout(Q155), + {{value, 17, 17}, Q157} = pqueue4:pout(Q156), + {{value, 17, 17}, Q158} = pqueue4:pout(Q157), + {{value, 18, 18}, Q159} = pqueue4:pout(Q158), + {{value, 18, 18}, Q160} = pqueue4:pout(Q159), + {{value, 19, 19}, Q161} = pqueue4:pout(Q160), + {{value, 19, 19}, Q162} = pqueue4:pout(Q161), + {{value, 20, 20}, Q163} = pqueue4:pout(Q162), + {{value, 20, 20}, Q164} = pqueue4:pout(Q163), + {{value, 20}, Q164} = pqueue4:out(Q163), + {{value, 20}, Q164} = pqueue4:out(20, Q163), + true = pqueue4:is_empty(Q164), + empty = erlang:element(1, Q164), % current priority + 0 = erlang:element(2, Q164), % size + {empty, Q164} = pqueue4:pout(Q164), + {empty, Q164} = pqueue4:out(Q164), + {empty, Q164} = pqueue4:out(20, Q164), + + Queue0 = queue:new(), + "{[],[]}" = lists:flatten(io_lib:format("~p", [Queue0])), + Queue1 = queue:in(1, Queue0), + Queue2 = queue:in(2, Queue1), + Queue3 = queue:in(3, Queue2), + {{value, 1}, _} = queue:out(Queue2), + "{[3,2],[1]}" = lists:flatten(io_lib:format("~p", [Queue3])), + {true, {[3],[1]}} = queue_remove_unique(fun(I) -> I == 2 end, {[3,2],[1]}), + Queue4 = queue:filter(fun(I) -> not (I == 2) end, Queue3), + "{[3],[1]}" = lists:flatten(io_lib:format("~p", [Queue4])), + 2 = queue:len(Queue4), + {{value, 1}, _} = queue:out(Queue4), + [1, 3] = queue:to_list(Queue4), + + Q166 = pqueue4:new(), + true = pqueue4:is_queue(Q166), + Q167 = pqueue4:in(6, 1, Q166), + Q168 = pqueue4:in(7, 1, Q167), + Q169 = pqueue4:in(8, 1, Q168), + Q170 = pqueue4:in(3, 0, Q169), + Q171 = pqueue4:in(4, 0, Q170), + Q172 = pqueue4:in(5, 0, Q171), + Q173 = pqueue4:in(0, -1, Q172), + Q174 = pqueue4:in(1, -1, Q173), + Q175 = pqueue4:in(2, -1, Q174), + [{-1, [0, 1, 2]}, {0, [3, 4, 5]}, {1, [6, 7, 8]}] = pqueue4:to_plist(Q175), + 3 = pqueue4:len(pqueue4:filter(fun(I) -> I > 5 end, Q175)), + 3 = pqueue4:len(pqueue4:filter(fun(I) -> I < 3 end, Q175)), + 3 = pqueue4:len(pqueue4:filter(fun(I) -> (I < 1) orelse (I > 6) end, Q175)), + {true, Q176} = pqueue4:remove_unique(fun(I) -> I == 4 end, Q175), + [{-1, [0, 1, 2]}, {0, [3, 5]}, {1, [6, 7, 8]}] = pqueue4:to_plist(Q176), + {true, Q177} = pqueue4:remove_unique(fun(I) -> I == 1 end, Q176), + [{-1, [0, 2]}, {0, [3, 5]}, {1, [6, 7, 8]}] = pqueue4:to_plist(Q177), + {true, Q178} = pqueue4:remove_unique(fun(I) -> I == 7 end, Q177), + [{-1, [0, 2]}, {0, [3, 5]}, {1, [6, 8]}] = pqueue4:to_plist(Q178), + 6 = pqueue4:len(Q178), + {{value, 0, -1}, Q179} = pqueue4:pout(Q178), + {{value, 2}, Q180} = pqueue4:out(Q179), + {{value, 6}, Q181} = pqueue4:out(1, Q180), + {false, Q181} = pqueue4:remove_unique(fun(I) -> I == 7 end, Q181), + [{0, [3, 5]}, {1, [8]}] = pqueue4:to_plist(Q181), + {true, Q182} = pqueue4:remove_unique(fun(I) -> I == 5 end, Q181), + {true, Q183} = pqueue4:remove_unique(fun(I) -> I == 8 end, 1, Q182), + {true, Q184} = pqueue4:remove_unique(fun(I) -> I == 3 end, Q183), + {empty, Q184} = pqueue4:pout(Q184), + {empty, Q184} = pqueue4:out(Q184), + {empty, Q184} = pqueue4:out(0, Q184), + ok. + +%%%------------------------------------------------------------------------ +%%% Private functions +%%%------------------------------------------------------------------------ + +%% @hidden +-define(FILTER_P_Qn128(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + V3, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn112(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, + V3, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn96(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, + V3, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn80(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, + V3, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn64(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, + V3, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn48(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, + V3, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn32(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V3, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qn16(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V3, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp16(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V3, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp32(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V3, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp48(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V3, + Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp64(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V3, + Qp80, Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp80(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V3, + Qp96, Qp112, Qp128}). +-define(FILTER_P_Qp96(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V3, + Qp112, Qp128}). +-define(FILTER_P_Qp112(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V3, + Qp128}). +-define(FILTER_P_Qp128(P, V1, V2, V3), +filter_priority(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}) -> + V2 = queue:filter(F, V1), + NewSize = Size - (queue:len(V1) - queue:len(V2)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V3}). + +?FILTER_P_Qn128(-128, + Qn128, NewQn128, + {NewQn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-127, + Qn127, NewQn127, + {Qn128, NewQn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-126, + Qn126, NewQn126, + {Qn128, Qn127, NewQn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-125, + Qn125, NewQn125, + {Qn128, Qn127, Qn126, NewQn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-124, + Qn124, NewQn124, + {Qn128, Qn127, Qn126, Qn125, NewQn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-123, + Qn123, NewQn123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + NewQn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-122, + Qn122, NewQn122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, NewQn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-121, + Qn121, NewQn121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, NewQn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-120, + Qn120, NewQn120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, NewQn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-119, + Qn119, NewQn119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, NewQn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-118, + Qn118, NewQn118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, NewQn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-117, + Qn117, NewQn117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + NewQn117, Qn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-116, + Qn116, NewQn116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, NewQn116, Qn115, Qn114, Qn113}); +?FILTER_P_Qn128(-115, + Qn115, NewQn115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, NewQn115, Qn114, Qn113}); +?FILTER_P_Qn128(-114, + Qn114, NewQn114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, NewQn114, Qn113}); +?FILTER_P_Qn128(-113, + Qn113, NewQn113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, NewQn113}); +?FILTER_P_Qn112(-112, + Qn112, NewQn112, + {NewQn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-111, + Qn111, NewQn111, + {Qn112, NewQn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-110, + Qn110, NewQn110, + {Qn112, Qn111, NewQn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-109, + Qn109, NewQn109, + {Qn112, Qn111, Qn110, NewQn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-108, + Qn108, NewQn108, + {Qn112, Qn111, Qn110, Qn109, NewQn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-107, + Qn107, NewQn107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + NewQn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-106, + Qn106, NewQn106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, NewQn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-105, + Qn105, NewQn105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, NewQn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-104, + Qn104, NewQn104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, NewQn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-103, + Qn103, NewQn103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, NewQn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-102, + Qn102, NewQn102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, NewQn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-101, + Qn101, NewQn101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + NewQn101, Qn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-100, + Qn100, NewQn100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, NewQn100, Qn99, Qn98, Qn97}); +?FILTER_P_Qn112(-99, + Qn99, NewQn99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, NewQn99, Qn98, Qn97}); +?FILTER_P_Qn112(-98, + Qn98, NewQn98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, NewQn98, Qn97}); +?FILTER_P_Qn112(-97, + Qn97, NewQn97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, NewQn97}); +?FILTER_P_Qn96(-96, + Qn96, NewQn96, + {NewQn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-95, + Qn95, NewQn95, + {Qn96, NewQn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-94, + Qn94, NewQn94, + {Qn96, Qn95, NewQn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-93, + Qn93, NewQn93, + {Qn96, Qn95, Qn94, NewQn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-92, + Qn92, NewQn92, + {Qn96, Qn95, Qn94, Qn93, NewQn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-91, + Qn91, NewQn91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + NewQn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-90, + Qn90, NewQn90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, NewQn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-89, + Qn89, NewQn89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, NewQn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-88, + Qn88, NewQn88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, NewQn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-87, + Qn87, NewQn87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, NewQn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-86, + Qn86, NewQn86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, NewQn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-85, + Qn85, NewQn85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + NewQn85, Qn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-84, + Qn84, NewQn84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, NewQn84, Qn83, Qn82, Qn81}); +?FILTER_P_Qn96(-83, + Qn83, NewQn83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, NewQn83, Qn82, Qn81}); +?FILTER_P_Qn96(-82, + Qn82, NewQn82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, NewQn82, Qn81}); +?FILTER_P_Qn96(-81, + Qn81, NewQn81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, NewQn81}); +?FILTER_P_Qn80(-80, + Qn80, NewQn80, + {NewQn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-79, + Qn79, NewQn79, + {Qn80, NewQn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-78, + Qn78, NewQn78, + {Qn80, Qn79, NewQn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-77, + Qn77, NewQn77, + {Qn80, Qn79, Qn78, NewQn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-76, + Qn76, NewQn76, + {Qn80, Qn79, Qn78, Qn77, NewQn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-75, + Qn75, NewQn75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + NewQn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-74, + Qn74, NewQn74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, NewQn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-73, + Qn73, NewQn73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, NewQn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-72, + Qn72, NewQn72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, NewQn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-71, + Qn71, NewQn71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, NewQn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-70, + Qn70, NewQn70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, NewQn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-69, + Qn69, NewQn69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + NewQn69, Qn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-68, + Qn68, NewQn68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, NewQn68, Qn67, Qn66, Qn65}); +?FILTER_P_Qn80(-67, + Qn67, NewQn67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, NewQn67, Qn66, Qn65}); +?FILTER_P_Qn80(-66, + Qn66, NewQn66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, NewQn66, Qn65}); +?FILTER_P_Qn80(-65, + Qn65, NewQn65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, NewQn65}); +?FILTER_P_Qn64(-64, + Qn64, NewQn64, + {NewQn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-63, + Qn63, NewQn63, + {Qn64, NewQn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-62, + Qn62, NewQn62, + {Qn64, Qn63, NewQn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-61, + Qn61, NewQn61, + {Qn64, Qn63, Qn62, NewQn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-60, + Qn60, NewQn60, + {Qn64, Qn63, Qn62, Qn61, NewQn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-59, + Qn59, NewQn59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + NewQn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-58, + Qn58, NewQn58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, NewQn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-57, + Qn57, NewQn57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, NewQn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-56, + Qn56, NewQn56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, NewQn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-55, + Qn55, NewQn55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, NewQn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-54, + Qn54, NewQn54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, NewQn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-53, + Qn53, NewQn53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + NewQn53, Qn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-52, + Qn52, NewQn52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, NewQn52, Qn51, Qn50, Qn49}); +?FILTER_P_Qn64(-51, + Qn51, NewQn51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, NewQn51, Qn50, Qn49}); +?FILTER_P_Qn64(-50, + Qn50, NewQn50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, NewQn50, Qn49}); +?FILTER_P_Qn64(-49, + Qn49, NewQn49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, NewQn49}); +?FILTER_P_Qn48(-48, + Qn48, NewQn48, + {NewQn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-47, + Qn47, NewQn47, + {Qn48, NewQn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-46, + Qn46, NewQn46, + {Qn48, Qn47, NewQn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-45, + Qn45, NewQn45, + {Qn48, Qn47, Qn46, NewQn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-44, + Qn44, NewQn44, + {Qn48, Qn47, Qn46, Qn45, NewQn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-43, + Qn43, NewQn43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + NewQn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-42, + Qn42, NewQn42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, NewQn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-41, + Qn41, NewQn41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, NewQn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-40, + Qn40, NewQn40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, NewQn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-39, + Qn39, NewQn39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, NewQn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-38, + Qn38, NewQn38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, NewQn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-37, + Qn37, NewQn37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + NewQn37, Qn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-36, + Qn36, NewQn36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, NewQn36, Qn35, Qn34, Qn33}); +?FILTER_P_Qn48(-35, + Qn35, NewQn35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, NewQn35, Qn34, Qn33}); +?FILTER_P_Qn48(-34, + Qn34, NewQn34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, NewQn34, Qn33}); +?FILTER_P_Qn48(-33, + Qn33, NewQn33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, NewQn33}); +?FILTER_P_Qn32(-32, + Qn32, NewQn32, + {NewQn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-31, + Qn31, NewQn31, + {Qn32, NewQn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-30, + Qn30, NewQn30, + {Qn32, Qn31, NewQn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-29, + Qn29, NewQn29, + {Qn32, Qn31, Qn30, NewQn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-28, + Qn28, NewQn28, + {Qn32, Qn31, Qn30, Qn29, NewQn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-27, + Qn27, NewQn27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + NewQn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-26, + Qn26, NewQn26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, NewQn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-25, + Qn25, NewQn25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, NewQn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-24, + Qn24, NewQn24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, NewQn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-23, + Qn23, NewQn23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, NewQn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-22, + Qn22, NewQn22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, NewQn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-21, + Qn21, NewQn21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + NewQn21, Qn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-20, + Qn20, NewQn20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, NewQn20, Qn19, Qn18, Qn17}); +?FILTER_P_Qn32(-19, + Qn19, NewQn19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, NewQn19, Qn18, Qn17}); +?FILTER_P_Qn32(-18, + Qn18, NewQn18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, NewQn18, Qn17}); +?FILTER_P_Qn32(-17, + Qn17, NewQn17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, NewQn17}); +?FILTER_P_Qn16(-16, + Qn16, NewQn16, + {NewQn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-15, + Qn15, NewQn15, + {Qn16, NewQn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-14, + Qn14, NewQn14, + {Qn16, Qn15, NewQn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-13, + Qn13, NewQn13, + {Qn16, Qn15, Qn14, NewQn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-12, + Qn12, NewQn12, + {Qn16, Qn15, Qn14, Qn13, NewQn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-11, + Qn11, NewQn11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + NewQn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-10, + Qn10, NewQn10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, NewQn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-9, + Qn9, NewQn9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, NewQn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-8, + Qn8, NewQn8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, NewQn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-7, + Qn7, NewQn7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, NewQn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-6, + Qn6, NewQn6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, NewQn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-5, + Qn5, NewQn5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + NewQn5, Qn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-4, + Qn4, NewQn4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, NewQn4, Qn3, Qn2, Qn1}); +?FILTER_P_Qn16(-3, + Qn3, NewQn3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, NewQn3, Qn2, Qn1}); +?FILTER_P_Qn16(-2, + Qn2, NewQn2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, NewQn2, Qn1}); +?FILTER_P_Qn16(-1, + Qn1, NewQn1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, NewQn1}); +filter_priority(0, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + NewQ0 = queue:filter(F, Q0), + NewSize = Size - (queue:len(Q0) - queue:len(NewQ0)), + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + NewQ0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}; +?FILTER_P_Qp16(1, + Qp1, NewQp1, + {NewQp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(2, + Qp2, NewQp2, + {Qp1, NewQp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(3, + Qp3, NewQp3, + {Qp1, Qp2, NewQp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(4, + Qp4, NewQp4, + {Qp1, Qp2, Qp3, NewQp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(5, + Qp5, NewQp5, + {Qp1, Qp2, Qp3, Qp4, NewQp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(6, + Qp6, NewQp6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + NewQp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(7, + Qp7, NewQp7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, NewQp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(8, + Qp8, NewQp8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, NewQp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(9, + Qp9, NewQp9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, NewQp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(10, + Qp10, NewQp10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, NewQp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(11, + Qp11, NewQp11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, NewQp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(12, + Qp12, NewQp12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + NewQp12, Qp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(13, + Qp13, NewQp13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, NewQp13, Qp14, Qp15, Qp16}); +?FILTER_P_Qp16(14, + Qp14, NewQp14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, NewQp14, Qp15, Qp16}); +?FILTER_P_Qp16(15, + Qp15, NewQp15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, NewQp15, Qp16}); +?FILTER_P_Qp16(16, + Qp16, NewQp16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, NewQp16}); +?FILTER_P_Qp32(17, + Qp17, NewQp17, + {NewQp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(18, + Qp18, NewQp18, + {Qp17, NewQp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(19, + Qp19, NewQp19, + {Qp17, Qp18, NewQp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(20, + Qp20, NewQp20, + {Qp17, Qp18, Qp19, NewQp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(21, + Qp21, NewQp21, + {Qp17, Qp18, Qp19, Qp20, NewQp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(22, + Qp22, NewQp22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + NewQp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(23, + Qp23, NewQp23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, NewQp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(24, + Qp24, NewQp24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, NewQp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(25, + Qp25, NewQp25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, NewQp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(26, + Qp26, NewQp26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, NewQp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(27, + Qp27, NewQp27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, NewQp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(28, + Qp28, NewQp28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + NewQp28, Qp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(29, + Qp29, NewQp29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, NewQp29, Qp30, Qp31, Qp32}); +?FILTER_P_Qp32(30, + Qp30, NewQp30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, NewQp30, Qp31, Qp32}); +?FILTER_P_Qp32(31, + Qp31, NewQp31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, NewQp31, Qp32}); +?FILTER_P_Qp32(32, + Qp32, NewQp32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, NewQp32}); +?FILTER_P_Qp48(33, + Qp33, NewQp33, + {NewQp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(34, + Qp34, NewQp34, + {Qp33, NewQp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(35, + Qp35, NewQp35, + {Qp33, Qp34, NewQp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(36, + Qp36, NewQp36, + {Qp33, Qp34, Qp35, NewQp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(37, + Qp37, NewQp37, + {Qp33, Qp34, Qp35, Qp36, NewQp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(38, + Qp38, NewQp38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + NewQp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(39, + Qp39, NewQp39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, NewQp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(40, + Qp40, NewQp40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, NewQp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(41, + Qp41, NewQp41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, NewQp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(42, + Qp42, NewQp42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, NewQp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(43, + Qp43, NewQp43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, NewQp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(44, + Qp44, NewQp44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + NewQp44, Qp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(45, + Qp45, NewQp45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, NewQp45, Qp46, Qp47, Qp48}); +?FILTER_P_Qp48(46, + Qp46, NewQp46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, NewQp46, Qp47, Qp48}); +?FILTER_P_Qp48(47, + Qp47, NewQp47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, NewQp47, Qp48}); +?FILTER_P_Qp48(48, + Qp48, NewQp48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, NewQp48}); +?FILTER_P_Qp64(49, + Qp49, NewQp49, + {NewQp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(50, + Qp50, NewQp50, + {Qp49, NewQp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(51, + Qp51, NewQp51, + {Qp49, Qp50, NewQp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(52, + Qp52, NewQp52, + {Qp49, Qp50, Qp51, NewQp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(53, + Qp53, NewQp53, + {Qp49, Qp50, Qp51, Qp52, NewQp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(54, + Qp54, NewQp54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + NewQp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(55, + Qp55, NewQp55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, NewQp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(56, + Qp56, NewQp56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, NewQp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(57, + Qp57, NewQp57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, NewQp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(58, + Qp58, NewQp58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, NewQp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(59, + Qp59, NewQp59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, NewQp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(60, + Qp60, NewQp60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + NewQp60, Qp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(61, + Qp61, NewQp61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, NewQp61, Qp62, Qp63, Qp64}); +?FILTER_P_Qp64(62, + Qp62, NewQp62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, NewQp62, Qp63, Qp64}); +?FILTER_P_Qp64(63, + Qp63, NewQp63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, NewQp63, Qp64}); +?FILTER_P_Qp64(64, + Qp64, NewQp64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, NewQp64}); +?FILTER_P_Qp80(65, + Qp65, NewQp65, + {NewQp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(66, + Qp66, NewQp66, + {Qp65, NewQp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(67, + Qp67, NewQp67, + {Qp65, Qp66, NewQp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(68, + Qp68, NewQp68, + {Qp65, Qp66, Qp67, NewQp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(69, + Qp69, NewQp69, + {Qp65, Qp66, Qp67, Qp68, NewQp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(70, + Qp70, NewQp70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + NewQp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(71, + Qp71, NewQp71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, NewQp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(72, + Qp72, NewQp72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, NewQp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(73, + Qp73, NewQp73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, NewQp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(74, + Qp74, NewQp74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, NewQp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(75, + Qp75, NewQp75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, NewQp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(76, + Qp76, NewQp76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + NewQp76, Qp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(77, + Qp77, NewQp77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, NewQp77, Qp78, Qp79, Qp80}); +?FILTER_P_Qp80(78, + Qp78, NewQp78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, NewQp78, Qp79, Qp80}); +?FILTER_P_Qp80(79, + Qp79, NewQp79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, NewQp79, Qp80}); +?FILTER_P_Qp80(80, + Qp80, NewQp80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, NewQp80}); +?FILTER_P_Qp96(81, + Qp81, NewQp81, + {NewQp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(82, + Qp82, NewQp82, + {Qp81, NewQp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(83, + Qp83, NewQp83, + {Qp81, Qp82, NewQp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(84, + Qp84, NewQp84, + {Qp81, Qp82, Qp83, NewQp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(85, + Qp85, NewQp85, + {Qp81, Qp82, Qp83, Qp84, NewQp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(86, + Qp86, NewQp86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + NewQp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(87, + Qp87, NewQp87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, NewQp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(88, + Qp88, NewQp88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, NewQp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(89, + Qp89, NewQp89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, NewQp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(90, + Qp90, NewQp90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, NewQp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(91, + Qp91, NewQp91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, NewQp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(92, + Qp92, NewQp92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + NewQp92, Qp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(93, + Qp93, NewQp93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, NewQp93, Qp94, Qp95, Qp96}); +?FILTER_P_Qp96(94, + Qp94, NewQp94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, NewQp94, Qp95, Qp96}); +?FILTER_P_Qp96(95, + Qp95, NewQp95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, NewQp95, Qp96}); +?FILTER_P_Qp96(96, + Qp96, NewQp96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, NewQp96}); +?FILTER_P_Qp112(97, + Qp97, NewQp97, + {NewQp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(98, + Qp98, NewQp98, + {Qp97, NewQp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(99, + Qp99, NewQp99, + {Qp97, Qp98, NewQp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(100, + Qp100, NewQp100, + {Qp97, Qp98, Qp99, NewQp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(101, + Qp101, NewQp101, + {Qp97, Qp98, Qp99, Qp100, NewQp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(102, + Qp102, NewQp102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + NewQp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(103, + Qp103, NewQp103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, NewQp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(104, + Qp104, NewQp104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, NewQp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(105, + Qp105, NewQp105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, NewQp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(106, + Qp106, NewQp106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, NewQp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(107, + Qp107, NewQp107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, NewQp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(108, + Qp108, NewQp108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + NewQp108, Qp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(109, + Qp109, NewQp109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, NewQp109, Qp110, Qp111, Qp112}); +?FILTER_P_Qp112(110, + Qp110, NewQp110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, NewQp110, Qp111, Qp112}); +?FILTER_P_Qp112(111, + Qp111, NewQp111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, NewQp111, Qp112}); +?FILTER_P_Qp112(112, + Qp112, NewQp112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, NewQp112}); +?FILTER_P_Qp128(113, + Qp113, NewQp113, + {NewQp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(114, + Qp114, NewQp114, + {Qp113, NewQp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(115, + Qp115, NewQp115, + {Qp113, Qp114, NewQp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(116, + Qp116, NewQp116, + {Qp113, Qp114, Qp115, NewQp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(117, + Qp117, NewQp117, + {Qp113, Qp114, Qp115, Qp116, NewQp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(118, + Qp118, NewQp118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + NewQp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(119, + Qp119, NewQp119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, NewQp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(120, + Qp120, NewQp120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, NewQp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(121, + Qp121, NewQp121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, NewQp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(122, + Qp122, NewQp122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, NewQp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(123, + Qp123, NewQp123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, NewQp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(124, + Qp124, NewQp124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + NewQp124, Qp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(125, + Qp125, NewQp125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, NewQp125, Qp126, Qp127, Qp128}); +?FILTER_P_Qp128(126, + Qp126, NewQp126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, NewQp126, Qp127, Qp128}); +?FILTER_P_Qp128(127, + Qp127, NewQp127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, NewQp127, Qp128}); +?FILTER_P_Qp128(128, + Qp128, NewQp128, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, NewQp128}). + +%% @hidden +-define(IN_HIGHER_Qn128(P, V), +in_higher(P, + {_, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + V, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn112(P, V), +in_higher(P, + {_, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, + V, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn96(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, + V, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn80(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, + V, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn64(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, + V, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn48(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, + V, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn32(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qn16(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp16(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp32(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp48(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V, + Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp64(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V, + Qp80, Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp80(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V, + Qp96, Qp112, Qp128}). +-define(IN_HIGHER_Qp96(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V, + Qp112, Qp128}). +-define(IN_HIGHER_Qp112(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V, + Qp128}). +-define(IN_HIGHER_Qp128(P, V), +in_higher(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}, X) -> + {P, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V}). + +?IN_HIGHER_Qn128(-128, + {queue:in(X, Qn128), Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-127, + {Qn128, queue:in(X, Qn127), Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-126, + {Qn128, Qn127, queue:in(X, Qn126), Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-125, + {Qn128, Qn127, Qn126, queue:in(X, Qn125), Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-124, + {Qn128, Qn127, Qn126, Qn125, queue:in(X, Qn124), + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + queue:in(X, Qn123), Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, queue:in(X, Qn122), Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, queue:in(X, Qn121), Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, queue:in(X, Qn120), Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, queue:in(X, Qn119), Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, queue:in(X, Qn118), + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + queue:in(X, Qn117), Qn116, Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, queue:in(X, Qn116), Qn115, Qn114, Qn113}); +?IN_HIGHER_Qn128(-115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, queue:in(X, Qn115), Qn114, Qn113}); +?IN_HIGHER_Qn128(-114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, queue:in(X, Qn114), Qn113}); +?IN_HIGHER_Qn128(-113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, queue:in(X, Qn113)}); +?IN_HIGHER_Qn112(-112, + {queue:in(X, Qn112), Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-111, + {Qn112, queue:in(X, Qn111), Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-110, + {Qn112, Qn111, queue:in(X, Qn110), Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-109, + {Qn112, Qn111, Qn110, queue:in(X, Qn109), Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-108, + {Qn112, Qn111, Qn110, Qn109, queue:in(X, Qn108), + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + queue:in(X, Qn107), Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, queue:in(X, Qn106), Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, queue:in(X, Qn105), Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, queue:in(X, Qn104), Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, queue:in(X, Qn103), Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, queue:in(X, Qn102), + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + queue:in(X, Qn101), Qn100, Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, queue:in(X, Qn100), Qn99, Qn98, Qn97}); +?IN_HIGHER_Qn112(-99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, queue:in(X, Qn99), Qn98, Qn97}); +?IN_HIGHER_Qn112(-98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, queue:in(X, Qn98), Qn97}); +?IN_HIGHER_Qn112(-97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, queue:in(X, Qn97)}); +?IN_HIGHER_Qn96(-96, + {queue:in(X, Qn96), Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-95, + {Qn96, queue:in(X, Qn95), Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-94, + {Qn96, Qn95, queue:in(X, Qn94), Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-93, + {Qn96, Qn95, Qn94, queue:in(X, Qn93), Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-92, + {Qn96, Qn95, Qn94, Qn93, queue:in(X, Qn92), + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + queue:in(X, Qn91), Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, queue:in(X, Qn90), Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, queue:in(X, Qn89), Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, queue:in(X, Qn88), Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, queue:in(X, Qn87), Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, queue:in(X, Qn86), + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + queue:in(X, Qn85), Qn84, Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, queue:in(X, Qn84), Qn83, Qn82, Qn81}); +?IN_HIGHER_Qn96(-83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, queue:in(X, Qn83), Qn82, Qn81}); +?IN_HIGHER_Qn96(-82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, queue:in(X, Qn82), Qn81}); +?IN_HIGHER_Qn96(-81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, queue:in(X, Qn81)}); +?IN_HIGHER_Qn80(-80, + {queue:in(X, Qn80), Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-79, + {Qn80, queue:in(X, Qn79), Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-78, + {Qn80, Qn79, queue:in(X, Qn78), Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-77, + {Qn80, Qn79, Qn78, queue:in(X, Qn77), Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-76, + {Qn80, Qn79, Qn78, Qn77, queue:in(X, Qn76), + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + queue:in(X, Qn75), Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, queue:in(X, Qn74), Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, queue:in(X, Qn73), Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, queue:in(X, Qn72), Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, queue:in(X, Qn71), Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, queue:in(X, Qn70), + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + queue:in(X, Qn69), Qn68, Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, queue:in(X, Qn68), Qn67, Qn66, Qn65}); +?IN_HIGHER_Qn80(-67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, queue:in(X, Qn67), Qn66, Qn65}); +?IN_HIGHER_Qn80(-66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, queue:in(X, Qn66), Qn65}); +?IN_HIGHER_Qn80(-65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, queue:in(X, Qn65)}); +?IN_HIGHER_Qn64(-64, + {queue:in(X, Qn64), Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-63, + {Qn64, queue:in(X, Qn63), Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-62, + {Qn64, Qn63, queue:in(X, Qn62), Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-61, + {Qn64, Qn63, Qn62, queue:in(X, Qn61), Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-60, + {Qn64, Qn63, Qn62, Qn61, queue:in(X, Qn60), + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + queue:in(X, Qn59), Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, queue:in(X, Qn58), Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, queue:in(X, Qn57), Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, queue:in(X, Qn56), Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, queue:in(X, Qn55), Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, queue:in(X, Qn54), + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + queue:in(X, Qn53), Qn52, Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, queue:in(X, Qn52), Qn51, Qn50, Qn49}); +?IN_HIGHER_Qn64(-51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, queue:in(X, Qn51), Qn50, Qn49}); +?IN_HIGHER_Qn64(-50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, queue:in(X, Qn50), Qn49}); +?IN_HIGHER_Qn64(-49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, queue:in(X, Qn49)}); +?IN_HIGHER_Qn48(-48, + {queue:in(X, Qn48), Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-47, + {Qn48, queue:in(X, Qn47), Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-46, + {Qn48, Qn47, queue:in(X, Qn46), Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-45, + {Qn48, Qn47, Qn46, queue:in(X, Qn45), Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-44, + {Qn48, Qn47, Qn46, Qn45, queue:in(X, Qn44), + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + queue:in(X, Qn43), Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, queue:in(X, Qn42), Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, queue:in(X, Qn41), Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, queue:in(X, Qn40), Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, queue:in(X, Qn39), Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, queue:in(X, Qn38), + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + queue:in(X, Qn37), Qn36, Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, queue:in(X, Qn36), Qn35, Qn34, Qn33}); +?IN_HIGHER_Qn48(-35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, queue:in(X, Qn35), Qn34, Qn33}); +?IN_HIGHER_Qn48(-34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, queue:in(X, Qn34), Qn33}); +?IN_HIGHER_Qn48(-33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, queue:in(X, Qn33)}); +?IN_HIGHER_Qn32(-32, + {queue:in(X, Qn32), Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-31, + {Qn32, queue:in(X, Qn31), Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-30, + {Qn32, Qn31, queue:in(X, Qn30), Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-29, + {Qn32, Qn31, Qn30, queue:in(X, Qn29), Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-28, + {Qn32, Qn31, Qn30, Qn29, queue:in(X, Qn28), + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + queue:in(X, Qn27), Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, queue:in(X, Qn26), Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, queue:in(X, Qn25), Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, queue:in(X, Qn24), Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, queue:in(X, Qn23), Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, queue:in(X, Qn22), + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + queue:in(X, Qn21), Qn20, Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, queue:in(X, Qn20), Qn19, Qn18, Qn17}); +?IN_HIGHER_Qn32(-19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, queue:in(X, Qn19), Qn18, Qn17}); +?IN_HIGHER_Qn32(-18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, queue:in(X, Qn18), Qn17}); +?IN_HIGHER_Qn32(-17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, queue:in(X, Qn17)}); +?IN_HIGHER_Qn16(-16, + {queue:in(X, Qn16), Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-15, + {Qn16, queue:in(X, Qn15), Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-14, + {Qn16, Qn15, queue:in(X, Qn14), Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-13, + {Qn16, Qn15, Qn14, queue:in(X, Qn13), Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-12, + {Qn16, Qn15, Qn14, Qn13, queue:in(X, Qn12), + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + queue:in(X, Qn11), Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, queue:in(X, Qn10), Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, queue:in(X, Qn9), Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, queue:in(X, Qn8), Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, queue:in(X, Qn7), Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, queue:in(X, Qn6), + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + queue:in(X, Qn5), Qn4, Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, queue:in(X, Qn4), Qn3, Qn2, Qn1}); +?IN_HIGHER_Qn16(-3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, queue:in(X, Qn3), Qn2, Qn1}); +?IN_HIGHER_Qn16(-2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, queue:in(X, Qn2), Qn1}); +?IN_HIGHER_Qn16(-1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, queue:in(X, Qn1)}); +in_higher(0, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {0, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + queue:in(X, Q0), + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}; +?IN_HIGHER_Qp16(1, + {queue:in(X, Qp1), Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(2, + {Qp1, queue:in(X, Qp2), Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(3, + {Qp1, Qp2, queue:in(X, Qp3), Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(4, + {Qp1, Qp2, Qp3, queue:in(X, Qp4), Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(5, + {Qp1, Qp2, Qp3, Qp4, queue:in(X, Qp5), + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + queue:in(X, Qp6), Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, queue:in(X, Qp7), Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, queue:in(X, Qp8), Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, queue:in(X, Qp9), Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, queue:in(X, Qp10), Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, queue:in(X, Qp11), + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + queue:in(X, Qp12), Qp13, Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, queue:in(X, Qp13), Qp14, Qp15, Qp16}); +?IN_HIGHER_Qp16(14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, queue:in(X, Qp14), Qp15, Qp16}); +?IN_HIGHER_Qp16(15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, queue:in(X, Qp15), Qp16}); +?IN_HIGHER_Qp16(16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, queue:in(X, Qp16)}); +?IN_HIGHER_Qp32(17, + {queue:in(X, Qp17), Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(18, + {Qp17, queue:in(X, Qp18), Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(19, + {Qp17, Qp18, queue:in(X, Qp19), Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(20, + {Qp17, Qp18, Qp19, queue:in(X, Qp20), Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(21, + {Qp17, Qp18, Qp19, Qp20, queue:in(X, Qp21), + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + queue:in(X, Qp22), Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, queue:in(X, Qp23), Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, queue:in(X, Qp24), Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, queue:in(X, Qp25), Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, queue:in(X, Qp26), Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, queue:in(X, Qp27), + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + queue:in(X, Qp28), Qp29, Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, queue:in(X, Qp29), Qp30, Qp31, Qp32}); +?IN_HIGHER_Qp32(30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, queue:in(X, Qp30), Qp31, Qp32}); +?IN_HIGHER_Qp32(31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, queue:in(X, Qp31), Qp32}); +?IN_HIGHER_Qp32(32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, queue:in(X, Qp32)}); +?IN_HIGHER_Qp48(33, + {queue:in(X, Qp33), Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(34, + {Qp33, queue:in(X, Qp34), Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(35, + {Qp33, Qp34, queue:in(X, Qp35), Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(36, + {Qp33, Qp34, Qp35, queue:in(X, Qp36), Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(37, + {Qp33, Qp34, Qp35, Qp36, queue:in(X, Qp37), + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + queue:in(X, Qp38), Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, queue:in(X, Qp39), Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, queue:in(X, Qp40), Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, queue:in(X, Qp41), Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, queue:in(X, Qp42), Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, queue:in(X, Qp43), + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + queue:in(X, Qp44), Qp45, Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, queue:in(X, Qp45), Qp46, Qp47, Qp48}); +?IN_HIGHER_Qp48(46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, queue:in(X, Qp46), Qp47, Qp48}); +?IN_HIGHER_Qp48(47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, queue:in(X, Qp47), Qp48}); +?IN_HIGHER_Qp48(48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, queue:in(X, Qp48)}); +?IN_HIGHER_Qp64(49, + {queue:in(X, Qp49), Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(50, + {Qp49, queue:in(X, Qp50), Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(51, + {Qp49, Qp50, queue:in(X, Qp51), Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(52, + {Qp49, Qp50, Qp51, queue:in(X, Qp52), Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(53, + {Qp49, Qp50, Qp51, Qp52, queue:in(X, Qp53), + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + queue:in(X, Qp54), Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, queue:in(X, Qp55), Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, queue:in(X, Qp56), Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, queue:in(X, Qp57), Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, queue:in(X, Qp58), Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, queue:in(X, Qp59), + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + queue:in(X, Qp60), Qp61, Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, queue:in(X, Qp61), Qp62, Qp63, Qp64}); +?IN_HIGHER_Qp64(62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, queue:in(X, Qp62), Qp63, Qp64}); +?IN_HIGHER_Qp64(63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, queue:in(X, Qp63), Qp64}); +?IN_HIGHER_Qp64(64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, queue:in(X, Qp64)}); +?IN_HIGHER_Qp80(65, + {queue:in(X, Qp65), Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(66, + {Qp65, queue:in(X, Qp66), Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(67, + {Qp65, Qp66, queue:in(X, Qp67), Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(68, + {Qp65, Qp66, Qp67, queue:in(X, Qp68), Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(69, + {Qp65, Qp66, Qp67, Qp68, queue:in(X, Qp69), + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + queue:in(X, Qp70), Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, queue:in(X, Qp71), Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, queue:in(X, Qp72), Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, queue:in(X, Qp73), Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, queue:in(X, Qp74), Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, queue:in(X, Qp75), + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + queue:in(X, Qp76), Qp77, Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, queue:in(X, Qp77), Qp78, Qp79, Qp80}); +?IN_HIGHER_Qp80(78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, queue:in(X, Qp78), Qp79, Qp80}); +?IN_HIGHER_Qp80(79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, queue:in(X, Qp79), Qp80}); +?IN_HIGHER_Qp80(80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, queue:in(X, Qp80)}); +?IN_HIGHER_Qp96(81, + {queue:in(X, Qp81), Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(82, + {Qp81, queue:in(X, Qp82), Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(83, + {Qp81, Qp82, queue:in(X, Qp83), Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(84, + {Qp81, Qp82, Qp83, queue:in(X, Qp84), Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(85, + {Qp81, Qp82, Qp83, Qp84, queue:in(X, Qp85), + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + queue:in(X, Qp86), Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, queue:in(X, Qp87), Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, queue:in(X, Qp88), Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, queue:in(X, Qp89), Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, queue:in(X, Qp90), Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, queue:in(X, Qp91), + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + queue:in(X, Qp92), Qp93, Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, queue:in(X, Qp93), Qp94, Qp95, Qp96}); +?IN_HIGHER_Qp96(94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, queue:in(X, Qp94), Qp95, Qp96}); +?IN_HIGHER_Qp96(95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, queue:in(X, Qp95), Qp96}); +?IN_HIGHER_Qp96(96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, queue:in(X, Qp96)}); +?IN_HIGHER_Qp112(97, + {queue:in(X, Qp97), Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(98, + {Qp97, queue:in(X, Qp98), Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(99, + {Qp97, Qp98, queue:in(X, Qp99), Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(100, + {Qp97, Qp98, Qp99, queue:in(X, Qp100), Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(101, + {Qp97, Qp98, Qp99, Qp100, queue:in(X, Qp101), + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + queue:in(X, Qp102), Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, queue:in(X, Qp103), Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, queue:in(X, Qp104), Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, queue:in(X, Qp105), Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, queue:in(X, Qp106), Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, queue:in(X, Qp107), + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + queue:in(X, Qp108), Qp109, Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, queue:in(X, Qp109), Qp110, Qp111, Qp112}); +?IN_HIGHER_Qp112(110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, queue:in(X, Qp110), Qp111, Qp112}); +?IN_HIGHER_Qp112(111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, queue:in(X, Qp111), Qp112}); +?IN_HIGHER_Qp112(112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, queue:in(X, Qp112)}); +?IN_HIGHER_Qp128(113, + {queue:in(X, Qp113), Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(114, + {Qp113, queue:in(X, Qp114), Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(115, + {Qp113, Qp114, queue:in(X, Qp115), Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(116, + {Qp113, Qp114, Qp115, queue:in(X, Qp116), Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(117, + {Qp113, Qp114, Qp115, Qp116, queue:in(X, Qp117), + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + queue:in(X, Qp118), Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, queue:in(X, Qp119), Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, queue:in(X, Qp120), Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, queue:in(X, Qp121), Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, queue:in(X, Qp122), Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, queue:in(X, Qp123), + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + queue:in(X, Qp124), Qp125, Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, queue:in(X, Qp125), Qp126, Qp127, Qp128}); +?IN_HIGHER_Qp128(126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, queue:in(X, Qp126), Qp127, Qp128}); +?IN_HIGHER_Qp128(127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, queue:in(X, Qp127), Qp128}); +?IN_HIGHER_Qp128(128, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, queue:in(X, Qp128)}). + +%% @hidden +-define(IN_LOWER_Qn128(P, V), +in_lower(P, + {Pc, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + V, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn112(P, V), +in_lower(P, + {Pc, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, + V, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn96(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, + V, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn80(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, + V, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn64(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, + V, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn48(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, + V, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn32(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qn16(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp16(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp32(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp48(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V, + Qp64, Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp64(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V, + Qp80, Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp80(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V, + Qp96, Qp112, Qp128}). +-define(IN_LOWER_Qp96(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V, + Qp112, Qp128}). +-define(IN_LOWER_Qp112(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V, + Qp128}). +-define(IN_LOWER_Qp128(P, V), +in_lower(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V}). + +?IN_LOWER_Qn128(-128, + {queue:in(X, Qn128), Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-127, + {Qn128, queue:in(X, Qn127), Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-126, + {Qn128, Qn127, queue:in(X, Qn126), Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-125, + {Qn128, Qn127, Qn126, queue:in(X, Qn125), Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-124, + {Qn128, Qn127, Qn126, Qn125, queue:in(X, Qn124), + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + queue:in(X, Qn123), Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, queue:in(X, Qn122), Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, queue:in(X, Qn121), Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, queue:in(X, Qn120), Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, queue:in(X, Qn119), Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, queue:in(X, Qn118), + Qn117, Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + queue:in(X, Qn117), Qn116, Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, queue:in(X, Qn116), Qn115, Qn114, Qn113}); +?IN_LOWER_Qn128(-115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, queue:in(X, Qn115), Qn114, Qn113}); +?IN_LOWER_Qn128(-114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, queue:in(X, Qn114), Qn113}); +?IN_LOWER_Qn128(-113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, queue:in(X, Qn113)}); +?IN_LOWER_Qn112(-112, + {queue:in(X, Qn112), Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-111, + {Qn112, queue:in(X, Qn111), Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-110, + {Qn112, Qn111, queue:in(X, Qn110), Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-109, + {Qn112, Qn111, Qn110, queue:in(X, Qn109), Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-108, + {Qn112, Qn111, Qn110, Qn109, queue:in(X, Qn108), + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + queue:in(X, Qn107), Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, queue:in(X, Qn106), Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, queue:in(X, Qn105), Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, queue:in(X, Qn104), Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, queue:in(X, Qn103), Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, queue:in(X, Qn102), + Qn101, Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + queue:in(X, Qn101), Qn100, Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, queue:in(X, Qn100), Qn99, Qn98, Qn97}); +?IN_LOWER_Qn112(-99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, queue:in(X, Qn99), Qn98, Qn97}); +?IN_LOWER_Qn112(-98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, queue:in(X, Qn98), Qn97}); +?IN_LOWER_Qn112(-97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, queue:in(X, Qn97)}); +?IN_LOWER_Qn96(-96, + {queue:in(X, Qn96), Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-95, + {Qn96, queue:in(X, Qn95), Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-94, + {Qn96, Qn95, queue:in(X, Qn94), Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-93, + {Qn96, Qn95, Qn94, queue:in(X, Qn93), Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-92, + {Qn96, Qn95, Qn94, Qn93, queue:in(X, Qn92), + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + queue:in(X, Qn91), Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, queue:in(X, Qn90), Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, queue:in(X, Qn89), Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, queue:in(X, Qn88), Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, queue:in(X, Qn87), Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, queue:in(X, Qn86), + Qn85, Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + queue:in(X, Qn85), Qn84, Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, queue:in(X, Qn84), Qn83, Qn82, Qn81}); +?IN_LOWER_Qn96(-83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, queue:in(X, Qn83), Qn82, Qn81}); +?IN_LOWER_Qn96(-82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, queue:in(X, Qn82), Qn81}); +?IN_LOWER_Qn96(-81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, queue:in(X, Qn81)}); +?IN_LOWER_Qn80(-80, + {queue:in(X, Qn80), Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-79, + {Qn80, queue:in(X, Qn79), Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-78, + {Qn80, Qn79, queue:in(X, Qn78), Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-77, + {Qn80, Qn79, Qn78, queue:in(X, Qn77), Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-76, + {Qn80, Qn79, Qn78, Qn77, queue:in(X, Qn76), + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + queue:in(X, Qn75), Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, queue:in(X, Qn74), Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, queue:in(X, Qn73), Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, queue:in(X, Qn72), Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, queue:in(X, Qn71), Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, queue:in(X, Qn70), + Qn69, Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + queue:in(X, Qn69), Qn68, Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, queue:in(X, Qn68), Qn67, Qn66, Qn65}); +?IN_LOWER_Qn80(-67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, queue:in(X, Qn67), Qn66, Qn65}); +?IN_LOWER_Qn80(-66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, queue:in(X, Qn66), Qn65}); +?IN_LOWER_Qn80(-65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, queue:in(X, Qn65)}); +?IN_LOWER_Qn64(-64, + {queue:in(X, Qn64), Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-63, + {Qn64, queue:in(X, Qn63), Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-62, + {Qn64, Qn63, queue:in(X, Qn62), Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-61, + {Qn64, Qn63, Qn62, queue:in(X, Qn61), Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-60, + {Qn64, Qn63, Qn62, Qn61, queue:in(X, Qn60), + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + queue:in(X, Qn59), Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, queue:in(X, Qn58), Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, queue:in(X, Qn57), Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, queue:in(X, Qn56), Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, queue:in(X, Qn55), Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, queue:in(X, Qn54), + Qn53, Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + queue:in(X, Qn53), Qn52, Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, queue:in(X, Qn52), Qn51, Qn50, Qn49}); +?IN_LOWER_Qn64(-51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, queue:in(X, Qn51), Qn50, Qn49}); +?IN_LOWER_Qn64(-50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, queue:in(X, Qn50), Qn49}); +?IN_LOWER_Qn64(-49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, queue:in(X, Qn49)}); +?IN_LOWER_Qn48(-48, + {queue:in(X, Qn48), Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-47, + {Qn48, queue:in(X, Qn47), Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-46, + {Qn48, Qn47, queue:in(X, Qn46), Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-45, + {Qn48, Qn47, Qn46, queue:in(X, Qn45), Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-44, + {Qn48, Qn47, Qn46, Qn45, queue:in(X, Qn44), + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + queue:in(X, Qn43), Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, queue:in(X, Qn42), Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, queue:in(X, Qn41), Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, queue:in(X, Qn40), Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, queue:in(X, Qn39), Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, queue:in(X, Qn38), + Qn37, Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + queue:in(X, Qn37), Qn36, Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, queue:in(X, Qn36), Qn35, Qn34, Qn33}); +?IN_LOWER_Qn48(-35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, queue:in(X, Qn35), Qn34, Qn33}); +?IN_LOWER_Qn48(-34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, queue:in(X, Qn34), Qn33}); +?IN_LOWER_Qn48(-33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, queue:in(X, Qn33)}); +?IN_LOWER_Qn32(-32, + {queue:in(X, Qn32), Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-31, + {Qn32, queue:in(X, Qn31), Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-30, + {Qn32, Qn31, queue:in(X, Qn30), Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-29, + {Qn32, Qn31, Qn30, queue:in(X, Qn29), Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-28, + {Qn32, Qn31, Qn30, Qn29, queue:in(X, Qn28), + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + queue:in(X, Qn27), Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, queue:in(X, Qn26), Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, queue:in(X, Qn25), Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, queue:in(X, Qn24), Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, queue:in(X, Qn23), Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, queue:in(X, Qn22), + Qn21, Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + queue:in(X, Qn21), Qn20, Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, queue:in(X, Qn20), Qn19, Qn18, Qn17}); +?IN_LOWER_Qn32(-19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, queue:in(X, Qn19), Qn18, Qn17}); +?IN_LOWER_Qn32(-18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, queue:in(X, Qn18), Qn17}); +?IN_LOWER_Qn32(-17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, queue:in(X, Qn17)}); +?IN_LOWER_Qn16(-16, + {queue:in(X, Qn16), Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-15, + {Qn16, queue:in(X, Qn15), Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-14, + {Qn16, Qn15, queue:in(X, Qn14), Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-13, + {Qn16, Qn15, Qn14, queue:in(X, Qn13), Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-12, + {Qn16, Qn15, Qn14, Qn13, queue:in(X, Qn12), + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + queue:in(X, Qn11), Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, queue:in(X, Qn10), Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, queue:in(X, Qn9), Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, queue:in(X, Qn8), Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, queue:in(X, Qn7), Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, queue:in(X, Qn6), + Qn5, Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + queue:in(X, Qn5), Qn4, Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, queue:in(X, Qn4), Qn3, Qn2, Qn1}); +?IN_LOWER_Qn16(-3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, queue:in(X, Qn3), Qn2, Qn1}); +?IN_LOWER_Qn16(-2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, queue:in(X, Qn2), Qn1}); +?IN_LOWER_Qn16(-1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, queue:in(X, Qn1)}); +in_lower(0, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}, X) -> + {Pc, + Size + 1, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + queue:in(X, Q0), + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}; +?IN_LOWER_Qp16(1, + {queue:in(X, Qp1), Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(2, + {Qp1, queue:in(X, Qp2), Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(3, + {Qp1, Qp2, queue:in(X, Qp3), Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(4, + {Qp1, Qp2, Qp3, queue:in(X, Qp4), Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(5, + {Qp1, Qp2, Qp3, Qp4, queue:in(X, Qp5), + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + queue:in(X, Qp6), Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, queue:in(X, Qp7), Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, queue:in(X, Qp8), Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, queue:in(X, Qp9), Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, queue:in(X, Qp10), Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, queue:in(X, Qp11), + Qp12, Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + queue:in(X, Qp12), Qp13, Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, queue:in(X, Qp13), Qp14, Qp15, Qp16}); +?IN_LOWER_Qp16(14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, queue:in(X, Qp14), Qp15, Qp16}); +?IN_LOWER_Qp16(15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, queue:in(X, Qp15), Qp16}); +?IN_LOWER_Qp16(16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, queue:in(X, Qp16)}); +?IN_LOWER_Qp32(17, + {queue:in(X, Qp17), Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(18, + {Qp17, queue:in(X, Qp18), Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(19, + {Qp17, Qp18, queue:in(X, Qp19), Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(20, + {Qp17, Qp18, Qp19, queue:in(X, Qp20), Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(21, + {Qp17, Qp18, Qp19, Qp20, queue:in(X, Qp21), + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + queue:in(X, Qp22), Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, queue:in(X, Qp23), Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, queue:in(X, Qp24), Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, queue:in(X, Qp25), Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, queue:in(X, Qp26), Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, queue:in(X, Qp27), + Qp28, Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + queue:in(X, Qp28), Qp29, Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, queue:in(X, Qp29), Qp30, Qp31, Qp32}); +?IN_LOWER_Qp32(30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, queue:in(X, Qp30), Qp31, Qp32}); +?IN_LOWER_Qp32(31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, queue:in(X, Qp31), Qp32}); +?IN_LOWER_Qp32(32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, queue:in(X, Qp32)}); +?IN_LOWER_Qp48(33, + {queue:in(X, Qp33), Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(34, + {Qp33, queue:in(X, Qp34), Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(35, + {Qp33, Qp34, queue:in(X, Qp35), Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(36, + {Qp33, Qp34, Qp35, queue:in(X, Qp36), Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(37, + {Qp33, Qp34, Qp35, Qp36, queue:in(X, Qp37), + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + queue:in(X, Qp38), Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, queue:in(X, Qp39), Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, queue:in(X, Qp40), Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, queue:in(X, Qp41), Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, queue:in(X, Qp42), Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, queue:in(X, Qp43), + Qp44, Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + queue:in(X, Qp44), Qp45, Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, queue:in(X, Qp45), Qp46, Qp47, Qp48}); +?IN_LOWER_Qp48(46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, queue:in(X, Qp46), Qp47, Qp48}); +?IN_LOWER_Qp48(47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, queue:in(X, Qp47), Qp48}); +?IN_LOWER_Qp48(48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, queue:in(X, Qp48)}); +?IN_LOWER_Qp64(49, + {queue:in(X, Qp49), Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(50, + {Qp49, queue:in(X, Qp50), Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(51, + {Qp49, Qp50, queue:in(X, Qp51), Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(52, + {Qp49, Qp50, Qp51, queue:in(X, Qp52), Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(53, + {Qp49, Qp50, Qp51, Qp52, queue:in(X, Qp53), + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + queue:in(X, Qp54), Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, queue:in(X, Qp55), Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, queue:in(X, Qp56), Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, queue:in(X, Qp57), Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, queue:in(X, Qp58), Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, queue:in(X, Qp59), + Qp60, Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + queue:in(X, Qp60), Qp61, Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, queue:in(X, Qp61), Qp62, Qp63, Qp64}); +?IN_LOWER_Qp64(62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, queue:in(X, Qp62), Qp63, Qp64}); +?IN_LOWER_Qp64(63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, queue:in(X, Qp63), Qp64}); +?IN_LOWER_Qp64(64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, queue:in(X, Qp64)}); +?IN_LOWER_Qp80(65, + {queue:in(X, Qp65), Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(66, + {Qp65, queue:in(X, Qp66), Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(67, + {Qp65, Qp66, queue:in(X, Qp67), Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(68, + {Qp65, Qp66, Qp67, queue:in(X, Qp68), Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(69, + {Qp65, Qp66, Qp67, Qp68, queue:in(X, Qp69), + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + queue:in(X, Qp70), Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, queue:in(X, Qp71), Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, queue:in(X, Qp72), Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, queue:in(X, Qp73), Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, queue:in(X, Qp74), Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, queue:in(X, Qp75), + Qp76, Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + queue:in(X, Qp76), Qp77, Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, queue:in(X, Qp77), Qp78, Qp79, Qp80}); +?IN_LOWER_Qp80(78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, queue:in(X, Qp78), Qp79, Qp80}); +?IN_LOWER_Qp80(79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, queue:in(X, Qp79), Qp80}); +?IN_LOWER_Qp80(80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, queue:in(X, Qp80)}); +?IN_LOWER_Qp96(81, + {queue:in(X, Qp81), Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(82, + {Qp81, queue:in(X, Qp82), Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(83, + {Qp81, Qp82, queue:in(X, Qp83), Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(84, + {Qp81, Qp82, Qp83, queue:in(X, Qp84), Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(85, + {Qp81, Qp82, Qp83, Qp84, queue:in(X, Qp85), + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + queue:in(X, Qp86), Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, queue:in(X, Qp87), Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, queue:in(X, Qp88), Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, queue:in(X, Qp89), Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, queue:in(X, Qp90), Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, queue:in(X, Qp91), + Qp92, Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + queue:in(X, Qp92), Qp93, Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, queue:in(X, Qp93), Qp94, Qp95, Qp96}); +?IN_LOWER_Qp96(94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, queue:in(X, Qp94), Qp95, Qp96}); +?IN_LOWER_Qp96(95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, queue:in(X, Qp95), Qp96}); +?IN_LOWER_Qp96(96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, queue:in(X, Qp96)}); +?IN_LOWER_Qp112(97, + {queue:in(X, Qp97), Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(98, + {Qp97, queue:in(X, Qp98), Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(99, + {Qp97, Qp98, queue:in(X, Qp99), Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(100, + {Qp97, Qp98, Qp99, queue:in(X, Qp100), Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(101, + {Qp97, Qp98, Qp99, Qp100, queue:in(X, Qp101), + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + queue:in(X, Qp102), Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, queue:in(X, Qp103), Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, queue:in(X, Qp104), Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, queue:in(X, Qp105), Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, queue:in(X, Qp106), Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, queue:in(X, Qp107), + Qp108, Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + queue:in(X, Qp108), Qp109, Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, queue:in(X, Qp109), Qp110, Qp111, Qp112}); +?IN_LOWER_Qp112(110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, queue:in(X, Qp110), Qp111, Qp112}); +?IN_LOWER_Qp112(111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, queue:in(X, Qp111), Qp112}); +?IN_LOWER_Qp112(112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, queue:in(X, Qp112)}); +?IN_LOWER_Qp128(113, + {queue:in(X, Qp113), Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(114, + {Qp113, queue:in(X, Qp114), Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(115, + {Qp113, Qp114, queue:in(X, Qp115), Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(116, + {Qp113, Qp114, Qp115, queue:in(X, Qp116), Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(117, + {Qp113, Qp114, Qp115, Qp116, queue:in(X, Qp117), + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + queue:in(X, Qp118), Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, queue:in(X, Qp119), Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, queue:in(X, Qp120), Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, queue:in(X, Qp121), Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, queue:in(X, Qp122), Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, queue:in(X, Qp123), + Qp124, Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + queue:in(X, Qp124), Qp125, Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, queue:in(X, Qp125), Qp126, Qp127, Qp128}); +?IN_LOWER_Qp128(126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, queue:in(X, Qp126), Qp127, Qp128}); +?IN_LOWER_Qp128(127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, queue:in(X, Qp127), Qp128}); +?IN_LOWER_Qp128(128, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, queue:in(X, Qp128)}). + +%% @hidden +-define(OUT_CURRENT_Qn128(P, V1, V2, V3), +out_current(P, + {_, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + V3, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn112(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, + V3, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn96(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, + V3, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn80(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, + V3, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn64(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, + V3, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn48(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, + V3, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn32(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V3, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qn16(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V3, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp16(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V3, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp32(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V3, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp48(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V3, + Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp64(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V3, + Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp80(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V3, + Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp96(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V3, + Qp112, Qp128}} + end). +-define(OUT_CURRENT_Qp112(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V3, + Qp128}} + end). +-define(OUT_CURRENT_Qp128(P, V1, V2, V3), +out_current(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}} = Q) -> + {Value, V2} = queue:out(V1), + if + Value =:= empty -> + out_current(P + 1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V3}} + end). + +?OUT_CURRENT_Qn128(-128, + Qn128, NewQn128, + {NewQn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-127, + Qn127, NewQn127, + {Qn128, NewQn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-126, + Qn126, NewQn126, + {Qn128, Qn127, NewQn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-125, + Qn125, NewQn125, + {Qn128, Qn127, Qn126, NewQn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-124, + Qn124, NewQn124, + {Qn128, Qn127, Qn126, Qn125, NewQn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-123, + Qn123, NewQn123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + NewQn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-122, + Qn122, NewQn122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, NewQn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-121, + Qn121, NewQn121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, NewQn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-120, + Qn120, NewQn120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, NewQn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-119, + Qn119, NewQn119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, NewQn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-118, + Qn118, NewQn118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, NewQn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-117, + Qn117, NewQn117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + NewQn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-116, + Qn116, NewQn116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, NewQn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-115, + Qn115, NewQn115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, NewQn115, Qn114, Qn113}); +?OUT_CURRENT_Qn128(-114, + Qn114, NewQn114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, NewQn114, Qn113}); +?OUT_CURRENT_Qn128(-113, + Qn113, NewQn113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, NewQn113}); +?OUT_CURRENT_Qn112(-112, + Qn112, NewQn112, + {NewQn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-111, + Qn111, NewQn111, + {Qn112, NewQn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-110, + Qn110, NewQn110, + {Qn112, Qn111, NewQn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-109, + Qn109, NewQn109, + {Qn112, Qn111, Qn110, NewQn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-108, + Qn108, NewQn108, + {Qn112, Qn111, Qn110, Qn109, NewQn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-107, + Qn107, NewQn107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + NewQn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-106, + Qn106, NewQn106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, NewQn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-105, + Qn105, NewQn105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, NewQn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-104, + Qn104, NewQn104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, NewQn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-103, + Qn103, NewQn103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, NewQn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-102, + Qn102, NewQn102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, NewQn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-101, + Qn101, NewQn101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + NewQn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-100, + Qn100, NewQn100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, NewQn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-99, + Qn99, NewQn99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, NewQn99, Qn98, Qn97}); +?OUT_CURRENT_Qn112(-98, + Qn98, NewQn98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, NewQn98, Qn97}); +?OUT_CURRENT_Qn112(-97, + Qn97, NewQn97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, NewQn97}); +?OUT_CURRENT_Qn96(-96, + Qn96, NewQn96, + {NewQn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-95, + Qn95, NewQn95, + {Qn96, NewQn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-94, + Qn94, NewQn94, + {Qn96, Qn95, NewQn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-93, + Qn93, NewQn93, + {Qn96, Qn95, Qn94, NewQn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-92, + Qn92, NewQn92, + {Qn96, Qn95, Qn94, Qn93, NewQn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-91, + Qn91, NewQn91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + NewQn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-90, + Qn90, NewQn90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, NewQn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-89, + Qn89, NewQn89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, NewQn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-88, + Qn88, NewQn88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, NewQn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-87, + Qn87, NewQn87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, NewQn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-86, + Qn86, NewQn86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, NewQn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-85, + Qn85, NewQn85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + NewQn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-84, + Qn84, NewQn84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, NewQn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-83, + Qn83, NewQn83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, NewQn83, Qn82, Qn81}); +?OUT_CURRENT_Qn96(-82, + Qn82, NewQn82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, NewQn82, Qn81}); +?OUT_CURRENT_Qn96(-81, + Qn81, NewQn81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, NewQn81}); +?OUT_CURRENT_Qn80(-80, + Qn80, NewQn80, + {NewQn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-79, + Qn79, NewQn79, + {Qn80, NewQn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-78, + Qn78, NewQn78, + {Qn80, Qn79, NewQn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-77, + Qn77, NewQn77, + {Qn80, Qn79, Qn78, NewQn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-76, + Qn76, NewQn76, + {Qn80, Qn79, Qn78, Qn77, NewQn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-75, + Qn75, NewQn75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + NewQn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-74, + Qn74, NewQn74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, NewQn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-73, + Qn73, NewQn73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, NewQn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-72, + Qn72, NewQn72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, NewQn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-71, + Qn71, NewQn71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, NewQn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-70, + Qn70, NewQn70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, NewQn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-69, + Qn69, NewQn69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + NewQn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-68, + Qn68, NewQn68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, NewQn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-67, + Qn67, NewQn67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, NewQn67, Qn66, Qn65}); +?OUT_CURRENT_Qn80(-66, + Qn66, NewQn66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, NewQn66, Qn65}); +?OUT_CURRENT_Qn80(-65, + Qn65, NewQn65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, NewQn65}); +?OUT_CURRENT_Qn64(-64, + Qn64, NewQn64, + {NewQn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-63, + Qn63, NewQn63, + {Qn64, NewQn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-62, + Qn62, NewQn62, + {Qn64, Qn63, NewQn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-61, + Qn61, NewQn61, + {Qn64, Qn63, Qn62, NewQn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-60, + Qn60, NewQn60, + {Qn64, Qn63, Qn62, Qn61, NewQn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-59, + Qn59, NewQn59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + NewQn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-58, + Qn58, NewQn58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, NewQn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-57, + Qn57, NewQn57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, NewQn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-56, + Qn56, NewQn56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, NewQn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-55, + Qn55, NewQn55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, NewQn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-54, + Qn54, NewQn54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, NewQn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-53, + Qn53, NewQn53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + NewQn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-52, + Qn52, NewQn52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, NewQn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-51, + Qn51, NewQn51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, NewQn51, Qn50, Qn49}); +?OUT_CURRENT_Qn64(-50, + Qn50, NewQn50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, NewQn50, Qn49}); +?OUT_CURRENT_Qn64(-49, + Qn49, NewQn49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, NewQn49}); +?OUT_CURRENT_Qn48(-48, + Qn48, NewQn48, + {NewQn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-47, + Qn47, NewQn47, + {Qn48, NewQn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-46, + Qn46, NewQn46, + {Qn48, Qn47, NewQn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-45, + Qn45, NewQn45, + {Qn48, Qn47, Qn46, NewQn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-44, + Qn44, NewQn44, + {Qn48, Qn47, Qn46, Qn45, NewQn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-43, + Qn43, NewQn43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + NewQn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-42, + Qn42, NewQn42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, NewQn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-41, + Qn41, NewQn41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, NewQn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-40, + Qn40, NewQn40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, NewQn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-39, + Qn39, NewQn39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, NewQn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-38, + Qn38, NewQn38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, NewQn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-37, + Qn37, NewQn37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + NewQn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-36, + Qn36, NewQn36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, NewQn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-35, + Qn35, NewQn35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, NewQn35, Qn34, Qn33}); +?OUT_CURRENT_Qn48(-34, + Qn34, NewQn34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, NewQn34, Qn33}); +?OUT_CURRENT_Qn48(-33, + Qn33, NewQn33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, NewQn33}); +?OUT_CURRENT_Qn32(-32, + Qn32, NewQn32, + {NewQn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-31, + Qn31, NewQn31, + {Qn32, NewQn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-30, + Qn30, NewQn30, + {Qn32, Qn31, NewQn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-29, + Qn29, NewQn29, + {Qn32, Qn31, Qn30, NewQn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-28, + Qn28, NewQn28, + {Qn32, Qn31, Qn30, Qn29, NewQn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-27, + Qn27, NewQn27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + NewQn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-26, + Qn26, NewQn26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, NewQn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-25, + Qn25, NewQn25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, NewQn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-24, + Qn24, NewQn24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, NewQn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-23, + Qn23, NewQn23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, NewQn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-22, + Qn22, NewQn22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, NewQn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-21, + Qn21, NewQn21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + NewQn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-20, + Qn20, NewQn20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, NewQn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-19, + Qn19, NewQn19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, NewQn19, Qn18, Qn17}); +?OUT_CURRENT_Qn32(-18, + Qn18, NewQn18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, NewQn18, Qn17}); +?OUT_CURRENT_Qn32(-17, + Qn17, NewQn17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, NewQn17}); +?OUT_CURRENT_Qn16(-16, + Qn16, NewQn16, + {NewQn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-15, + Qn15, NewQn15, + {Qn16, NewQn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-14, + Qn14, NewQn14, + {Qn16, Qn15, NewQn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-13, + Qn13, NewQn13, + {Qn16, Qn15, Qn14, NewQn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-12, + Qn12, NewQn12, + {Qn16, Qn15, Qn14, Qn13, NewQn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-11, + Qn11, NewQn11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + NewQn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-10, + Qn10, NewQn10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, NewQn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-9, + Qn9, NewQn9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, NewQn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-8, + Qn8, NewQn8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, NewQn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-7, + Qn7, NewQn7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, NewQn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-6, + Qn6, NewQn6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, NewQn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-5, + Qn5, NewQn5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + NewQn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-4, + Qn4, NewQn4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, NewQn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-3, + Qn3, NewQn3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, NewQn3, Qn2, Qn1}); +?OUT_CURRENT_Qn16(-2, + Qn2, NewQn2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, NewQn2, Qn1}); +?OUT_CURRENT_Qn16(-1, + Qn1, NewQn1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, NewQn1}); +out_current(0, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + {Value, NewQ0} = queue:out(Q0), + if + Value =:= empty -> + out_current(1, Q); + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> 0 end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + NewQ0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end; +?OUT_CURRENT_Qp16(1, + Qp1, NewQp1, + {NewQp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(2, + Qp2, NewQp2, + {Qp1, NewQp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(3, + Qp3, NewQp3, + {Qp1, Qp2, NewQp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(4, + Qp4, NewQp4, + {Qp1, Qp2, Qp3, NewQp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(5, + Qp5, NewQp5, + {Qp1, Qp2, Qp3, Qp4, NewQp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(6, + Qp6, NewQp6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + NewQp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(7, + Qp7, NewQp7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, NewQp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(8, + Qp8, NewQp8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, NewQp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(9, + Qp9, NewQp9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, NewQp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(10, + Qp10, NewQp10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, NewQp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(11, + Qp11, NewQp11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, NewQp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(12, + Qp12, NewQp12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + NewQp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(13, + Qp13, NewQp13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, NewQp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(14, + Qp14, NewQp14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, NewQp14, Qp15, Qp16}); +?OUT_CURRENT_Qp16(15, + Qp15, NewQp15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, NewQp15, Qp16}); +?OUT_CURRENT_Qp16(16, + Qp16, NewQp16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, NewQp16}); +?OUT_CURRENT_Qp32(17, + Qp17, NewQp17, + {NewQp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(18, + Qp18, NewQp18, + {Qp17, NewQp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(19, + Qp19, NewQp19, + {Qp17, Qp18, NewQp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(20, + Qp20, NewQp20, + {Qp17, Qp18, Qp19, NewQp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(21, + Qp21, NewQp21, + {Qp17, Qp18, Qp19, Qp20, NewQp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(22, + Qp22, NewQp22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + NewQp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(23, + Qp23, NewQp23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, NewQp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(24, + Qp24, NewQp24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, NewQp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(25, + Qp25, NewQp25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, NewQp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(26, + Qp26, NewQp26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, NewQp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(27, + Qp27, NewQp27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, NewQp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(28, + Qp28, NewQp28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + NewQp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(29, + Qp29, NewQp29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, NewQp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(30, + Qp30, NewQp30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, NewQp30, Qp31, Qp32}); +?OUT_CURRENT_Qp32(31, + Qp31, NewQp31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, NewQp31, Qp32}); +?OUT_CURRENT_Qp32(32, + Qp32, NewQp32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, NewQp32}); +?OUT_CURRENT_Qp48(33, + Qp33, NewQp33, + {NewQp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(34, + Qp34, NewQp34, + {Qp33, NewQp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(35, + Qp35, NewQp35, + {Qp33, Qp34, NewQp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(36, + Qp36, NewQp36, + {Qp33, Qp34, Qp35, NewQp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(37, + Qp37, NewQp37, + {Qp33, Qp34, Qp35, Qp36, NewQp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(38, + Qp38, NewQp38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + NewQp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(39, + Qp39, NewQp39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, NewQp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(40, + Qp40, NewQp40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, NewQp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(41, + Qp41, NewQp41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, NewQp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(42, + Qp42, NewQp42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, NewQp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(43, + Qp43, NewQp43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, NewQp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(44, + Qp44, NewQp44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + NewQp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(45, + Qp45, NewQp45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, NewQp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(46, + Qp46, NewQp46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, NewQp46, Qp47, Qp48}); +?OUT_CURRENT_Qp48(47, + Qp47, NewQp47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, NewQp47, Qp48}); +?OUT_CURRENT_Qp48(48, + Qp48, NewQp48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, NewQp48}); +?OUT_CURRENT_Qp64(49, + Qp49, NewQp49, + {NewQp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(50, + Qp50, NewQp50, + {Qp49, NewQp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(51, + Qp51, NewQp51, + {Qp49, Qp50, NewQp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(52, + Qp52, NewQp52, + {Qp49, Qp50, Qp51, NewQp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(53, + Qp53, NewQp53, + {Qp49, Qp50, Qp51, Qp52, NewQp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(54, + Qp54, NewQp54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + NewQp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(55, + Qp55, NewQp55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, NewQp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(56, + Qp56, NewQp56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, NewQp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(57, + Qp57, NewQp57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, NewQp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(58, + Qp58, NewQp58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, NewQp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(59, + Qp59, NewQp59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, NewQp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(60, + Qp60, NewQp60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + NewQp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(61, + Qp61, NewQp61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, NewQp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(62, + Qp62, NewQp62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, NewQp62, Qp63, Qp64}); +?OUT_CURRENT_Qp64(63, + Qp63, NewQp63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, NewQp63, Qp64}); +?OUT_CURRENT_Qp64(64, + Qp64, NewQp64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, NewQp64}); +?OUT_CURRENT_Qp80(65, + Qp65, NewQp65, + {NewQp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(66, + Qp66, NewQp66, + {Qp65, NewQp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(67, + Qp67, NewQp67, + {Qp65, Qp66, NewQp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(68, + Qp68, NewQp68, + {Qp65, Qp66, Qp67, NewQp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(69, + Qp69, NewQp69, + {Qp65, Qp66, Qp67, Qp68, NewQp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(70, + Qp70, NewQp70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + NewQp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(71, + Qp71, NewQp71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, NewQp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(72, + Qp72, NewQp72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, NewQp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(73, + Qp73, NewQp73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, NewQp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(74, + Qp74, NewQp74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, NewQp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(75, + Qp75, NewQp75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, NewQp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(76, + Qp76, NewQp76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + NewQp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(77, + Qp77, NewQp77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, NewQp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(78, + Qp78, NewQp78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, NewQp78, Qp79, Qp80}); +?OUT_CURRENT_Qp80(79, + Qp79, NewQp79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, NewQp79, Qp80}); +?OUT_CURRENT_Qp80(80, + Qp80, NewQp80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, NewQp80}); +?OUT_CURRENT_Qp96(81, + Qp81, NewQp81, + {NewQp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(82, + Qp82, NewQp82, + {Qp81, NewQp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(83, + Qp83, NewQp83, + {Qp81, Qp82, NewQp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(84, + Qp84, NewQp84, + {Qp81, Qp82, Qp83, NewQp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(85, + Qp85, NewQp85, + {Qp81, Qp82, Qp83, Qp84, NewQp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(86, + Qp86, NewQp86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + NewQp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(87, + Qp87, NewQp87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, NewQp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(88, + Qp88, NewQp88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, NewQp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(89, + Qp89, NewQp89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, NewQp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(90, + Qp90, NewQp90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, NewQp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(91, + Qp91, NewQp91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, NewQp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(92, + Qp92, NewQp92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + NewQp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(93, + Qp93, NewQp93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, NewQp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(94, + Qp94, NewQp94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, NewQp94, Qp95, Qp96}); +?OUT_CURRENT_Qp96(95, + Qp95, NewQp95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, NewQp95, Qp96}); +?OUT_CURRENT_Qp96(96, + Qp96, NewQp96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, NewQp96}); +?OUT_CURRENT_Qp112(97, + Qp97, NewQp97, + {NewQp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(98, + Qp98, NewQp98, + {Qp97, NewQp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(99, + Qp99, NewQp99, + {Qp97, Qp98, NewQp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(100, + Qp100, NewQp100, + {Qp97, Qp98, Qp99, NewQp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(101, + Qp101, NewQp101, + {Qp97, Qp98, Qp99, Qp100, NewQp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(102, + Qp102, NewQp102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + NewQp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(103, + Qp103, NewQp103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, NewQp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(104, + Qp104, NewQp104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, NewQp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(105, + Qp105, NewQp105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, NewQp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(106, + Qp106, NewQp106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, NewQp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(107, + Qp107, NewQp107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, NewQp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(108, + Qp108, NewQp108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + NewQp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(109, + Qp109, NewQp109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, NewQp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(110, + Qp110, NewQp110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, NewQp110, Qp111, Qp112}); +?OUT_CURRENT_Qp112(111, + Qp111, NewQp111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, NewQp111, Qp112}); +?OUT_CURRENT_Qp112(112, + Qp112, NewQp112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, NewQp112}); +?OUT_CURRENT_Qp128(113, + Qp113, NewQp113, + {NewQp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(114, + Qp114, NewQp114, + {Qp113, NewQp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(115, + Qp115, NewQp115, + {Qp113, Qp114, NewQp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(116, + Qp116, NewQp116, + {Qp113, Qp114, Qp115, NewQp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(117, + Qp117, NewQp117, + {Qp113, Qp114, Qp115, Qp116, NewQp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(118, + Qp118, NewQp118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + NewQp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(119, + Qp119, NewQp119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, NewQp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(120, + Qp120, NewQp120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, NewQp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(121, + Qp121, NewQp121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, NewQp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(122, + Qp122, NewQp122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, NewQp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(123, + Qp123, NewQp123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, NewQp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(124, + Qp124, NewQp124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + NewQp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(125, + Qp125, NewQp125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, NewQp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(126, + Qp126, NewQp126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, NewQp126, Qp127, Qp128}); +?OUT_CURRENT_Qp128(127, + Qp127, NewQp127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, NewQp127, Qp128}); +out_current(128, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}) -> + {Value, NewQp128} = queue:out(Qp128), + if + Value =:= empty -> + {empty, + {empty, + 0, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, NewQp128}}}; + true -> + NewSize = Size - 1, + {Value, + {if NewSize == 0 -> empty; true -> 128 end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, NewQp128}}} + end. + +%% @hidden +-define(OUT_CURRENT_P_Qn128(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + V3, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn112(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, + V3, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn96(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, + V3, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn80(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, + V3, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn64(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, + V3, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn48(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, + V3, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn32(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V3, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qn16(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V3, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp16(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V3, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp32(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V3, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp48(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V3, + Qp64, Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp64(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V3, + Qp80, Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp80(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V3, + Qp96, Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp96(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V3, + Qp112, Qp128}} + end). +-define(OUT_CURRENT_P_Qp112(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V3, + Qp128}} + end). +-define(OUT_CURRENT_P_Qp128(P, V1, V2, V3), +out_current_p(P, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}} = Q) -> + case queue:out(V1) of + {empty, _} -> + out_current_p(P + 1, Q); + {{value, X}, V2} -> + NewSize = Size - 1, + {{value, X, P}, + {if NewSize == 0 -> empty; true -> P end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V3}} + end). + +?OUT_CURRENT_P_Qn128(-128, + Qn128, NewQn128, + {NewQn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-127, + Qn127, NewQn127, + {Qn128, NewQn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-126, + Qn126, NewQn126, + {Qn128, Qn127, NewQn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-125, + Qn125, NewQn125, + {Qn128, Qn127, Qn126, NewQn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-124, + Qn124, NewQn124, + {Qn128, Qn127, Qn126, Qn125, NewQn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-123, + Qn123, NewQn123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + NewQn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-122, + Qn122, NewQn122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, NewQn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-121, + Qn121, NewQn121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, NewQn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-120, + Qn120, NewQn120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, NewQn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-119, + Qn119, NewQn119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, NewQn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-118, + Qn118, NewQn118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, NewQn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-117, + Qn117, NewQn117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + NewQn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-116, + Qn116, NewQn116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, NewQn116, Qn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-115, + Qn115, NewQn115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, NewQn115, Qn114, Qn113}); +?OUT_CURRENT_P_Qn128(-114, + Qn114, NewQn114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, NewQn114, Qn113}); +?OUT_CURRENT_P_Qn128(-113, + Qn113, NewQn113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, NewQn113}); +?OUT_CURRENT_P_Qn112(-112, + Qn112, NewQn112, + {NewQn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-111, + Qn111, NewQn111, + {Qn112, NewQn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-110, + Qn110, NewQn110, + {Qn112, Qn111, NewQn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-109, + Qn109, NewQn109, + {Qn112, Qn111, Qn110, NewQn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-108, + Qn108, NewQn108, + {Qn112, Qn111, Qn110, Qn109, NewQn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-107, + Qn107, NewQn107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + NewQn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-106, + Qn106, NewQn106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, NewQn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-105, + Qn105, NewQn105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, NewQn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-104, + Qn104, NewQn104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, NewQn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-103, + Qn103, NewQn103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, NewQn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-102, + Qn102, NewQn102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, NewQn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-101, + Qn101, NewQn101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + NewQn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-100, + Qn100, NewQn100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, NewQn100, Qn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-99, + Qn99, NewQn99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, NewQn99, Qn98, Qn97}); +?OUT_CURRENT_P_Qn112(-98, + Qn98, NewQn98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, NewQn98, Qn97}); +?OUT_CURRENT_P_Qn112(-97, + Qn97, NewQn97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, NewQn97}); +?OUT_CURRENT_P_Qn96(-96, + Qn96, NewQn96, + {NewQn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-95, + Qn95, NewQn95, + {Qn96, NewQn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-94, + Qn94, NewQn94, + {Qn96, Qn95, NewQn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-93, + Qn93, NewQn93, + {Qn96, Qn95, Qn94, NewQn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-92, + Qn92, NewQn92, + {Qn96, Qn95, Qn94, Qn93, NewQn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-91, + Qn91, NewQn91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + NewQn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-90, + Qn90, NewQn90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, NewQn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-89, + Qn89, NewQn89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, NewQn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-88, + Qn88, NewQn88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, NewQn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-87, + Qn87, NewQn87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, NewQn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-86, + Qn86, NewQn86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, NewQn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-85, + Qn85, NewQn85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + NewQn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-84, + Qn84, NewQn84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, NewQn84, Qn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-83, + Qn83, NewQn83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, NewQn83, Qn82, Qn81}); +?OUT_CURRENT_P_Qn96(-82, + Qn82, NewQn82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, NewQn82, Qn81}); +?OUT_CURRENT_P_Qn96(-81, + Qn81, NewQn81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, NewQn81}); +?OUT_CURRENT_P_Qn80(-80, + Qn80, NewQn80, + {NewQn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-79, + Qn79, NewQn79, + {Qn80, NewQn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-78, + Qn78, NewQn78, + {Qn80, Qn79, NewQn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-77, + Qn77, NewQn77, + {Qn80, Qn79, Qn78, NewQn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-76, + Qn76, NewQn76, + {Qn80, Qn79, Qn78, Qn77, NewQn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-75, + Qn75, NewQn75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + NewQn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-74, + Qn74, NewQn74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, NewQn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-73, + Qn73, NewQn73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, NewQn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-72, + Qn72, NewQn72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, NewQn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-71, + Qn71, NewQn71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, NewQn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-70, + Qn70, NewQn70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, NewQn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-69, + Qn69, NewQn69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + NewQn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-68, + Qn68, NewQn68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, NewQn68, Qn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-67, + Qn67, NewQn67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, NewQn67, Qn66, Qn65}); +?OUT_CURRENT_P_Qn80(-66, + Qn66, NewQn66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, NewQn66, Qn65}); +?OUT_CURRENT_P_Qn80(-65, + Qn65, NewQn65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, NewQn65}); +?OUT_CURRENT_P_Qn64(-64, + Qn64, NewQn64, + {NewQn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-63, + Qn63, NewQn63, + {Qn64, NewQn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-62, + Qn62, NewQn62, + {Qn64, Qn63, NewQn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-61, + Qn61, NewQn61, + {Qn64, Qn63, Qn62, NewQn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-60, + Qn60, NewQn60, + {Qn64, Qn63, Qn62, Qn61, NewQn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-59, + Qn59, NewQn59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + NewQn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-58, + Qn58, NewQn58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, NewQn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-57, + Qn57, NewQn57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, NewQn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-56, + Qn56, NewQn56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, NewQn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-55, + Qn55, NewQn55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, NewQn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-54, + Qn54, NewQn54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, NewQn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-53, + Qn53, NewQn53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + NewQn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-52, + Qn52, NewQn52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, NewQn52, Qn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-51, + Qn51, NewQn51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, NewQn51, Qn50, Qn49}); +?OUT_CURRENT_P_Qn64(-50, + Qn50, NewQn50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, NewQn50, Qn49}); +?OUT_CURRENT_P_Qn64(-49, + Qn49, NewQn49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, NewQn49}); +?OUT_CURRENT_P_Qn48(-48, + Qn48, NewQn48, + {NewQn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-47, + Qn47, NewQn47, + {Qn48, NewQn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-46, + Qn46, NewQn46, + {Qn48, Qn47, NewQn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-45, + Qn45, NewQn45, + {Qn48, Qn47, Qn46, NewQn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-44, + Qn44, NewQn44, + {Qn48, Qn47, Qn46, Qn45, NewQn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-43, + Qn43, NewQn43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + NewQn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-42, + Qn42, NewQn42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, NewQn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-41, + Qn41, NewQn41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, NewQn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-40, + Qn40, NewQn40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, NewQn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-39, + Qn39, NewQn39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, NewQn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-38, + Qn38, NewQn38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, NewQn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-37, + Qn37, NewQn37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + NewQn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-36, + Qn36, NewQn36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, NewQn36, Qn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-35, + Qn35, NewQn35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, NewQn35, Qn34, Qn33}); +?OUT_CURRENT_P_Qn48(-34, + Qn34, NewQn34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, NewQn34, Qn33}); +?OUT_CURRENT_P_Qn48(-33, + Qn33, NewQn33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, NewQn33}); +?OUT_CURRENT_P_Qn32(-32, + Qn32, NewQn32, + {NewQn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-31, + Qn31, NewQn31, + {Qn32, NewQn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-30, + Qn30, NewQn30, + {Qn32, Qn31, NewQn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-29, + Qn29, NewQn29, + {Qn32, Qn31, Qn30, NewQn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-28, + Qn28, NewQn28, + {Qn32, Qn31, Qn30, Qn29, NewQn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-27, + Qn27, NewQn27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + NewQn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-26, + Qn26, NewQn26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, NewQn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-25, + Qn25, NewQn25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, NewQn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-24, + Qn24, NewQn24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, NewQn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-23, + Qn23, NewQn23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, NewQn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-22, + Qn22, NewQn22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, NewQn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-21, + Qn21, NewQn21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + NewQn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-20, + Qn20, NewQn20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, NewQn20, Qn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-19, + Qn19, NewQn19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, NewQn19, Qn18, Qn17}); +?OUT_CURRENT_P_Qn32(-18, + Qn18, NewQn18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, NewQn18, Qn17}); +?OUT_CURRENT_P_Qn32(-17, + Qn17, NewQn17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, NewQn17}); +?OUT_CURRENT_P_Qn16(-16, + Qn16, NewQn16, + {NewQn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-15, + Qn15, NewQn15, + {Qn16, NewQn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-14, + Qn14, NewQn14, + {Qn16, Qn15, NewQn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-13, + Qn13, NewQn13, + {Qn16, Qn15, Qn14, NewQn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-12, + Qn12, NewQn12, + {Qn16, Qn15, Qn14, Qn13, NewQn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-11, + Qn11, NewQn11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + NewQn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-10, + Qn10, NewQn10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, NewQn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-9, + Qn9, NewQn9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, NewQn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-8, + Qn8, NewQn8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, NewQn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-7, + Qn7, NewQn7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, NewQn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-6, + Qn6, NewQn6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, NewQn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-5, + Qn5, NewQn5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + NewQn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-4, + Qn4, NewQn4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, NewQn4, Qn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-3, + Qn3, NewQn3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, NewQn3, Qn2, Qn1}); +?OUT_CURRENT_P_Qn16(-2, + Qn2, NewQn2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, NewQn2, Qn1}); +?OUT_CURRENT_P_Qn16(-1, + Qn1, NewQn1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, NewQn1}); +out_current_p(0, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128} = Q) -> + case queue:out(Q0) of + {empty, _} -> + out_current_p(1, Q); + {{value, X}, NewQ0} -> + NewSize = Size - 1, + {{value, X, 0}, + {if NewSize == 0 -> empty; true -> 0 end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + NewQ0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}} + end; +?OUT_CURRENT_P_Qp16(1, + Qp1, NewQp1, + {NewQp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(2, + Qp2, NewQp2, + {Qp1, NewQp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(3, + Qp3, NewQp3, + {Qp1, Qp2, NewQp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(4, + Qp4, NewQp4, + {Qp1, Qp2, Qp3, NewQp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(5, + Qp5, NewQp5, + {Qp1, Qp2, Qp3, Qp4, NewQp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(6, + Qp6, NewQp6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + NewQp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(7, + Qp7, NewQp7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, NewQp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(8, + Qp8, NewQp8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, NewQp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(9, + Qp9, NewQp9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, NewQp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(10, + Qp10, NewQp10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, NewQp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(11, + Qp11, NewQp11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, NewQp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(12, + Qp12, NewQp12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + NewQp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(13, + Qp13, NewQp13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, NewQp13, Qp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(14, + Qp14, NewQp14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, NewQp14, Qp15, Qp16}); +?OUT_CURRENT_P_Qp16(15, + Qp15, NewQp15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, NewQp15, Qp16}); +?OUT_CURRENT_P_Qp16(16, + Qp16, NewQp16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, NewQp16}); +?OUT_CURRENT_P_Qp32(17, + Qp17, NewQp17, + {NewQp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(18, + Qp18, NewQp18, + {Qp17, NewQp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(19, + Qp19, NewQp19, + {Qp17, Qp18, NewQp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(20, + Qp20, NewQp20, + {Qp17, Qp18, Qp19, NewQp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(21, + Qp21, NewQp21, + {Qp17, Qp18, Qp19, Qp20, NewQp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(22, + Qp22, NewQp22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + NewQp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(23, + Qp23, NewQp23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, NewQp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(24, + Qp24, NewQp24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, NewQp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(25, + Qp25, NewQp25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, NewQp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(26, + Qp26, NewQp26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, NewQp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(27, + Qp27, NewQp27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, NewQp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(28, + Qp28, NewQp28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + NewQp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(29, + Qp29, NewQp29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, NewQp29, Qp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(30, + Qp30, NewQp30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, NewQp30, Qp31, Qp32}); +?OUT_CURRENT_P_Qp32(31, + Qp31, NewQp31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, NewQp31, Qp32}); +?OUT_CURRENT_P_Qp32(32, + Qp32, NewQp32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, NewQp32}); +?OUT_CURRENT_P_Qp48(33, + Qp33, NewQp33, + {NewQp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(34, + Qp34, NewQp34, + {Qp33, NewQp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(35, + Qp35, NewQp35, + {Qp33, Qp34, NewQp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(36, + Qp36, NewQp36, + {Qp33, Qp34, Qp35, NewQp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(37, + Qp37, NewQp37, + {Qp33, Qp34, Qp35, Qp36, NewQp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(38, + Qp38, NewQp38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + NewQp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(39, + Qp39, NewQp39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, NewQp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(40, + Qp40, NewQp40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, NewQp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(41, + Qp41, NewQp41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, NewQp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(42, + Qp42, NewQp42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, NewQp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(43, + Qp43, NewQp43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, NewQp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(44, + Qp44, NewQp44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + NewQp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(45, + Qp45, NewQp45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, NewQp45, Qp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(46, + Qp46, NewQp46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, NewQp46, Qp47, Qp48}); +?OUT_CURRENT_P_Qp48(47, + Qp47, NewQp47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, NewQp47, Qp48}); +?OUT_CURRENT_P_Qp48(48, + Qp48, NewQp48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, NewQp48}); +?OUT_CURRENT_P_Qp64(49, + Qp49, NewQp49, + {NewQp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(50, + Qp50, NewQp50, + {Qp49, NewQp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(51, + Qp51, NewQp51, + {Qp49, Qp50, NewQp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(52, + Qp52, NewQp52, + {Qp49, Qp50, Qp51, NewQp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(53, + Qp53, NewQp53, + {Qp49, Qp50, Qp51, Qp52, NewQp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(54, + Qp54, NewQp54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + NewQp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(55, + Qp55, NewQp55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, NewQp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(56, + Qp56, NewQp56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, NewQp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(57, + Qp57, NewQp57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, NewQp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(58, + Qp58, NewQp58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, NewQp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(59, + Qp59, NewQp59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, NewQp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(60, + Qp60, NewQp60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + NewQp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(61, + Qp61, NewQp61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, NewQp61, Qp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(62, + Qp62, NewQp62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, NewQp62, Qp63, Qp64}); +?OUT_CURRENT_P_Qp64(63, + Qp63, NewQp63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, NewQp63, Qp64}); +?OUT_CURRENT_P_Qp64(64, + Qp64, NewQp64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, NewQp64}); +?OUT_CURRENT_P_Qp80(65, + Qp65, NewQp65, + {NewQp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(66, + Qp66, NewQp66, + {Qp65, NewQp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(67, + Qp67, NewQp67, + {Qp65, Qp66, NewQp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(68, + Qp68, NewQp68, + {Qp65, Qp66, Qp67, NewQp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(69, + Qp69, NewQp69, + {Qp65, Qp66, Qp67, Qp68, NewQp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(70, + Qp70, NewQp70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + NewQp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(71, + Qp71, NewQp71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, NewQp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(72, + Qp72, NewQp72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, NewQp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(73, + Qp73, NewQp73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, NewQp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(74, + Qp74, NewQp74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, NewQp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(75, + Qp75, NewQp75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, NewQp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(76, + Qp76, NewQp76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + NewQp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(77, + Qp77, NewQp77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, NewQp77, Qp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(78, + Qp78, NewQp78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, NewQp78, Qp79, Qp80}); +?OUT_CURRENT_P_Qp80(79, + Qp79, NewQp79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, NewQp79, Qp80}); +?OUT_CURRENT_P_Qp80(80, + Qp80, NewQp80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, NewQp80}); +?OUT_CURRENT_P_Qp96(81, + Qp81, NewQp81, + {NewQp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(82, + Qp82, NewQp82, + {Qp81, NewQp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(83, + Qp83, NewQp83, + {Qp81, Qp82, NewQp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(84, + Qp84, NewQp84, + {Qp81, Qp82, Qp83, NewQp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(85, + Qp85, NewQp85, + {Qp81, Qp82, Qp83, Qp84, NewQp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(86, + Qp86, NewQp86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + NewQp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(87, + Qp87, NewQp87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, NewQp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(88, + Qp88, NewQp88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, NewQp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(89, + Qp89, NewQp89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, NewQp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(90, + Qp90, NewQp90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, NewQp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(91, + Qp91, NewQp91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, NewQp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(92, + Qp92, NewQp92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + NewQp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(93, + Qp93, NewQp93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, NewQp93, Qp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(94, + Qp94, NewQp94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, NewQp94, Qp95, Qp96}); +?OUT_CURRENT_P_Qp96(95, + Qp95, NewQp95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, NewQp95, Qp96}); +?OUT_CURRENT_P_Qp96(96, + Qp96, NewQp96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, NewQp96}); +?OUT_CURRENT_P_Qp112(97, + Qp97, NewQp97, + {NewQp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(98, + Qp98, NewQp98, + {Qp97, NewQp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(99, + Qp99, NewQp99, + {Qp97, Qp98, NewQp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(100, + Qp100, NewQp100, + {Qp97, Qp98, Qp99, NewQp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(101, + Qp101, NewQp101, + {Qp97, Qp98, Qp99, Qp100, NewQp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(102, + Qp102, NewQp102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + NewQp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(103, + Qp103, NewQp103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, NewQp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(104, + Qp104, NewQp104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, NewQp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(105, + Qp105, NewQp105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, NewQp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(106, + Qp106, NewQp106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, NewQp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(107, + Qp107, NewQp107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, NewQp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(108, + Qp108, NewQp108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + NewQp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(109, + Qp109, NewQp109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, NewQp109, Qp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(110, + Qp110, NewQp110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, NewQp110, Qp111, Qp112}); +?OUT_CURRENT_P_Qp112(111, + Qp111, NewQp111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, NewQp111, Qp112}); +?OUT_CURRENT_P_Qp112(112, + Qp112, NewQp112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, NewQp112}); +?OUT_CURRENT_P_Qp128(113, + Qp113, NewQp113, + {NewQp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(114, + Qp114, NewQp114, + {Qp113, NewQp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(115, + Qp115, NewQp115, + {Qp113, Qp114, NewQp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(116, + Qp116, NewQp116, + {Qp113, Qp114, Qp115, NewQp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(117, + Qp117, NewQp117, + {Qp113, Qp114, Qp115, Qp116, NewQp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(118, + Qp118, NewQp118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + NewQp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(119, + Qp119, NewQp119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, NewQp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(120, + Qp120, NewQp120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, NewQp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(121, + Qp121, NewQp121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, NewQp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(122, + Qp122, NewQp122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, NewQp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(123, + Qp123, NewQp123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, NewQp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(124, + Qp124, NewQp124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + NewQp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(125, + Qp125, NewQp125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, NewQp125, Qp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(126, + Qp126, NewQp126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, NewQp126, Qp127, Qp128}); +?OUT_CURRENT_P_Qp128(127, + Qp127, NewQp127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, NewQp127, Qp128}); +out_current_p(128, + {_, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}) -> + case queue:out(Qp128) of + {empty, _} -> + {empty, + {empty, + 0, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}}; + {{value, X}, NewQp128} -> + NewSize = Size - 1, + {{value, X, 128}, + {if NewSize == 0 -> empty; true -> 128 end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, NewQp128}}} + end. + +%% @hidden +-define(OUT_SPECIFIC_Qn128(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + V3, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn112(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, + V3, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn96(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, + V3, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn80(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, + V3, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn64(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, + V3, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn48(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, + V3, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn32(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V3, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qn16(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V3, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp16(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V3, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp32(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V3, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp48(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V3, + Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp64(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V3, + Qp80, Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp80(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V3, + Qp96, Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp96(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V3, + Qp112, Qp128}}). +-define(OUT_SPECIFIC_Qp112(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V3, + Qp128}}). +-define(OUT_SPECIFIC_Qp128(P, V1, V2, V3), +out_specific(P, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}) -> + {Value, V2} = queue:out(V1), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V3}}). + +?OUT_SPECIFIC_Qn128(-128, + Qn128, NewQn128, + {NewQn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-127, + Qn127, NewQn127, + {Qn128, NewQn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-126, + Qn126, NewQn126, + {Qn128, Qn127, NewQn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-125, + Qn125, NewQn125, + {Qn128, Qn127, Qn126, NewQn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-124, + Qn124, NewQn124, + {Qn128, Qn127, Qn126, Qn125, NewQn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-123, + Qn123, NewQn123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + NewQn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-122, + Qn122, NewQn122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, NewQn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-121, + Qn121, NewQn121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, NewQn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-120, + Qn120, NewQn120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, NewQn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-119, + Qn119, NewQn119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, NewQn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-118, + Qn118, NewQn118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, NewQn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-117, + Qn117, NewQn117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + NewQn117, Qn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-116, + Qn116, NewQn116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, NewQn116, Qn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-115, + Qn115, NewQn115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, NewQn115, Qn114, Qn113}); +?OUT_SPECIFIC_Qn128(-114, + Qn114, NewQn114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, NewQn114, Qn113}); +?OUT_SPECIFIC_Qn128(-113, + Qn113, NewQn113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, NewQn113}); +?OUT_SPECIFIC_Qn112(-112, + Qn112, NewQn112, + {NewQn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-111, + Qn111, NewQn111, + {Qn112, NewQn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-110, + Qn110, NewQn110, + {Qn112, Qn111, NewQn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-109, + Qn109, NewQn109, + {Qn112, Qn111, Qn110, NewQn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-108, + Qn108, NewQn108, + {Qn112, Qn111, Qn110, Qn109, NewQn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-107, + Qn107, NewQn107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + NewQn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-106, + Qn106, NewQn106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, NewQn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-105, + Qn105, NewQn105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, NewQn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-104, + Qn104, NewQn104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, NewQn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-103, + Qn103, NewQn103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, NewQn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-102, + Qn102, NewQn102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, NewQn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-101, + Qn101, NewQn101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + NewQn101, Qn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-100, + Qn100, NewQn100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, NewQn100, Qn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-99, + Qn99, NewQn99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, NewQn99, Qn98, Qn97}); +?OUT_SPECIFIC_Qn112(-98, + Qn98, NewQn98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, NewQn98, Qn97}); +?OUT_SPECIFIC_Qn112(-97, + Qn97, NewQn97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, NewQn97}); +?OUT_SPECIFIC_Qn96(-96, + Qn96, NewQn96, + {NewQn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-95, + Qn95, NewQn95, + {Qn96, NewQn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-94, + Qn94, NewQn94, + {Qn96, Qn95, NewQn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-93, + Qn93, NewQn93, + {Qn96, Qn95, Qn94, NewQn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-92, + Qn92, NewQn92, + {Qn96, Qn95, Qn94, Qn93, NewQn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-91, + Qn91, NewQn91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + NewQn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-90, + Qn90, NewQn90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, NewQn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-89, + Qn89, NewQn89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, NewQn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-88, + Qn88, NewQn88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, NewQn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-87, + Qn87, NewQn87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, NewQn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-86, + Qn86, NewQn86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, NewQn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-85, + Qn85, NewQn85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + NewQn85, Qn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-84, + Qn84, NewQn84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, NewQn84, Qn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-83, + Qn83, NewQn83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, NewQn83, Qn82, Qn81}); +?OUT_SPECIFIC_Qn96(-82, + Qn82, NewQn82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, NewQn82, Qn81}); +?OUT_SPECIFIC_Qn96(-81, + Qn81, NewQn81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, NewQn81}); +?OUT_SPECIFIC_Qn80(-80, + Qn80, NewQn80, + {NewQn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-79, + Qn79, NewQn79, + {Qn80, NewQn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-78, + Qn78, NewQn78, + {Qn80, Qn79, NewQn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-77, + Qn77, NewQn77, + {Qn80, Qn79, Qn78, NewQn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-76, + Qn76, NewQn76, + {Qn80, Qn79, Qn78, Qn77, NewQn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-75, + Qn75, NewQn75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + NewQn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-74, + Qn74, NewQn74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, NewQn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-73, + Qn73, NewQn73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, NewQn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-72, + Qn72, NewQn72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, NewQn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-71, + Qn71, NewQn71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, NewQn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-70, + Qn70, NewQn70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, NewQn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-69, + Qn69, NewQn69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + NewQn69, Qn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-68, + Qn68, NewQn68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, NewQn68, Qn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-67, + Qn67, NewQn67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, NewQn67, Qn66, Qn65}); +?OUT_SPECIFIC_Qn80(-66, + Qn66, NewQn66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, NewQn66, Qn65}); +?OUT_SPECIFIC_Qn80(-65, + Qn65, NewQn65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, NewQn65}); +?OUT_SPECIFIC_Qn64(-64, + Qn64, NewQn64, + {NewQn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-63, + Qn63, NewQn63, + {Qn64, NewQn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-62, + Qn62, NewQn62, + {Qn64, Qn63, NewQn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-61, + Qn61, NewQn61, + {Qn64, Qn63, Qn62, NewQn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-60, + Qn60, NewQn60, + {Qn64, Qn63, Qn62, Qn61, NewQn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-59, + Qn59, NewQn59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + NewQn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-58, + Qn58, NewQn58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, NewQn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-57, + Qn57, NewQn57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, NewQn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-56, + Qn56, NewQn56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, NewQn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-55, + Qn55, NewQn55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, NewQn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-54, + Qn54, NewQn54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, NewQn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-53, + Qn53, NewQn53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + NewQn53, Qn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-52, + Qn52, NewQn52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, NewQn52, Qn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-51, + Qn51, NewQn51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, NewQn51, Qn50, Qn49}); +?OUT_SPECIFIC_Qn64(-50, + Qn50, NewQn50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, NewQn50, Qn49}); +?OUT_SPECIFIC_Qn64(-49, + Qn49, NewQn49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, NewQn49}); +?OUT_SPECIFIC_Qn48(-48, + Qn48, NewQn48, + {NewQn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-47, + Qn47, NewQn47, + {Qn48, NewQn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-46, + Qn46, NewQn46, + {Qn48, Qn47, NewQn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-45, + Qn45, NewQn45, + {Qn48, Qn47, Qn46, NewQn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-44, + Qn44, NewQn44, + {Qn48, Qn47, Qn46, Qn45, NewQn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-43, + Qn43, NewQn43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + NewQn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-42, + Qn42, NewQn42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, NewQn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-41, + Qn41, NewQn41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, NewQn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-40, + Qn40, NewQn40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, NewQn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-39, + Qn39, NewQn39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, NewQn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-38, + Qn38, NewQn38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, NewQn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-37, + Qn37, NewQn37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + NewQn37, Qn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-36, + Qn36, NewQn36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, NewQn36, Qn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-35, + Qn35, NewQn35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, NewQn35, Qn34, Qn33}); +?OUT_SPECIFIC_Qn48(-34, + Qn34, NewQn34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, NewQn34, Qn33}); +?OUT_SPECIFIC_Qn48(-33, + Qn33, NewQn33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, NewQn33}); +?OUT_SPECIFIC_Qn32(-32, + Qn32, NewQn32, + {NewQn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-31, + Qn31, NewQn31, + {Qn32, NewQn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-30, + Qn30, NewQn30, + {Qn32, Qn31, NewQn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-29, + Qn29, NewQn29, + {Qn32, Qn31, Qn30, NewQn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-28, + Qn28, NewQn28, + {Qn32, Qn31, Qn30, Qn29, NewQn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-27, + Qn27, NewQn27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + NewQn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-26, + Qn26, NewQn26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, NewQn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-25, + Qn25, NewQn25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, NewQn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-24, + Qn24, NewQn24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, NewQn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-23, + Qn23, NewQn23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, NewQn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-22, + Qn22, NewQn22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, NewQn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-21, + Qn21, NewQn21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + NewQn21, Qn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-20, + Qn20, NewQn20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, NewQn20, Qn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-19, + Qn19, NewQn19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, NewQn19, Qn18, Qn17}); +?OUT_SPECIFIC_Qn32(-18, + Qn18, NewQn18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, NewQn18, Qn17}); +?OUT_SPECIFIC_Qn32(-17, + Qn17, NewQn17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, NewQn17}); +?OUT_SPECIFIC_Qn16(-16, + Qn16, NewQn16, + {NewQn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-15, + Qn15, NewQn15, + {Qn16, NewQn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-14, + Qn14, NewQn14, + {Qn16, Qn15, NewQn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-13, + Qn13, NewQn13, + {Qn16, Qn15, Qn14, NewQn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-12, + Qn12, NewQn12, + {Qn16, Qn15, Qn14, Qn13, NewQn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-11, + Qn11, NewQn11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + NewQn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-10, + Qn10, NewQn10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, NewQn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-9, + Qn9, NewQn9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, NewQn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-8, + Qn8, NewQn8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, NewQn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-7, + Qn7, NewQn7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, NewQn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-6, + Qn6, NewQn6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, NewQn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-5, + Qn5, NewQn5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + NewQn5, Qn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-4, + Qn4, NewQn4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, NewQn4, Qn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-3, + Qn3, NewQn3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, NewQn3, Qn2, Qn1}); +?OUT_SPECIFIC_Qn16(-2, + Qn2, NewQn2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, NewQn2, Qn1}); +?OUT_SPECIFIC_Qn16(-1, + Qn1, NewQn1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, NewQn1}); +out_specific(0, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, NewQ0} = queue:out(Q0), + NewSize = if Value =/= empty -> Size - 1; true -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + NewQ0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}; +?OUT_SPECIFIC_Qp16(1, + Qp1, NewQp1, + {NewQp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(2, + Qp2, NewQp2, + {Qp1, NewQp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(3, + Qp3, NewQp3, + {Qp1, Qp2, NewQp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(4, + Qp4, NewQp4, + {Qp1, Qp2, Qp3, NewQp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(5, + Qp5, NewQp5, + {Qp1, Qp2, Qp3, Qp4, NewQp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(6, + Qp6, NewQp6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + NewQp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(7, + Qp7, NewQp7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, NewQp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(8, + Qp8, NewQp8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, NewQp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(9, + Qp9, NewQp9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, NewQp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(10, + Qp10, NewQp10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, NewQp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(11, + Qp11, NewQp11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, NewQp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(12, + Qp12, NewQp12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + NewQp12, Qp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(13, + Qp13, NewQp13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, NewQp13, Qp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(14, + Qp14, NewQp14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, NewQp14, Qp15, Qp16}); +?OUT_SPECIFIC_Qp16(15, + Qp15, NewQp15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, NewQp15, Qp16}); +?OUT_SPECIFIC_Qp16(16, + Qp16, NewQp16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, NewQp16}); +?OUT_SPECIFIC_Qp32(17, + Qp17, NewQp17, + {NewQp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(18, + Qp18, NewQp18, + {Qp17, NewQp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(19, + Qp19, NewQp19, + {Qp17, Qp18, NewQp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(20, + Qp20, NewQp20, + {Qp17, Qp18, Qp19, NewQp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(21, + Qp21, NewQp21, + {Qp17, Qp18, Qp19, Qp20, NewQp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(22, + Qp22, NewQp22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + NewQp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(23, + Qp23, NewQp23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, NewQp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(24, + Qp24, NewQp24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, NewQp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(25, + Qp25, NewQp25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, NewQp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(26, + Qp26, NewQp26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, NewQp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(27, + Qp27, NewQp27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, NewQp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(28, + Qp28, NewQp28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + NewQp28, Qp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(29, + Qp29, NewQp29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, NewQp29, Qp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(30, + Qp30, NewQp30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, NewQp30, Qp31, Qp32}); +?OUT_SPECIFIC_Qp32(31, + Qp31, NewQp31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, NewQp31, Qp32}); +?OUT_SPECIFIC_Qp32(32, + Qp32, NewQp32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, NewQp32}); +?OUT_SPECIFIC_Qp48(33, + Qp33, NewQp33, + {NewQp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(34, + Qp34, NewQp34, + {Qp33, NewQp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(35, + Qp35, NewQp35, + {Qp33, Qp34, NewQp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(36, + Qp36, NewQp36, + {Qp33, Qp34, Qp35, NewQp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(37, + Qp37, NewQp37, + {Qp33, Qp34, Qp35, Qp36, NewQp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(38, + Qp38, NewQp38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + NewQp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(39, + Qp39, NewQp39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, NewQp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(40, + Qp40, NewQp40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, NewQp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(41, + Qp41, NewQp41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, NewQp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(42, + Qp42, NewQp42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, NewQp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(43, + Qp43, NewQp43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, NewQp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(44, + Qp44, NewQp44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + NewQp44, Qp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(45, + Qp45, NewQp45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, NewQp45, Qp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(46, + Qp46, NewQp46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, NewQp46, Qp47, Qp48}); +?OUT_SPECIFIC_Qp48(47, + Qp47, NewQp47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, NewQp47, Qp48}); +?OUT_SPECIFIC_Qp48(48, + Qp48, NewQp48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, NewQp48}); +?OUT_SPECIFIC_Qp64(49, + Qp49, NewQp49, + {NewQp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(50, + Qp50, NewQp50, + {Qp49, NewQp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(51, + Qp51, NewQp51, + {Qp49, Qp50, NewQp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(52, + Qp52, NewQp52, + {Qp49, Qp50, Qp51, NewQp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(53, + Qp53, NewQp53, + {Qp49, Qp50, Qp51, Qp52, NewQp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(54, + Qp54, NewQp54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + NewQp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(55, + Qp55, NewQp55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, NewQp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(56, + Qp56, NewQp56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, NewQp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(57, + Qp57, NewQp57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, NewQp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(58, + Qp58, NewQp58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, NewQp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(59, + Qp59, NewQp59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, NewQp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(60, + Qp60, NewQp60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + NewQp60, Qp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(61, + Qp61, NewQp61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, NewQp61, Qp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(62, + Qp62, NewQp62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, NewQp62, Qp63, Qp64}); +?OUT_SPECIFIC_Qp64(63, + Qp63, NewQp63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, NewQp63, Qp64}); +?OUT_SPECIFIC_Qp64(64, + Qp64, NewQp64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, NewQp64}); +?OUT_SPECIFIC_Qp80(65, + Qp65, NewQp65, + {NewQp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(66, + Qp66, NewQp66, + {Qp65, NewQp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(67, + Qp67, NewQp67, + {Qp65, Qp66, NewQp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(68, + Qp68, NewQp68, + {Qp65, Qp66, Qp67, NewQp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(69, + Qp69, NewQp69, + {Qp65, Qp66, Qp67, Qp68, NewQp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(70, + Qp70, NewQp70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + NewQp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(71, + Qp71, NewQp71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, NewQp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(72, + Qp72, NewQp72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, NewQp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(73, + Qp73, NewQp73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, NewQp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(74, + Qp74, NewQp74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, NewQp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(75, + Qp75, NewQp75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, NewQp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(76, + Qp76, NewQp76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + NewQp76, Qp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(77, + Qp77, NewQp77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, NewQp77, Qp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(78, + Qp78, NewQp78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, NewQp78, Qp79, Qp80}); +?OUT_SPECIFIC_Qp80(79, + Qp79, NewQp79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, NewQp79, Qp80}); +?OUT_SPECIFIC_Qp80(80, + Qp80, NewQp80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, NewQp80}); +?OUT_SPECIFIC_Qp96(81, + Qp81, NewQp81, + {NewQp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(82, + Qp82, NewQp82, + {Qp81, NewQp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(83, + Qp83, NewQp83, + {Qp81, Qp82, NewQp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(84, + Qp84, NewQp84, + {Qp81, Qp82, Qp83, NewQp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(85, + Qp85, NewQp85, + {Qp81, Qp82, Qp83, Qp84, NewQp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(86, + Qp86, NewQp86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + NewQp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(87, + Qp87, NewQp87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, NewQp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(88, + Qp88, NewQp88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, NewQp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(89, + Qp89, NewQp89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, NewQp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(90, + Qp90, NewQp90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, NewQp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(91, + Qp91, NewQp91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, NewQp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(92, + Qp92, NewQp92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + NewQp92, Qp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(93, + Qp93, NewQp93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, NewQp93, Qp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(94, + Qp94, NewQp94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, NewQp94, Qp95, Qp96}); +?OUT_SPECIFIC_Qp96(95, + Qp95, NewQp95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, NewQp95, Qp96}); +?OUT_SPECIFIC_Qp96(96, + Qp96, NewQp96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, NewQp96}); +?OUT_SPECIFIC_Qp112(97, + Qp97, NewQp97, + {NewQp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(98, + Qp98, NewQp98, + {Qp97, NewQp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(99, + Qp99, NewQp99, + {Qp97, Qp98, NewQp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(100, + Qp100, NewQp100, + {Qp97, Qp98, Qp99, NewQp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(101, + Qp101, NewQp101, + {Qp97, Qp98, Qp99, Qp100, NewQp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(102, + Qp102, NewQp102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + NewQp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(103, + Qp103, NewQp103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, NewQp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(104, + Qp104, NewQp104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, NewQp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(105, + Qp105, NewQp105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, NewQp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(106, + Qp106, NewQp106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, NewQp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(107, + Qp107, NewQp107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, NewQp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(108, + Qp108, NewQp108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + NewQp108, Qp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(109, + Qp109, NewQp109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, NewQp109, Qp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(110, + Qp110, NewQp110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, NewQp110, Qp111, Qp112}); +?OUT_SPECIFIC_Qp112(111, + Qp111, NewQp111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, NewQp111, Qp112}); +?OUT_SPECIFIC_Qp112(112, + Qp112, NewQp112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, NewQp112}); +?OUT_SPECIFIC_Qp128(113, + Qp113, NewQp113, + {NewQp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(114, + Qp114, NewQp114, + {Qp113, NewQp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(115, + Qp115, NewQp115, + {Qp113, Qp114, NewQp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(116, + Qp116, NewQp116, + {Qp113, Qp114, Qp115, NewQp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(117, + Qp117, NewQp117, + {Qp113, Qp114, Qp115, Qp116, NewQp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(118, + Qp118, NewQp118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + NewQp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(119, + Qp119, NewQp119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, NewQp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(120, + Qp120, NewQp120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, NewQp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(121, + Qp121, NewQp121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, NewQp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(122, + Qp122, NewQp122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, NewQp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(123, + Qp123, NewQp123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, NewQp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(124, + Qp124, NewQp124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + NewQp124, Qp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(125, + Qp125, NewQp125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, NewQp125, Qp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(126, + Qp126, NewQp126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, NewQp126, Qp127, Qp128}); +?OUT_SPECIFIC_Qp128(127, + Qp127, NewQp127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, NewQp127, Qp128}); +?OUT_SPECIFIC_Qp128(128, + Qp128, NewQp128, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, NewQp128}). + +%% @hidden +-define(REMOVE_UNIQ_P_Qn128(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + {Qn128, Qn127, Qn126, Qn125, Qn124, Qn123, Qn122, Qn121, + Qn120, Qn119, Qn118, Qn117, Qn116, Qn115, Qn114, Qn113}, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + V3, + Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn112(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, + {Qn112, Qn111, Qn110, Qn109, Qn108, Qn107, Qn106, Qn105, + Qn104, Qn103, Qn102, Qn101, Qn100, Qn99, Qn98, Qn97}, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, + V3, + Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn96(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, + {Qn96, Qn95, Qn94, Qn93, Qn92, Qn91, Qn90, Qn89, + Qn88, Qn87, Qn86, Qn85, Qn84, Qn83, Qn82, Qn81}, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, + V3, + Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn80(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, + {Qn80, Qn79, Qn78, Qn77, Qn76, Qn75, Qn74, Qn73, + Qn72, Qn71, Qn70, Qn69, Qn68, Qn67, Qn66, Qn65}, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, + V3, + Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn64(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, + {Qn64, Qn63, Qn62, Qn61, Qn60, Qn59, Qn58, Qn57, + Qn56, Qn55, Qn54, Qn53, Qn52, Qn51, Qn50, Qn49}, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, + V3, + Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn48(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, + {Qn48, Qn47, Qn46, Qn45, Qn44, Qn43, Qn42, Qn41, + Qn40, Qn39, Qn38, Qn37, Qn36, Qn35, Qn34, Qn33}, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, + V3, + Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn32(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + {Qn32, Qn31, Qn30, Qn29, Qn28, Qn27, Qn26, Qn25, + Qn24, Qn23, Qn22, Qn21, Qn20, Qn19, Qn18, Qn17}, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, + V3, + Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qn16(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + {Qn16, Qn15, Qn14, Qn13, Qn12, Qn11, Qn10, Qn9, + Qn8, Qn7, Qn6, Qn5, Qn4, Qn3, Qn2, Qn1}, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, + V3, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp16(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + {Qp1, Qp2, Qp3, Qp4, Qp5, Qp6, Qp7, Qp8, + Qp9, Qp10, Qp11, Qp12, Qp13, Qp14, Qp15, Qp16}, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + V3, + Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp32(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + {Qp17, Qp18, Qp19, Qp20, Qp21, Qp22, Qp23, Qp24, + Qp25, Qp26, Qp27, Qp28, Qp29, Qp30, Qp31, Qp32}, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, + V3, + Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp48(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + {Qp33, Qp34, Qp35, Qp36, Qp37, Qp38, Qp39, Qp40, + Qp41, Qp42, Qp43, Qp44, Qp45, Qp46, Qp47, Qp48}, + Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, + V3, + Qp64, Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp64(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + {Qp49, Qp50, Qp51, Qp52, Qp53, Qp54, Qp55, Qp56, + Qp57, Qp58, Qp59, Qp60, Qp61, Qp62, Qp63, Qp64}, + Qp80, Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, + V3, + Qp80, Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp80(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + {Qp65, Qp66, Qp67, Qp68, Qp69, Qp70, Qp71, Qp72, + Qp73, Qp74, Qp75, Qp76, Qp77, Qp78, Qp79, Qp80}, + Qp96, Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, + V3, + Qp96, Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp96(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + {Qp81, Qp82, Qp83, Qp84, Qp85, Qp86, Qp87, Qp88, + Qp89, Qp90, Qp91, Qp92, Qp93, Qp94, Qp95, Qp96}, + Qp112, Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, + V3, + Qp112, Qp128}}). +-define(REMOVE_UNIQ_P_Qp112(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + {Qp97, Qp98, Qp99, Qp100, Qp101, Qp102, Qp103, Qp104, + Qp105, Qp106, Qp107, Qp108, Qp109, Qp110, Qp111, Qp112}, + Qp128}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, + V3, + Qp128}}). +-define(REMOVE_UNIQ_P_Qp128(P, V1, V2, V3), +remove_unique_p(P, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + {Qp113, Qp114, Qp115, Qp116, Qp117, Qp118, Qp119, Qp120, + Qp121, Qp122, Qp123, Qp124, Qp125, Qp126, Qp127, Qp128}}) -> + {Value, V2} = queue_remove_unique(F, V1), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, + V3}}). + +?REMOVE_UNIQ_P_Qn128(-128, + Qn128, NewQn128, + {NewQn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-127, + Qn127, NewQn127, + {Qn128, NewQn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-126, + Qn126, NewQn126, + {Qn128, Qn127, NewQn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-125, + Qn125, NewQn125, + {Qn128, Qn127, Qn126, NewQn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-124, + Qn124, NewQn124, + {Qn128, Qn127, Qn126, Qn125, NewQn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-123, + Qn123, NewQn123, + {Qn128, Qn127, Qn126, Qn125, Qn124, + NewQn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-122, + Qn122, NewQn122, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, NewQn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-121, + Qn121, NewQn121, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, NewQn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-120, + Qn120, NewQn120, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, NewQn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-119, + Qn119, NewQn119, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, NewQn119, Qn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-118, + Qn118, NewQn118, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, NewQn118, + Qn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-117, + Qn117, NewQn117, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + NewQn117, Qn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-116, + Qn116, NewQn116, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, NewQn116, Qn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-115, + Qn115, NewQn115, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, NewQn115, Qn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-114, + Qn114, NewQn114, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, NewQn114, Qn113}); +?REMOVE_UNIQ_P_Qn128(-113, + Qn113, NewQn113, + {Qn128, Qn127, Qn126, Qn125, Qn124, + Qn123, Qn122, Qn121, Qn120, Qn119, Qn118, + Qn117, Qn116, Qn115, Qn114, NewQn113}); +?REMOVE_UNIQ_P_Qn112(-112, + Qn112, NewQn112, + {NewQn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-111, + Qn111, NewQn111, + {Qn112, NewQn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-110, + Qn110, NewQn110, + {Qn112, Qn111, NewQn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-109, + Qn109, NewQn109, + {Qn112, Qn111, Qn110, NewQn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-108, + Qn108, NewQn108, + {Qn112, Qn111, Qn110, Qn109, NewQn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-107, + Qn107, NewQn107, + {Qn112, Qn111, Qn110, Qn109, Qn108, + NewQn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-106, + Qn106, NewQn106, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, NewQn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-105, + Qn105, NewQn105, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, NewQn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-104, + Qn104, NewQn104, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, NewQn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-103, + Qn103, NewQn103, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, NewQn103, Qn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-102, + Qn102, NewQn102, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, NewQn102, + Qn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-101, + Qn101, NewQn101, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + NewQn101, Qn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-100, + Qn100, NewQn100, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, NewQn100, Qn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-99, + Qn99, NewQn99, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, NewQn99, Qn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-98, + Qn98, NewQn98, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, NewQn98, Qn97}); +?REMOVE_UNIQ_P_Qn112(-97, + Qn97, NewQn97, + {Qn112, Qn111, Qn110, Qn109, Qn108, + Qn107, Qn106, Qn105, Qn104, Qn103, Qn102, + Qn101, Qn100, Qn99, Qn98, NewQn97}); +?REMOVE_UNIQ_P_Qn96(-96, + Qn96, NewQn96, + {NewQn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-95, + Qn95, NewQn95, + {Qn96, NewQn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-94, + Qn94, NewQn94, + {Qn96, Qn95, NewQn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-93, + Qn93, NewQn93, + {Qn96, Qn95, Qn94, NewQn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-92, + Qn92, NewQn92, + {Qn96, Qn95, Qn94, Qn93, NewQn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-91, + Qn91, NewQn91, + {Qn96, Qn95, Qn94, Qn93, Qn92, + NewQn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-90, + Qn90, NewQn90, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, NewQn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-89, + Qn89, NewQn89, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, NewQn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-88, + Qn88, NewQn88, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, NewQn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-87, + Qn87, NewQn87, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, NewQn87, Qn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-86, + Qn86, NewQn86, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, NewQn86, + Qn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-85, + Qn85, NewQn85, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + NewQn85, Qn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-84, + Qn84, NewQn84, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, NewQn84, Qn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-83, + Qn83, NewQn83, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, NewQn83, Qn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-82, + Qn82, NewQn82, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, NewQn82, Qn81}); +?REMOVE_UNIQ_P_Qn96(-81, + Qn81, NewQn81, + {Qn96, Qn95, Qn94, Qn93, Qn92, + Qn91, Qn90, Qn89, Qn88, Qn87, Qn86, + Qn85, Qn84, Qn83, Qn82, NewQn81}); +?REMOVE_UNIQ_P_Qn80(-80, + Qn80, NewQn80, + {NewQn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-79, + Qn79, NewQn79, + {Qn80, NewQn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-78, + Qn78, NewQn78, + {Qn80, Qn79, NewQn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-77, + Qn77, NewQn77, + {Qn80, Qn79, Qn78, NewQn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-76, + Qn76, NewQn76, + {Qn80, Qn79, Qn78, Qn77, NewQn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-75, + Qn75, NewQn75, + {Qn80, Qn79, Qn78, Qn77, Qn76, + NewQn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-74, + Qn74, NewQn74, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, NewQn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-73, + Qn73, NewQn73, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, NewQn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-72, + Qn72, NewQn72, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, NewQn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-71, + Qn71, NewQn71, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, NewQn71, Qn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-70, + Qn70, NewQn70, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, NewQn70, + Qn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-69, + Qn69, NewQn69, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + NewQn69, Qn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-68, + Qn68, NewQn68, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, NewQn68, Qn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-67, + Qn67, NewQn67, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, NewQn67, Qn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-66, + Qn66, NewQn66, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, NewQn66, Qn65}); +?REMOVE_UNIQ_P_Qn80(-65, + Qn65, NewQn65, + {Qn80, Qn79, Qn78, Qn77, Qn76, + Qn75, Qn74, Qn73, Qn72, Qn71, Qn70, + Qn69, Qn68, Qn67, Qn66, NewQn65}); +?REMOVE_UNIQ_P_Qn64(-64, + Qn64, NewQn64, + {NewQn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-63, + Qn63, NewQn63, + {Qn64, NewQn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-62, + Qn62, NewQn62, + {Qn64, Qn63, NewQn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-61, + Qn61, NewQn61, + {Qn64, Qn63, Qn62, NewQn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-60, + Qn60, NewQn60, + {Qn64, Qn63, Qn62, Qn61, NewQn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-59, + Qn59, NewQn59, + {Qn64, Qn63, Qn62, Qn61, Qn60, + NewQn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-58, + Qn58, NewQn58, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, NewQn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-57, + Qn57, NewQn57, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, NewQn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-56, + Qn56, NewQn56, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, NewQn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-55, + Qn55, NewQn55, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, NewQn55, Qn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-54, + Qn54, NewQn54, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, NewQn54, + Qn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-53, + Qn53, NewQn53, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + NewQn53, Qn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-52, + Qn52, NewQn52, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, NewQn52, Qn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-51, + Qn51, NewQn51, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, NewQn51, Qn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-50, + Qn50, NewQn50, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, NewQn50, Qn49}); +?REMOVE_UNIQ_P_Qn64(-49, + Qn49, NewQn49, + {Qn64, Qn63, Qn62, Qn61, Qn60, + Qn59, Qn58, Qn57, Qn56, Qn55, Qn54, + Qn53, Qn52, Qn51, Qn50, NewQn49}); +?REMOVE_UNIQ_P_Qn48(-48, + Qn48, NewQn48, + {NewQn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-47, + Qn47, NewQn47, + {Qn48, NewQn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-46, + Qn46, NewQn46, + {Qn48, Qn47, NewQn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-45, + Qn45, NewQn45, + {Qn48, Qn47, Qn46, NewQn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-44, + Qn44, NewQn44, + {Qn48, Qn47, Qn46, Qn45, NewQn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-43, + Qn43, NewQn43, + {Qn48, Qn47, Qn46, Qn45, Qn44, + NewQn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-42, + Qn42, NewQn42, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, NewQn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-41, + Qn41, NewQn41, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, NewQn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-40, + Qn40, NewQn40, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, NewQn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-39, + Qn39, NewQn39, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, NewQn39, Qn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-38, + Qn38, NewQn38, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, NewQn38, + Qn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-37, + Qn37, NewQn37, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + NewQn37, Qn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-36, + Qn36, NewQn36, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, NewQn36, Qn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-35, + Qn35, NewQn35, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, NewQn35, Qn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-34, + Qn34, NewQn34, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, NewQn34, Qn33}); +?REMOVE_UNIQ_P_Qn48(-33, + Qn33, NewQn33, + {Qn48, Qn47, Qn46, Qn45, Qn44, + Qn43, Qn42, Qn41, Qn40, Qn39, Qn38, + Qn37, Qn36, Qn35, Qn34, NewQn33}); +?REMOVE_UNIQ_P_Qn32(-32, + Qn32, NewQn32, + {NewQn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-31, + Qn31, NewQn31, + {Qn32, NewQn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-30, + Qn30, NewQn30, + {Qn32, Qn31, NewQn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-29, + Qn29, NewQn29, + {Qn32, Qn31, Qn30, NewQn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-28, + Qn28, NewQn28, + {Qn32, Qn31, Qn30, Qn29, NewQn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-27, + Qn27, NewQn27, + {Qn32, Qn31, Qn30, Qn29, Qn28, + NewQn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-26, + Qn26, NewQn26, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, NewQn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-25, + Qn25, NewQn25, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, NewQn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-24, + Qn24, NewQn24, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, NewQn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-23, + Qn23, NewQn23, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, NewQn23, Qn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-22, + Qn22, NewQn22, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, NewQn22, + Qn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-21, + Qn21, NewQn21, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + NewQn21, Qn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-20, + Qn20, NewQn20, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, NewQn20, Qn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-19, + Qn19, NewQn19, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, NewQn19, Qn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-18, + Qn18, NewQn18, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, NewQn18, Qn17}); +?REMOVE_UNIQ_P_Qn32(-17, + Qn17, NewQn17, + {Qn32, Qn31, Qn30, Qn29, Qn28, + Qn27, Qn26, Qn25, Qn24, Qn23, Qn22, + Qn21, Qn20, Qn19, Qn18, NewQn17}); +?REMOVE_UNIQ_P_Qn16(-16, + Qn16, NewQn16, + {NewQn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-15, + Qn15, NewQn15, + {Qn16, NewQn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-14, + Qn14, NewQn14, + {Qn16, Qn15, NewQn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-13, + Qn13, NewQn13, + {Qn16, Qn15, Qn14, NewQn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-12, + Qn12, NewQn12, + {Qn16, Qn15, Qn14, Qn13, NewQn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-11, + Qn11, NewQn11, + {Qn16, Qn15, Qn14, Qn13, Qn12, + NewQn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-10, + Qn10, NewQn10, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, NewQn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-9, + Qn9, NewQn9, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, NewQn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-8, + Qn8, NewQn8, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, NewQn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-7, + Qn7, NewQn7, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, NewQn7, Qn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-6, + Qn6, NewQn6, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, NewQn6, + Qn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-5, + Qn5, NewQn5, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + NewQn5, Qn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-4, + Qn4, NewQn4, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, NewQn4, Qn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-3, + Qn3, NewQn3, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, NewQn3, Qn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-2, + Qn2, NewQn2, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, NewQn2, Qn1}); +?REMOVE_UNIQ_P_Qn16(-1, + Qn1, NewQn1, + {Qn16, Qn15, Qn14, Qn13, Qn12, + Qn11, Qn10, Qn9, Qn8, Qn7, Qn6, + Qn5, Qn4, Qn3, Qn2, NewQn1}); +remove_unique_p(0, F, + {Pc, + Size, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + Q0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}) -> + {Value, NewQ0} = queue_remove_unique(F, Q0), + NewSize = if Value =:= true -> Size - 1; Value =:= false -> Size end, + {Value, + {if NewSize == 0 -> empty; true -> Pc end, + NewSize, + Qn128, Qn112, Qn96, Qn80, Qn64, Qn48, Qn32, Qn16, + NewQ0, + Qp16, Qp32, Qp48, Qp64, Qp80, Qp96, Qp112, Qp128}}; +?REMOVE_UNIQ_P_Qp16(1, + Qp1, NewQp1, + {NewQp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(2, + Qp2, NewQp2, + {Qp1, NewQp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(3, + Qp3, NewQp3, + {Qp1, Qp2, NewQp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(4, + Qp4, NewQp4, + {Qp1, Qp2, Qp3, NewQp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(5, + Qp5, NewQp5, + {Qp1, Qp2, Qp3, Qp4, NewQp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(6, + Qp6, NewQp6, + {Qp1, Qp2, Qp3, Qp4, Qp5, + NewQp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(7, + Qp7, NewQp7, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, NewQp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(8, + Qp8, NewQp8, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, NewQp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(9, + Qp9, NewQp9, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, NewQp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(10, + Qp10, NewQp10, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, NewQp10, Qp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(11, + Qp11, NewQp11, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, NewQp11, + Qp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(12, + Qp12, NewQp12, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + NewQp12, Qp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(13, + Qp13, NewQp13, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, NewQp13, Qp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(14, + Qp14, NewQp14, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, NewQp14, Qp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(15, + Qp15, NewQp15, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, NewQp15, Qp16}); +?REMOVE_UNIQ_P_Qp16(16, + Qp16, NewQp16, + {Qp1, Qp2, Qp3, Qp4, Qp5, + Qp6, Qp7, Qp8, Qp9, Qp10, Qp11, + Qp12, Qp13, Qp14, Qp15, NewQp16}); +?REMOVE_UNIQ_P_Qp32(17, + Qp17, NewQp17, + {NewQp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(18, + Qp18, NewQp18, + {Qp17, NewQp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(19, + Qp19, NewQp19, + {Qp17, Qp18, NewQp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(20, + Qp20, NewQp20, + {Qp17, Qp18, Qp19, NewQp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(21, + Qp21, NewQp21, + {Qp17, Qp18, Qp19, Qp20, NewQp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(22, + Qp22, NewQp22, + {Qp17, Qp18, Qp19, Qp20, Qp21, + NewQp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(23, + Qp23, NewQp23, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, NewQp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(24, + Qp24, NewQp24, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, NewQp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(25, + Qp25, NewQp25, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, NewQp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(26, + Qp26, NewQp26, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, NewQp26, Qp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(27, + Qp27, NewQp27, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, NewQp27, + Qp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(28, + Qp28, NewQp28, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + NewQp28, Qp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(29, + Qp29, NewQp29, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, NewQp29, Qp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(30, + Qp30, NewQp30, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, NewQp30, Qp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(31, + Qp31, NewQp31, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, NewQp31, Qp32}); +?REMOVE_UNIQ_P_Qp32(32, + Qp32, NewQp32, + {Qp17, Qp18, Qp19, Qp20, Qp21, + Qp22, Qp23, Qp24, Qp25, Qp26, Qp27, + Qp28, Qp29, Qp30, Qp31, NewQp32}); +?REMOVE_UNIQ_P_Qp48(33, + Qp33, NewQp33, + {NewQp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(34, + Qp34, NewQp34, + {Qp33, NewQp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(35, + Qp35, NewQp35, + {Qp33, Qp34, NewQp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(36, + Qp36, NewQp36, + {Qp33, Qp34, Qp35, NewQp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(37, + Qp37, NewQp37, + {Qp33, Qp34, Qp35, Qp36, NewQp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(38, + Qp38, NewQp38, + {Qp33, Qp34, Qp35, Qp36, Qp37, + NewQp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(39, + Qp39, NewQp39, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, NewQp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(40, + Qp40, NewQp40, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, NewQp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(41, + Qp41, NewQp41, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, NewQp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(42, + Qp42, NewQp42, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, NewQp42, Qp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(43, + Qp43, NewQp43, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, NewQp43, + Qp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(44, + Qp44, NewQp44, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + NewQp44, Qp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(45, + Qp45, NewQp45, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, NewQp45, Qp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(46, + Qp46, NewQp46, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, NewQp46, Qp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(47, + Qp47, NewQp47, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, NewQp47, Qp48}); +?REMOVE_UNIQ_P_Qp48(48, + Qp48, NewQp48, + {Qp33, Qp34, Qp35, Qp36, Qp37, + Qp38, Qp39, Qp40, Qp41, Qp42, Qp43, + Qp44, Qp45, Qp46, Qp47, NewQp48}); +?REMOVE_UNIQ_P_Qp64(49, + Qp49, NewQp49, + {NewQp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(50, + Qp50, NewQp50, + {Qp49, NewQp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(51, + Qp51, NewQp51, + {Qp49, Qp50, NewQp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(52, + Qp52, NewQp52, + {Qp49, Qp50, Qp51, NewQp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(53, + Qp53, NewQp53, + {Qp49, Qp50, Qp51, Qp52, NewQp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(54, + Qp54, NewQp54, + {Qp49, Qp50, Qp51, Qp52, Qp53, + NewQp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(55, + Qp55, NewQp55, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, NewQp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(56, + Qp56, NewQp56, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, NewQp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(57, + Qp57, NewQp57, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, NewQp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(58, + Qp58, NewQp58, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, NewQp58, Qp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(59, + Qp59, NewQp59, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, NewQp59, + Qp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(60, + Qp60, NewQp60, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + NewQp60, Qp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(61, + Qp61, NewQp61, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, NewQp61, Qp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(62, + Qp62, NewQp62, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, NewQp62, Qp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(63, + Qp63, NewQp63, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, NewQp63, Qp64}); +?REMOVE_UNIQ_P_Qp64(64, + Qp64, NewQp64, + {Qp49, Qp50, Qp51, Qp52, Qp53, + Qp54, Qp55, Qp56, Qp57, Qp58, Qp59, + Qp60, Qp61, Qp62, Qp63, NewQp64}); +?REMOVE_UNIQ_P_Qp80(65, + Qp65, NewQp65, + {NewQp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(66, + Qp66, NewQp66, + {Qp65, NewQp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(67, + Qp67, NewQp67, + {Qp65, Qp66, NewQp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(68, + Qp68, NewQp68, + {Qp65, Qp66, Qp67, NewQp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(69, + Qp69, NewQp69, + {Qp65, Qp66, Qp67, Qp68, NewQp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(70, + Qp70, NewQp70, + {Qp65, Qp66, Qp67, Qp68, Qp69, + NewQp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(71, + Qp71, NewQp71, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, NewQp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(72, + Qp72, NewQp72, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, NewQp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(73, + Qp73, NewQp73, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, NewQp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(74, + Qp74, NewQp74, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, NewQp74, Qp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(75, + Qp75, NewQp75, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, NewQp75, + Qp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(76, + Qp76, NewQp76, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + NewQp76, Qp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(77, + Qp77, NewQp77, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, NewQp77, Qp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(78, + Qp78, NewQp78, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, NewQp78, Qp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(79, + Qp79, NewQp79, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, NewQp79, Qp80}); +?REMOVE_UNIQ_P_Qp80(80, + Qp80, NewQp80, + {Qp65, Qp66, Qp67, Qp68, Qp69, + Qp70, Qp71, Qp72, Qp73, Qp74, Qp75, + Qp76, Qp77, Qp78, Qp79, NewQp80}); +?REMOVE_UNIQ_P_Qp96(81, + Qp81, NewQp81, + {NewQp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(82, + Qp82, NewQp82, + {Qp81, NewQp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(83, + Qp83, NewQp83, + {Qp81, Qp82, NewQp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(84, + Qp84, NewQp84, + {Qp81, Qp82, Qp83, NewQp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(85, + Qp85, NewQp85, + {Qp81, Qp82, Qp83, Qp84, NewQp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(86, + Qp86, NewQp86, + {Qp81, Qp82, Qp83, Qp84, Qp85, + NewQp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(87, + Qp87, NewQp87, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, NewQp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(88, + Qp88, NewQp88, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, NewQp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(89, + Qp89, NewQp89, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, NewQp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(90, + Qp90, NewQp90, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, NewQp90, Qp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(91, + Qp91, NewQp91, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, NewQp91, + Qp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(92, + Qp92, NewQp92, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + NewQp92, Qp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(93, + Qp93, NewQp93, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, NewQp93, Qp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(94, + Qp94, NewQp94, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, NewQp94, Qp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(95, + Qp95, NewQp95, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, NewQp95, Qp96}); +?REMOVE_UNIQ_P_Qp96(96, + Qp96, NewQp96, + {Qp81, Qp82, Qp83, Qp84, Qp85, + Qp86, Qp87, Qp88, Qp89, Qp90, Qp91, + Qp92, Qp93, Qp94, Qp95, NewQp96}); +?REMOVE_UNIQ_P_Qp112(97, + Qp97, NewQp97, + {NewQp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(98, + Qp98, NewQp98, + {Qp97, NewQp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(99, + Qp99, NewQp99, + {Qp97, Qp98, NewQp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(100, + Qp100, NewQp100, + {Qp97, Qp98, Qp99, NewQp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(101, + Qp101, NewQp101, + {Qp97, Qp98, Qp99, Qp100, NewQp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(102, + Qp102, NewQp102, + {Qp97, Qp98, Qp99, Qp100, Qp101, + NewQp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(103, + Qp103, NewQp103, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, NewQp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(104, + Qp104, NewQp104, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, NewQp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(105, + Qp105, NewQp105, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, NewQp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(106, + Qp106, NewQp106, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, NewQp106, Qp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(107, + Qp107, NewQp107, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, NewQp107, + Qp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(108, + Qp108, NewQp108, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + NewQp108, Qp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(109, + Qp109, NewQp109, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, NewQp109, Qp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(110, + Qp110, NewQp110, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, NewQp110, Qp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(111, + Qp111, NewQp111, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, NewQp111, Qp112}); +?REMOVE_UNIQ_P_Qp112(112, + Qp112, NewQp112, + {Qp97, Qp98, Qp99, Qp100, Qp101, + Qp102, Qp103, Qp104, Qp105, Qp106, Qp107, + Qp108, Qp109, Qp110, Qp111, NewQp112}); +?REMOVE_UNIQ_P_Qp128(113, + Qp113, NewQp113, + {NewQp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(114, + Qp114, NewQp114, + {Qp113, NewQp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(115, + Qp115, NewQp115, + {Qp113, Qp114, NewQp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(116, + Qp116, NewQp116, + {Qp113, Qp114, Qp115, NewQp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(117, + Qp117, NewQp117, + {Qp113, Qp114, Qp115, Qp116, NewQp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(118, + Qp118, NewQp118, + {Qp113, Qp114, Qp115, Qp116, Qp117, + NewQp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(119, + Qp119, NewQp119, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, NewQp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(120, + Qp120, NewQp120, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, NewQp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(121, + Qp121, NewQp121, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, NewQp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(122, + Qp122, NewQp122, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, NewQp122, Qp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(123, + Qp123, NewQp123, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, NewQp123, + Qp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(124, + Qp124, NewQp124, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + NewQp124, Qp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(125, + Qp125, NewQp125, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, NewQp125, Qp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(126, + Qp126, NewQp126, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, NewQp126, Qp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(127, + Qp127, NewQp127, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, NewQp127, Qp128}); +?REMOVE_UNIQ_P_Qp128(128, + Qp128, NewQp128, + {Qp113, Qp114, Qp115, Qp116, Qp117, + Qp118, Qp119, Qp120, Qp121, Qp122, Qp123, + Qp124, Qp125, Qp126, Qp127, NewQp128}). + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +-include("pqueue_test.hrl"). + +module_test_() -> + {timeout, ?TEST_TIMEOUT, [ + {"internal tests", ?_assertOk(test())} + ]}. + +long_test_() -> + test_condition([ + {"proper tests", ?_assert(pqueue_proper:qc_pq4())} + ], ?CLOUDI_LONG_TEST_TIMEOUT). + +-endif. + +%%------------------------------------------------------------------------- +%% @hidden +%% remove a unique value from a queue based on a binary predicate, +%% traversal order is undefined to keep it efficient (i.e., shouldn't matter) +%% (based on the implementation of queue:filter/2 +%% which is under the Apache License 2.0) +%%------------------------------------------------------------------------- + +-spec queue_remove_unique(F :: fun((any()) -> boolean()), + Q :: {list(), list()}) -> + {boolean(), {list(), list()}}. + +queue_remove_unique(Fun, {R0, F0} = Q) + when is_function(Fun, 1), is_list(R0), is_list(F0) -> + case queue_remove_unique_f(Fun, F0) of + {true, []} -> + {true, queue_r2f(R0)}; + {true, F1} -> + {true, {R0, F1}}; + {false, F1} -> + %true = F1 == F0, + case queue_remove_unique_f(Fun, R0) of % backwards + {true, []} -> + {true, queue_f2r(F1)}; + {true, R1} -> + {true, {R1, F1}}; + {false, _} -> + {false, Q} + end + end; +queue_remove_unique(Fun, Q) -> + erlang:error(badarg, [Fun,Q]). + +% Call Fun in front to back order +queue_remove_unique_f(_, [] = F) -> + {false, F}; +queue_remove_unique_f(Fun, F) -> + queue_remove_unique_f(F, [], F, Fun). + +queue_remove_unique_f([], _, F, _) -> + {false, F}; +queue_remove_unique_f([X | F0], F1, F, Fun) -> + case Fun(X) of + true -> + {true, lists:reverse(F1, F0)}; + false -> + queue_remove_unique_f(F0, [X | F1], F, Fun) + end. + +-compile({inline, [{queue_r2f,1},{queue_f2r,1}]}). + +% Move half of elements from R to F, if there are at least three +queue_r2f([]) -> + {[],[]}; +queue_r2f([_]=R) -> + {[],R}; +queue_r2f([X,Y]) -> + {[X],[Y]}; +queue_r2f(List) -> + {FF,RR} = lists:split(length(List) div 2 + 1, List), + {FF,lists:reverse(RR, [])}. + +% Move half of elements from F to R, if there are enough +queue_f2r([]) -> + {[],[]}; +queue_f2r([_]=F) -> + {F,[]}; +queue_f2r([X,Y]) -> + {[Y],[X]}; +queue_f2r(List) -> + {FF,RR} = lists:split(length(List) div 2 + 1, List), + {lists:reverse(RR, []),FF}. + diff --git a/aoc2023/build/dev/erlang/pqueue/src/pqueue_test.hrl b/aoc2023/build/dev/erlang/pqueue/src/pqueue_test.hrl new file mode 100644 index 0000000..cedffe0 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/src/pqueue_test.hrl @@ -0,0 +1,49 @@ +%-*-Mode:erlang;coding:utf-8;tab-width:4;c-basic-offset:4;indent-tabs-mode:()-*- +% ex: set ft=erlang fenc=utf-8 sts=4 ts=4 sw=4 et nomod: +%%% +%%%------------------------------------------------------------------------ +%%% pqueue eunit common functionality +%%% +%%% MIT License +%%% +%%% Copyright (c) 2020 Michael Truog <mjtruog at protonmail dot com> +%%% +%%% Permission is hereby granted, free of charge, to any person obtaining a +%%% copy of this software and associated documentation files (the "Software"), +%%% to deal in the Software without restriction, including without limitation +%%% the rights to use, copy, modify, merge, publish, distribute, sublicense, +%%% and/or sell copies of the Software, and to permit persons to whom the +%%% Software is furnished to do so, subject to the following conditions: +%%% +%%% The above copyright notice and this permission notice shall be included in +%%% all copies or substantial portions of the Software. +%%% +%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +%%% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +%%% DEALINGS IN THE SOFTWARE. +%%% +%%%------------------------------------------------------------------------ + +-ifndef(_assertOk). +-define(_assertOk(Expr), ?_assertEqual(ok, Expr)). +-endif. + +-ifdef(CLOUDI_TEST_TIMEOUT). +-define(TEST_TIMEOUT, ?CLOUDI_TEST_TIMEOUT). % seconds +-else. +-define(TEST_TIMEOUT, 10). % seconds +-endif. +-ifndef(CLOUDI_LONG_TEST_TIMEOUT). +-define(CLOUDI_LONG_TEST_TIMEOUT, 60). % minutes +-endif. + +test_condition(_, 0) -> + []; +test_condition(L, LongTestTimeout) + when LongTestTimeout > 0 -> + {timeout, LongTestTimeout * 60, L}. + diff --git a/aoc2023/build/dev/erlang/pqueue/test/pqueue_proper.erl b/aoc2023/build/dev/erlang/pqueue/test/pqueue_proper.erl new file mode 100644 index 0000000..6702960 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/test/pqueue_proper.erl @@ -0,0 +1,156 @@ +-module(pqueue_proper). +-ifdef(TEST). +-include_lib("proper/include/proper.hrl"). + +-behaviour(proper_statem). + +-export([qc_pq/0, qc_pq2/0, qc_pq3/0, qc_pq4/0, correct/1]). + +-export([command/1, initial_state/0, next_state/3, postcondition/3, + precondition/2]). + +-type value() :: integer(). +-record(state, { in_queue :: [{value(), term()}] }). +-define(SERVER, queue_srv). + +priority() -> + integer(-20, 20). + +%% Selects priorities we have added +priority(InQ) -> + elements([P || {P, _} <- InQ]). + +value() -> + integer(). + +initial_state() -> + #state { in_queue = [] }. + +command(#state { in_queue = InQ }) -> + oneof([{call, ?SERVER, in, [value()]}, + {call, ?SERVER, in, [value(), priority()]}, + {call, ?SERVER, is_empty, []}, + {call, ?SERVER, is_queue, []}, + {call, ?SERVER, len, []}, + {call, ?SERVER, out, []}] ++ + [{call, ?SERVER, out, [priority(InQ)]} || InQ =/= []] ++ + [{call, ?SERVER, pout, []}, + {call, ?SERVER, to_list, []}]). + +next_state(#state { in_queue = InQ } = S, _V, {call, _, out, []}) -> + S#state { in_queue = listq_rem(InQ) }; +next_state(#state { in_queue = InQ } = S, _V, {call, _, out, [Prio]}) -> + S#state { in_queue = listq_rem(InQ, Prio) }; +next_state(#state { in_queue = InQ } = S, _V, {call, _, pout, _}) -> + S#state { in_queue = listq_rem(InQ) }; +next_state(S, _V, {call, _, to_list, _}) -> S; +next_state(S, _V, {call, _, is_queue, _}) -> S; +next_state(S, _V, {call, _, is_empty, _}) -> S; +next_state(S, _V, {call, _, len, _}) -> S; +next_state(#state { in_queue = InQ } = S, _V, {call, _, in, [Value, Prio]}) -> + S#state { in_queue = listq_insert({Prio, Value}, InQ) }; +next_state(#state { in_queue = InQ } = S, _V, {call, _, in, [Value]}) -> + S#state { in_queue = listq_insert({0, Value}, InQ) }. + +precondition(_S, _Call) -> + true. % No limitation on the things we can call at all. + +postcondition(#state { in_queue = InQ }, {call, _, out, [Prio]}, R) -> + R == listq_prio_peek(InQ, Prio); +postcondition(#state { in_queue = InQ }, {call, _, pout, _}, R) -> + R == listq_ppeek(InQ); +postcondition(#state { in_queue = InQ }, {call, _, out, _}, R) -> + R == listq_peek(InQ); +postcondition(S, {call, _, to_list, _}, R) -> + R == listq_to_list(S#state.in_queue); +postcondition(S, {call, _, len, _}, L) -> + L == listq_length(S#state.in_queue); +postcondition(_S, {call, _, is_queue, _}, true) -> true; +postcondition(S, {call, _, is_empty, _}, Res) -> + Res == (S#state.in_queue == []); +postcondition(_S, {call, _, in, _}, _) -> + true; +postcondition(_, _, _) -> + false. + +correct(M) -> + ?FORALL(Cmds, commands(?MODULE), + ?TRAPEXIT( + begin + ?SERVER:start_link(M), + {History,State,Result} = run_commands(?MODULE, Cmds), + ?SERVER:stop(), + ?WHENFAIL(io:format("History: ~w\nState: ~w\nResult: ~w\n", + [History,State,Result]), + aggregate(command_names(Cmds), Result =:= ok)) + end)). + +qc_opts() -> + [{numtests, 10000}]. + +qc_pq() -> + proper:quickcheck(pqueue_proper:correct(pqueue), qc_opts()). + +qc_pq2() -> + proper:quickcheck(pqueue_proper:correct(pqueue2), qc_opts()). + +qc_pq3() -> + proper:quickcheck(pqueue_proper:correct(pqueue3), qc_opts()). + +qc_pq4() -> + proper:quickcheck(pqueue_proper:correct(pqueue4), qc_opts()). + +%% ---------------------------------------------------------------------- + +%% A listq is a sorted list of priorities +listq_insert({P, V}, []) -> + [{P, [V]}]; +listq_insert({P, V}, [{P1, _} | _] = LQ) when P < P1 -> + [{P, [V]} | LQ]; +listq_insert({P, V}, [{P1, Vs} | Next]) when P == P1 -> + [{P, Vs ++ [V]} | Next]; +listq_insert({P, V}, [{P1, Vs} | Next]) when P > P1 -> + [{P1, Vs} | listq_insert({P, V}, Next)]. + +listq_to_list(L) -> + lists:concat( + [ Vals || {_Prio, Vals} <- L]). + +listq_length(L) -> + lists:sum( + [ length(Vs) || {_Prio, Vs} <- L]). + +listq_rem([]) -> + []; +listq_rem([{_P, [_V]} | Next]) -> + Next; +listq_rem([{P, [_V1 | Vs]} | Next]) -> + [{P, Vs} | Next]. + +listq_rem([], _P) -> + []; +listq_rem([{P, [_]} | Next], P) -> + Next; +listq_rem([{P, [_ | Vs]} | Next], P) -> + [{P, Vs} | Next]; +listq_rem([{P1, Vs} | Next], P) -> + [{P1, Vs} | listq_rem(Next, P)]. + +listq_peek([]) -> + empty; +listq_peek([{_P, [V | _]} | _]) -> + {value, V}. + +listq_prio_peek([{P, [V | _]} | _], P) -> + {value, V}; +listq_prio_peek([{_P1, _} | Next], P) -> + listq_prio_peek(Next, P); +listq_prio_peek([], _P) -> + empty. + +listq_ppeek([]) -> + empty; +listq_ppeek([{P, [V | _]} | _]) -> + {value, V, P}. + +-endif. diff --git a/aoc2023/build/dev/erlang/pqueue/test/queue_srv.erl b/aoc2023/build/dev/erlang/pqueue/test/queue_srv.erl new file mode 100644 index 0000000..7fcb0a1 --- /dev/null +++ b/aoc2023/build/dev/erlang/pqueue/test/queue_srv.erl @@ -0,0 +1,183 @@ +%%%------------------------------------------------------------------- +%%% @author Jesper Louis andersen <> +%%% @copyright (C) 2011, Jesper Louis andersen +%%% @doc +%%% +%%% @end +%%% Created : 11 Nov 2011 by Jesper Louis andersen <> +%%%------------------------------------------------------------------- +-module(queue_srv). + +-behaviour(gen_server). + +%% API +-export([start_link/1, stop/0, len/0, in/1, in/2, is_empty/0, + out/0, out/1, pout/0, + is_queue/0, to_list/0]). + +%% gen_server callbacks +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +-define(SERVER, ?MODULE). + +-record(state, { mod, q }). + +%%%=================================================================== +%%% API +%%%=================================================================== + +%%-------------------------------------------------------------------- +%% @doc +%% Starts the server +%% +%% @spec start_link(Mod) -> {ok, Pid} | ignore | {error, Error} +%% @end +%%-------------------------------------------------------------------- +start_link(Mod) -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [Mod], []). + +stop() -> + gen_server:stop(?SERVER). + +call(M) -> + gen_server:call(?SERVER, M, infinity). + +in(I) -> + call({in, I}). + +in(I, P) -> + call({in, I, P}). + +len() -> + call(len). + +is_empty() -> + call(is_empty). + +is_queue() -> + call(is_queue). + +to_list() -> + call(to_list). + +out() -> + call(out). + +out(P) -> + call({out, P}). + +pout() -> + call(pout). + +%%%=================================================================== +%%% gen_server callbacks +%%%=================================================================== + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Initializes the server +%% +%% @spec init(Args) -> {ok, State} | +%% {ok, State, Timeout} | +%% ignore | +%% {stop, Reason} +%% @end +%%-------------------------------------------------------------------- +init([Mod]) -> + {ok, #state{ mod = Mod, + q = Mod:new() }}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling call messages +%% +%% @spec handle_call(Request, From, State) -> +%% {reply, Reply, State} | +%% {reply, Reply, State, Timeout} | +%% {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, Reply, State} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_call({in, Item}, _F, #state { q = Q, mod = M } = S) -> + NQ = M:in(Item, Q), + {reply, ok, S#state { q = NQ }}; +handle_call({in, Item, Prio}, _F, #state { q = Q, mod = M } = S) -> + NQ = M:in(Item, Prio, Q), + {reply, ok, S#state { q = NQ }}; +handle_call({out, P}, _F, #state { q = Q, mod = M } = S) -> + {R, NQ} = M:out(P, Q), + {reply, R, S#state { q = NQ }}; +handle_call(Ty, _F, #state { q = Q, mod = M } = S) when Ty == out; + Ty == pout -> + {R, NQ} = M:Ty(Q), + {reply, R, S#state { q = NQ }}; +handle_call(Ty, _F, #state { q = Q, mod = M } = S) when Ty == is_queue; + Ty == is_empty; + Ty == len; + Ty == to_list -> + R = M:Ty(Q), + {reply, R, S}; +handle_call(Req, From, State) -> + error_logger:info_report([{handle_call, Req, From, State}]), + Reply = ok, + {reply, Reply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling cast messages +%% +%% @spec handle_cast(Msg, State) -> {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_cast(_Msg, State) -> + {noreply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Handling all non call/cast messages +%% +%% @spec handle_info(Info, State) -> {noreply, State} | +%% {noreply, State, Timeout} | +%% {stop, Reason, State} +%% @end +%%-------------------------------------------------------------------- +handle_info(_Info, State) -> + {noreply, State}. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% This function is called by a gen_server when it is about to +%% terminate. It should be the opposite of Module:init/1 and do any +%% necessary cleaning up. When it returns, the gen_server terminates +%% with Reason. The return value is ignored. +%% +%% @spec terminate(Reason, State) -> void() +%% @end +%%-------------------------------------------------------------------- +terminate(_Reason, _State) -> + ok. + +%%-------------------------------------------------------------------- +%% @private +%% @doc +%% Convert process state when code is changed +%% +%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} +%% @end +%%-------------------------------------------------------------------- +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%%%=================================================================== +%%% Internal functions +%%%=================================================================== diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache Binary files differnew file mode 100644 index 0000000..bf0b1d7 --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache_meta b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache_meta Binary files differnew file mode 100644 index 0000000..90aa893 --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.cache_meta diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.erl b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.erl new file mode 100644 index 0000000..2dbeac9 --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile.erl @@ -0,0 +1,287 @@ +-module(simplifile). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([read/1, write/2, delete/1, delete_all/1, append/2, read_bits/1, write_bits/2, append_bits/2, is_directory/1, create_directory/1, read_directory/1, is_file/1, create_file/1, get_files/1, create_directory_all/1, copy_directory/2, rename_directory/2, copy_file/2, rename_file/2]). +-export_type([file_error/0]). + +-type file_error() :: eacces | + eagain | + ebadf | + ebadmsg | + ebusy | + edeadlk | + edeadlock | + edquot | + eexist | + efault | + efbig | + eftype | + eintr | + einval | + eio | + eisdir | + eloop | + emfile | + emlink | + emultihop | + enametoolong | + enfile | + enobufs | + enodev | + enolck | + enolink | + enoent | + enomem | + enospc | + enosr | + enostr | + enosys | + enotblk | + enotdir | + enotsup | + enxio | + eopnotsupp | + eoverflow | + eperm | + epipe | + erange | + erofs | + espipe | + esrch | + estale | + etxtbsy | + exdev | + not_utf8 | + unknown. + +-spec do_append(binary(), binary()) -> {ok, nil} | {error, file_error()}. +do_append(Content, Filepath) -> + _pipe = Content, + _pipe@1 = gleam_stdlib:identity(_pipe), + simplifile_erl:append_file(_pipe@1, Filepath). + +-spec do_write(binary(), binary()) -> {ok, nil} | {error, file_error()}. +do_write(Content, Filepath) -> + _pipe = Content, + _pipe@1 = gleam_stdlib:identity(_pipe), + simplifile_erl:write_file(_pipe@1, Filepath). + +-spec do_read(binary()) -> {ok, binary()} | {error, file_error()}. +do_read(Filepath) -> + case simplifile_erl:read_file(Filepath) of + {ok, Bits} -> + case gleam@bit_array:to_string(Bits) of + {ok, Str} -> + {ok, Str}; + + _ -> + {error, not_utf8} + end; + + {error, E} -> + {error, E} + end. + +-spec cast_error({ok, FJY} | {error, file_error()}) -> {ok, FJY} | + {error, file_error()}. +cast_error(Input) -> + Input. + +-spec read(binary()) -> {ok, binary()} | {error, file_error()}. +read(Filepath) -> + _pipe = do_read(Filepath), + cast_error(_pipe). + +-spec write(binary(), binary()) -> {ok, nil} | {error, file_error()}. +write(Filepath, Contents) -> + _pipe = do_write(Contents, Filepath), + cast_error(_pipe). + +-spec delete(binary()) -> {ok, nil} | {error, file_error()}. +delete(Path) -> + _pipe = simplifile_erl:recursive_delete(Path), + cast_error(_pipe). + +-spec delete_all(list(binary())) -> {ok, nil} | {error, file_error()}. +delete_all(Paths) -> + case Paths of + [] -> + {ok, nil}; + + [Path | Rest] -> + case delete(Path) of + {ok, nil} -> + delete_all(Rest); + + {error, enoent} -> + delete_all(Rest); + + E -> + E + end + end. + +-spec append(binary(), binary()) -> {ok, nil} | {error, file_error()}. +append(Filepath, Contents) -> + _pipe = do_append(Contents, Filepath), + cast_error(_pipe). + +-spec read_bits(binary()) -> {ok, bitstring()} | {error, file_error()}. +read_bits(Filepath) -> + _pipe = simplifile_erl:read_file(Filepath), + cast_error(_pipe). + +-spec write_bits(binary(), bitstring()) -> {ok, nil} | {error, file_error()}. +write_bits(Filepath, Bits) -> + _pipe = simplifile_erl:write_file(Bits, Filepath), + cast_error(_pipe). + +-spec append_bits(binary(), bitstring()) -> {ok, nil} | {error, file_error()}. +append_bits(Filepath, Bits) -> + _pipe = simplifile_erl:append_file(Bits, Filepath), + cast_error(_pipe). + +-spec is_directory(binary()) -> boolean(). +is_directory(Filepath) -> + filelib:is_dir(Filepath). + +-spec create_directory(binary()) -> {ok, nil} | {error, file_error()}. +create_directory(Filepath) -> + _pipe = simplifile_erl:make_directory(Filepath), + cast_error(_pipe). + +-spec read_directory(binary()) -> {ok, list(binary())} | {error, file_error()}. +read_directory(Path) -> + _pipe = simplifile_erl:list_directory(Path), + cast_error(_pipe). + +-spec is_file(binary()) -> boolean(). +is_file(Filepath) -> + simplifile_erl:is_file(Filepath). + +-spec create_file(binary()) -> {ok, nil} | {error, file_error()}. +create_file(Filepath) -> + case begin + _pipe = Filepath, + is_file(_pipe) + end + orelse begin + _pipe@1 = Filepath, + is_directory(_pipe@1) + end of + true -> + {error, eexist}; + + false -> + write_bits(Filepath, <<>>) + end. + +-spec do_copy_directory(binary(), binary()) -> {ok, nil} | {error, file_error()}. +do_copy_directory(Src, Dest) -> + gleam@result:'try'( + read_directory(Src), + fun(Segments) -> + _pipe = Segments, + gleam@list:each( + _pipe, + fun(Segment) -> + Src_path = <<<<Src/binary, "/"/utf8>>/binary, + Segment/binary>>, + Dest_path = <<<<Dest/binary, "/"/utf8>>/binary, + Segment/binary>>, + case {is_file(Src_path), is_directory(Src_path)} of + {true, false} -> + gleam@result:'try'( + read_bits(Src_path), + fun(Content) -> _pipe@1 = Content, + write_bits(Dest_path, _pipe@1) end + ); + + {false, true} -> + gleam@result:'try'( + create_directory(Dest_path), + fun(_) -> + do_copy_directory(Src_path, Dest_path) + end + ); + + {_, _} -> + erlang:error(#{gleam_error => panic, + message => <<"unreachable"/utf8>>, + module => <<"simplifile"/utf8>>, + function => <<"do_copy_directory"/utf8>>, + line => 341}) + end + end + ), + {ok, nil} + end + ). + +-spec get_files(binary()) -> {ok, list(binary())} | {error, file_error()}. +get_files(Directory) -> + gleam@result:'try'( + read_directory(Directory), + fun(Contents) -> + Paths = gleam@list:map( + Contents, + fun(Segment) -> + <<<<Directory/binary, "/"/utf8>>/binary, Segment/binary>> + end + ), + Files = gleam@list:filter(Paths, fun is_file/1), + case gleam@list:filter(Paths, fun is_directory/1) of + [] -> + {ok, Files}; + + Directories -> + gleam@result:'try'( + gleam@list:try_map(Directories, fun get_files/1), + fun(Nested_files) -> + {ok, + gleam@list:append( + Files, + gleam@list:flatten(Nested_files) + )} + end + ) + end + end + ). + +-spec create_directory_all(binary()) -> {ok, nil} | {error, file_error()}. +create_directory_all(Dirpath) -> + Path = case begin + _pipe = Dirpath, + gleam@string:ends_with(_pipe, <<"/"/utf8>>) + end of + true -> + Dirpath; + + false -> + <<Dirpath/binary, "/"/utf8>> + end, + _pipe@1 = simplifile_erl:create_dir_all(Path), + cast_error(_pipe@1). + +-spec copy_directory(binary(), binary()) -> {ok, nil} | {error, file_error()}. +copy_directory(Src, Dest) -> + gleam@result:'try'( + create_directory_all(Dest), + fun(_) -> do_copy_directory(Src, Dest) end + ). + +-spec rename_directory(binary(), binary()) -> {ok, nil} | {error, file_error()}. +rename_directory(Src, Dest) -> + gleam@result:'try'(copy_directory(Src, Dest), fun(_) -> delete(Src) end). + +-spec copy_file(binary(), binary()) -> {ok, nil} | {error, file_error()}. +copy_file(Src, Dest) -> + _pipe = file:copy(Src, Dest), + _pipe@1 = gleam@result:replace(_pipe, nil), + cast_error(_pipe@1). + +-spec rename_file(binary(), binary()) -> {ok, nil} | {error, file_error()}. +rename_file(Src, Dest) -> + _pipe = simplifile_erl:rename_file(Src, Dest), + cast_error(_pipe). diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl new file mode 100644 index 0000000..dac135a --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_erl.erl @@ -0,0 +1,70 @@ +-module(simplifile_erl). +-export([ + read_file/1, + append_file/2, write_file/2, delete_file/1, delete_directory/1, recursive_delete/1, + list_directory/1, make_directory/1, is_file/1, create_dir_all/1, rename_file/2 +]). + +-define(is_posix_error(Error), + Error =:= eacces orelse Error =:= eagain orelse Error =:= ebadf orelse + Error =:= ebadmsg orelse Error =:= ebusy orelse Error =:= edeadlk orelse + Error =:= edeadlock orelse Error =:= edquot orelse Error =:= eexist orelse + Error =:= efault orelse Error =:= efbig orelse Error =:= eftype orelse + Error =:= eintr orelse Error =:= einval orelse Error =:= eio orelse + Error =:= eisdir orelse Error =:= eloop orelse Error =:= emfile orelse + Error =:= emlink orelse Error =:= emultihop orelse Error =:= enametoolong orelse + Error =:= enfile orelse Error =:= enobufs orelse Error =:= enodev orelse + Error =:= enolck orelse Error =:= enolink orelse Error =:= enoent orelse + Error =:= enomem orelse Error =:= enospc orelse Error =:= enosr orelse + Error =:= enostr orelse Error =:= enosys orelse Error =:= enotblk orelse + Error =:= enotdir orelse Error =:= enotsup orelse Error =:= enxio orelse + Error =:= eopnotsupp orelse Error =:= eoverflow orelse Error =:= eperm orelse + Error =:= epipe orelse Error =:= erange orelse Error =:= erofs orelse + Error =:= espipe orelse Error =:= esrch orelse Error =:= estale orelse + Error =:= etxtbsy orelse Error =:= exdev +). + +posix_result(Result) -> + case Result of + ok -> {ok, nil}; + {ok, Value} -> {ok, Value}; + {error, Reason} when ?is_posix_error(Reason) -> {error, Reason} + end. + +read_file(Filename) -> + posix_result(file:read_file(Filename)). + +write_file(Contents, Filename) -> + posix_result(file:write_file(Filename, Contents)). + +append_file(Contents, Filename) -> + posix_result(file:write_file(Filename, Contents, [append])). + +delete_file(Filename) -> + posix_result(file:delete(Filename)). + +make_directory(Dir) -> + posix_result(file:make_dir(Dir)). + +list_directory(Dir) -> + case file:list_dir(Dir) of + {ok, Filenames} -> + {ok, [list_to_binary(Filename) || Filename <- Filenames]}; + {error, Reason} when ?is_posix_error(Reason) -> + {error, Reason} + end. + +delete_directory(Dir) -> + posix_result(file:del_dir(Dir)). + +recursive_delete(Dir) -> + posix_result(file:del_dir_r(Dir)). + +is_file(Filename) -> + not (file:read_file_info(Filename) == {error, enoent}) and not filelib: is_dir(Filename). + +create_dir_all(Filename) -> + posix_result(filelib:ensure_dir(Filename)). + +rename_file(Source, Destination) -> + posix_result(file:rename(Source, Destination)). diff --git a/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_js.mjs b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_js.mjs new file mode 100644 index 0000000..faf4109 --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/_gleam_artefacts/simplifile_js.mjs @@ -0,0 +1,102 @@ +import fs from "node:fs" +import path from "node:path" +import { BitArray, Ok, Error as GError, toList} from "./gleam.mjs"; + +export function readBits(filepath) { + try { + const contents = fs.readFileSync(path.normalize(filepath)) + return new Ok(new BitArray(new Uint8Array(contents))) + } catch(e) { + return new GError(stringifyError(e)) + } +} + +export function writeBits(contents, filepath) { + try { + fs.writeFileSync(path.normalize(filepath), contents.buffer) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +export function appendBits(contents, filepath) { + try { + fs.appendFileSync(path.normalize(filepath), contents.buffer) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +function stringifyError(e) { + return e.code +} + +export function isFile(filepath) { + let fp = path.normalize(filepath) + return fs.existsSync(fp) && fs.lstatSync(fp).isFile(); +} + +export function isDirectory(filepath) { + let fp = path.normalize(filepath) + return fs.existsSync(fp) && fs.lstatSync(fp).isDirectory(); +} + +export function makeDirectory(filepath) { + try { + fs.mkdirSync(path.normalize(filepath)) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +export function createDirAll(filepath) { + try { + fs.mkdirSync(filepath, { recursive: true }) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +export function deleteFileOrDirRecursive(fileOrDirPath) { + try { + if (isDirectory(fileOrDirPath)) { + fs.rmSync(path.normalize(fileOrDirPath), { recursive: true }) + } else { + fs.unlinkSync(path.normalize(fileOrDirPath)) + } + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +export function listContents(filepath) { + try { + const stuff = toList(fs.readdirSync(path.normalize(filepath))) + return new Ok(stuff) + } catch(e) { + return new GError(stringifyError(e)) + } +} + +export function copyFile(srcpath, destpath) { + try { + fs.copyFileSync(path.normalize(srcpath), path.normalize(destpath)) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +} + +export function renameFile(srcpath, destpath) { + try { + fs.renameSync(path.normalize(srcpath), path.normalize(destpath)) + return new Ok(undefined) + } catch (e) { + return new GError(stringifyError(e)) + } +}
\ No newline at end of file diff --git a/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.app b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.app new file mode 100644 index 0000000..3bb63fa --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.app @@ -0,0 +1,7 @@ +{application, simplifile, [ + {vsn, "1.0.0"}, + {applications, [gleam_stdlib]}, + {description, "Basic file operations that work on all targets"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.beam b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.beam Binary files differnew file mode 100644 index 0000000..6631cad --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile.beam diff --git a/aoc2023/build/dev/erlang/simplifile/ebin/simplifile_erl.beam b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile_erl.beam Binary files differnew file mode 100644 index 0000000..2abefda --- /dev/null +++ b/aoc2023/build/dev/erlang/simplifile/ebin/simplifile_erl.beam diff --git a/aoc2023/build/dev/erlang/snag/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache Binary files differnew file mode 100644 index 0000000..bc9c27c --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache diff --git a/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache_meta b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache_meta Binary files differnew file mode 100644 index 0000000..daef1e9 --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.cache_meta diff --git a/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.erl b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.erl new file mode 100644 index 0000000..92d4f80 --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/_gleam_artefacts/snag.erl @@ -0,0 +1,74 @@ +-module(snag). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([new/1, error/1, layer/2, context/2, pretty_print/1, line_print/1]). +-export_type([snag/0]). + +-type snag() :: {snag, binary(), list(binary())}. + +-spec new(binary()) -> snag(). +new(Issue) -> + {snag, Issue, []}. + +-spec error(binary()) -> {ok, any()} | {error, snag()}. +error(Issue) -> + {error, new(Issue)}. + +-spec layer(snag(), binary()) -> snag(). +layer(Snag, Issue) -> + {snag, Issue, [erlang:element(2, Snag) | erlang:element(3, Snag)]}. + +-spec context({ok, KFH} | {error, snag()}, binary()) -> {ok, KFH} | + {error, snag()}. +context(Result, Issue) -> + case Result of + {ok, _} -> + Result; + + {error, Snag} -> + {error, layer(Snag, Issue)} + end. + +-spec pretty_print_cause(list(binary())) -> gleam@string_builder:string_builder(). +pretty_print_cause(Cause) -> + _pipe = Cause, + _pipe@1 = gleam@list:index_map( + _pipe, + fun(Index, Line) -> + gleam@string:concat( + [<<" "/utf8>>, + gleam@int:to_string(Index), + <<": "/utf8>>, + Line, + <<"\n"/utf8>>] + ) + end + ), + gleam@string_builder:from_strings(_pipe@1). + +-spec pretty_print(snag()) -> binary(). +pretty_print(Snag) -> + Builder = gleam@string_builder:from_strings( + [<<"error: "/utf8>>, erlang:element(2, Snag), <<"\n"/utf8>>] + ), + gleam@string_builder:to_string(case erlang:element(3, Snag) of + [] -> + Builder; + + Cause -> + _pipe = Builder, + _pipe@1 = gleam@string_builder:append( + _pipe, + <<"\ncause:\n"/utf8>> + ), + gleam@string_builder:append_builder( + _pipe@1, + pretty_print_cause(Cause) + ) + end). + +-spec line_print(snag()) -> binary(). +line_print(Snag) -> + _pipe = [gleam@string:append(<<"error: "/utf8>>, erlang:element(2, Snag)) | + erlang:element(3, Snag)], + gleam@string:join(_pipe, <<" <- "/utf8>>). diff --git a/aoc2023/build/dev/erlang/snag/ebin/snag.app b/aoc2023/build/dev/erlang/snag/ebin/snag.app new file mode 100644 index 0000000..724fb97 --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/ebin/snag.app @@ -0,0 +1,7 @@ +{application, snag, [ + {vsn, "0.2.1"}, + {applications, [gleam_stdlib]}, + {description, "A boilerplate-free ad-hoc error type"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/snag/ebin/snag.beam b/aoc2023/build/dev/erlang/snag/ebin/snag.beam Binary files differnew file mode 100644 index 0000000..896068a --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/ebin/snag.beam diff --git a/aoc2023/build/dev/erlang/snag/include/snag_Snag.hrl b/aoc2023/build/dev/erlang/snag/include/snag_Snag.hrl new file mode 100644 index 0000000..5d6614e --- /dev/null +++ b/aoc2023/build/dev/erlang/snag/include/snag_Snag.hrl @@ -0,0 +1 @@ +-record(snag, {issue :: binary(), cause :: list(binary())}). diff --git a/aoc2023/build/dev/erlang/tom/_gleam_artefacts/gleam@@compile.erl b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/gleam@@compile.erl new file mode 100644 index 0000000..543db88 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/gleam@@compile.erl @@ -0,0 +1,157 @@ +#!/usr/bin/env escript + +% TODO: Don't concurrently print warnings and errors +% TODO: Some tests + +-record(arguments, {lib = "./", out = "./", modules = []}). + +main(Args) -> + #arguments{out = Out, lib = Lib, modules = Modules} = parse(Args), + IsElixirModule = fun(Module) -> + filename:extension(Module) =:= ".ex" + end, + {ElixirModules, ErlangModules} = lists:partition(IsElixirModule, Modules), + ok = configure_logging(), + ok = add_lib_to_erlang_path(Lib), + ok = filelib:ensure_dir([Out, $/]), + {ErlangOk, _ErlangBeams} = compile_erlang(ErlangModules, Out), + {ElixirOk, _ElixirBeams} = case ErlangOk of + true -> compile_elixir(ElixirModules, Out); + false -> {false, []} + end, + case ErlangOk and ElixirOk of + true -> ok; + false -> erlang:halt(1) + end. + +compile_erlang(Modules, Out) -> + Workers = start_compiler_workers(Out), + ok = producer_loop(Modules, Workers), + collect_results({true, []}). + +collect_results(Acc = {Result, Beams}) -> + receive + {compiled, Beam} -> collect_results({Result, [Beam | Beams]}); + failed -> collect_results({false, Beams}) + after 0 -> Acc + end. + +producer_loop([], 0) -> + ok; +producer_loop([], Workers) -> + receive + {work_please, _} -> producer_loop([], Workers - 1) + end; +producer_loop([Module | Modules], Workers) -> + receive + {work_please, Worker} -> + erlang:send(Worker, {module, Module}), + producer_loop(Modules, Workers) + end. + +start_compiler_workers(Out) -> + Parent = self(), + NumSchedulers = erlang:system_info(schedulers), + SpawnWorker = fun(_) -> + erlang:spawn_link(fun() -> worker_loop(Parent, Out) end) + end, + lists:foreach(SpawnWorker, lists:seq(1, NumSchedulers)), + NumSchedulers. + +worker_loop(Parent, Out) -> + Options = [report_errors, report_warnings, debug_info, {outdir, Out}], + erlang:send(Parent, {work_please, self()}), + receive + {module, Module} -> + log({compiling, Module}), + case compile:file(Module, Options) of + {ok, ModuleName} -> + Beam = filename:join(Out, ModuleName) ++ ".beam", + Message = {compiled, Beam}, + log(Message), + erlang:send(Parent, Message); + error -> + log({failed, Module}), + erlang:send(Parent, failed) + end, + worker_loop(Parent, Out) + end. + +compile_elixir(Modules, Out) -> + Error = [ + "The program elixir was not found. Is it installed?", + $\n, + "Documentation for installing Elixir can be viewed here:", + $\n, + "https://elixir-lang.org/install.html" + ], + case Modules of + [] -> {true, []}; + _ -> + log({starting, "compiler.app"}), + ok = application:start(compiler), + log({starting, "elixir.app"}), + case application:start(elixir) of + ok -> do_compile_elixir(Modules, Out); + _ -> + io:put_chars(standard_error, [Error, $\n]), + {false, []} + end + end. + +do_compile_elixir(Modules, Out) -> + ModuleBins = lists:map(fun(Module) -> + log({compiling, Module}), + list_to_binary(Module) + end, Modules), + OutBin = list_to_binary(Out), + Options = [{dest, OutBin}], + % Silence "redefining module" warnings. + % Compiled modules in the build directory are added to the code path. + % These warnings result from recompiling loaded modules. + % TODO: This line can likely be removed if/when the build directory is cleaned before every compilation. + 'Elixir.Code':compiler_options([{ignore_module_conflict, true}]), + case 'Elixir.Kernel.ParallelCompiler':compile_to_path(ModuleBins, OutBin, Options) of + {ok, ModuleAtoms, _} -> + ToBeam = fun(ModuleAtom) -> + Beam = filename:join(Out, atom_to_list(ModuleAtom)) ++ ".beam", + log({compiled, Beam}), + Beam + end, + {true, lists:map(ToBeam, ModuleAtoms)}; + {error, Errors, _} -> + % Log all filenames associated with modules that failed to compile. + % Note: The compiler prints compilation errors upon encountering them. + ErrorFiles = lists:usort([File || {File, _, _} <- Errors]), + Log = fun(File) -> + log({failed, binary_to_list(File)}) + end, + lists:foreach(Log, ErrorFiles), + {false, []}; + _ -> {false, []} + end. + +add_lib_to_erlang_path(Lib) -> + code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + +parse(Args) -> + parse(Args, #arguments{}). + +parse([], Arguments) -> + Arguments; +parse(["--lib", Lib | Rest], Arguments) -> + parse(Rest, Arguments#arguments{lib = Lib}); +parse(["--out", Out | Rest], Arguments) -> + parse(Rest, Arguments#arguments{out = Out}); +parse([Module | Rest], Arguments = #arguments{modules = Modules}) -> + parse(Rest, Arguments#arguments{modules = [Module | Modules]}). + +configure_logging() -> + Enabled = os:getenv("GLEAM_LOG") /= false, + persistent_term:put(gleam_logging_enabled, Enabled). + +log(Term) -> + case persistent_term:get(gleam_logging_enabled) of + true -> erlang:display(Term), ok; + false -> ok + end. diff --git a/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache Binary files differnew file mode 100644 index 0000000..c9b63ee --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache diff --git a/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache_meta b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache_meta Binary files differnew file mode 100644 index 0000000..492599b --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.cache_meta diff --git a/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.erl b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.erl new file mode 100644 index 0000000..05ab1a6 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/_gleam_artefacts/tom.erl @@ -0,0 +1,2142 @@ +-module(tom). +-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). + +-export([get/2, get_int/2, get_float/2, get_bool/2, get_string/2, get_date/2, get_time/2, get_date_time/2, get_array/2, get_table/2, get_number/2, parse/1]). +-export_type([toml/0, date_time/0, date/0, time/0, offset/0, sign/0, parse_error/0, number_/0, get_error/0]). + +-type toml() :: {int, integer()} | + {float, float()} | + {infinity, sign()} | + {nan, sign()} | + {bool, boolean()} | + {string, binary()} | + {date, date()} | + {time, time()} | + {date_time, date_time()} | + {array, list(toml())} | + {array_of_tables, list(gleam@dict:dict(binary(), toml()))} | + {table, gleam@dict:dict(binary(), toml())} | + {inline_table, gleam@dict:dict(binary(), toml())}. + +-type date_time() :: {date_time_value, date(), time(), offset()}. + +-type date() :: {date_value, integer(), integer(), integer()}. + +-type time() :: {time_value, integer(), integer(), integer(), integer()}. + +-type offset() :: local | {offset, sign(), integer(), integer()}. + +-type sign() :: positive | negative. + +-type parse_error() :: {unexpected, binary(), binary()} | + {key_already_in_use, list(binary())}. + +-type number_() :: {number_int, integer()} | + {number_float, float()} | + {number_infinity, sign()} | + {number_nan, sign()}. + +-type get_error() :: {not_found, list(binary())} | + {wrong_type, list(binary()), binary(), binary()}. + +-spec classify(toml()) -> binary(). +classify(Toml) -> + case Toml of + {int, _} -> + <<"Int"/utf8>>; + + {float, _} -> + <<"Float"/utf8>>; + + {nan, positive} -> + <<"NaN"/utf8>>; + + {nan, negative} -> + <<"Negative NaN"/utf8>>; + + {infinity, positive} -> + <<"Infinity"/utf8>>; + + {infinity, negative} -> + <<"Negative Infinity"/utf8>>; + + {bool, _} -> + <<"Bool"/utf8>>; + + {string, _} -> + <<"String"/utf8>>; + + {date, _} -> + <<"Date"/utf8>>; + + {time, _} -> + <<"Time"/utf8>>; + + {date_time, _} -> + <<"DateTime"/utf8>>; + + {array, _} -> + <<"Array"/utf8>>; + + {array_of_tables, _} -> + <<"Array"/utf8>>; + + {table, _} -> + <<"Table"/utf8>>; + + {inline_table, _} -> + <<"Table"/utf8>> + end. + +-spec push_key({ok, LOB} | {error, get_error()}, binary()) -> {ok, LOB} | + {error, get_error()}. +push_key(Result, Key) -> + case Result of + {ok, T} -> + {ok, T}; + + {error, {not_found, Path}} -> + {error, {not_found, [Key | Path]}}; + + {error, {wrong_type, Path@1, Expected, Got}} -> + {error, {wrong_type, [Key | Path@1], Expected, Got}} + end. + +-spec get(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, toml()} | + {error, get_error()}. +get(Toml, Key) -> + case Key of + [] -> + {error, {not_found, []}}; + + [K] -> + gleam@result:replace_error(gleam@map:get(Toml, K), {not_found, [K]}); + + [K@1 | Key@1] -> + case gleam@map:get(Toml, K@1) of + {ok, {table, T}} -> + push_key(get(T, Key@1), K@1); + + {ok, Other} -> + {error, + {wrong_type, [K@1], <<"Table"/utf8>>, classify(Other)}}; + + {error, _} -> + {error, {not_found, [K@1]}} + end + end. + +-spec get_int(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + integer()} | + {error, get_error()}. +get_int(Toml, Key) -> + case get(Toml, Key) of + {ok, {int, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Int"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_float(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + float()} | + {error, get_error()}. +get_float(Toml, Key) -> + case get(Toml, Key) of + {ok, {float, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Float"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_bool(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + boolean()} | + {error, get_error()}. +get_bool(Toml, Key) -> + case get(Toml, Key) of + {ok, {bool, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Bool"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_string(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + binary()} | + {error, get_error()}. +get_string(Toml, Key) -> + case get(Toml, Key) of + {ok, {string, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"String"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_date(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + date()} | + {error, get_error()}. +get_date(Toml, Key) -> + case get(Toml, Key) of + {ok, {date, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Date"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_time(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + time()} | + {error, get_error()}. +get_time(Toml, Key) -> + case get(Toml, Key) of + {ok, {time, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Time"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_date_time(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + date_time()} | + {error, get_error()}. +get_date_time(Toml, Key) -> + case get(Toml, Key) of + {ok, {date_time, I}} -> + {ok, I}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"DateTime"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_array(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + list(toml())} | + {error, get_error()}. +get_array(Toml, Key) -> + case get(Toml, Key) of + {ok, {array, I}} -> + {ok, I}; + + {ok, {array_of_tables, I@1}} -> + {ok, gleam@list:map(I@1, fun(Field@0) -> {table, Field@0} end)}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Array"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_table(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + gleam@dict:dict(binary(), toml())} | + {error, get_error()}. +get_table(Toml, Key) -> + case get(Toml, Key) of + {ok, {table, I}} -> + {ok, I}; + + {ok, {inline_table, I@1}} -> + {ok, I@1}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Table"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec get_number(gleam@dict:dict(binary(), toml()), list(binary())) -> {ok, + number_()} | + {error, get_error()}. +get_number(Toml, Key) -> + case get(Toml, Key) of + {ok, {int, X}} -> + {ok, {number_int, X}}; + + {ok, {float, X@1}} -> + {ok, {number_float, X@1}}; + + {ok, {nan, X@2}} -> + {ok, {number_nan, X@2}}; + + {ok, {infinity, X@3}} -> + {ok, {number_infinity, X@3}}; + + {ok, Other} -> + {error, {wrong_type, Key, <<"Number"/utf8>>, classify(Other)}}; + + {error, E} -> + {error, E} + end. + +-spec merge(gleam@dict:dict(binary(), toml()), binary(), toml(), toml()) -> {ok, + gleam@dict:dict(binary(), toml())} | + {error, list(binary())}. +merge(Table, Key, Old, New) -> + case {Old, New} of + {{array_of_tables, Tables}, {array_of_tables, New@1}} -> + {ok, + gleam@map:insert( + Table, + Key, + {array_of_tables, gleam@list:append(New@1, Tables)} + )}; + + {_, _} -> + {error, [Key]} + end. + +-spec insert_loop(gleam@dict:dict(binary(), toml()), list(binary()), toml()) -> {ok, + gleam@dict:dict(binary(), toml())} | + {error, list(binary())}. +insert_loop(Table, Key, Value) -> + case Key of + [] -> + erlang:error(#{gleam_error => panic, + message => <<"unreachable"/utf8>>, + module => <<"tom"/utf8>>, + function => <<"insert_loop"/utf8>>, + line => 511}); + + [K] -> + case gleam@map:get(Table, K) of + {error, nil} -> + {ok, gleam@map:insert(Table, K, Value)}; + + {ok, Old} -> + merge(Table, K, Old, Value) + end; + + [K@1 | Key@1] -> + case gleam@map:get(Table, K@1) of + {error, nil} -> + case insert_loop(gleam@map:new(), Key@1, Value) of + {ok, Inner} -> + {ok, gleam@map:insert(Table, K@1, {table, Inner})}; + + {error, Path} -> + {error, [K@1 | Path]} + end; + + {ok, {array_of_tables, [Inner@1 | Rest]}} -> + case insert_loop(Inner@1, Key@1, Value) of + {ok, Inner@2} -> + {ok, + gleam@map:insert( + Table, + K@1, + {array_of_tables, [Inner@2 | Rest]} + )}; + + {error, Path@1} -> + {error, [K@1 | Path@1]} + end; + + {ok, {table, Inner@3}} -> + case insert_loop(Inner@3, Key@1, Value) of + {ok, Inner@4} -> + {ok, gleam@map:insert(Table, K@1, {table, Inner@4})}; + + {error, Path@2} -> + {error, [K@1 | Path@2]} + end; + + {ok, _} -> + {error, [K@1]} + end + end. + +-spec insert(gleam@dict:dict(binary(), toml()), list(binary()), toml()) -> {ok, + gleam@dict:dict(binary(), toml())} | + {error, parse_error()}. +insert(Table, Key, Value) -> + case insert_loop(Table, Key, Value) of + {ok, Table@1} -> + {ok, Table@1}; + + {error, Path} -> + {error, {key_already_in_use, Path}} + end. + +-spec expect_end_of_line( + list(binary()), + fun((list(binary())) -> {ok, {LQG, list(binary())}} | {error, parse_error()}) +) -> {ok, {LQG, list(binary())}} | {error, parse_error()}. +expect_end_of_line(Input, Next) -> + case Input of + [<<"\n"/utf8>> | Input@1] -> + Next(Input@1); + + [<<"\r\n"/utf8>> | Input@2] -> + Next(Input@2); + + [G | _] -> + {error, {unexpected, G, <<"\n"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"\n"/utf8>>}} + end. + +-spec parse_key_quoted(list(binary()), binary(), binary()) -> {ok, + {binary(), list(binary())}} | + {error, parse_error()}. +parse_key_quoted(Input, Close, Name) -> + case Input of + [G | Input@1] when G =:= Close -> + {ok, {Name, Input@1}}; + + [G@1 | Input@2] -> + parse_key_quoted(Input@2, Close, <<Name/binary, G@1/binary>>); + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, Close}} + end. + +-spec parse_key_bare(list(binary()), binary()) -> {ok, + {binary(), list(binary())}} | + {error, parse_error()}. +parse_key_bare(Input, Name) -> + case Input of + [<<" "/utf8>> | Input@1] when Name =/= <<""/utf8>> -> + {ok, {Name, Input@1}}; + + [<<"="/utf8>> | _] when Name =/= <<""/utf8>> -> + {ok, {Name, Input}}; + + [<<"."/utf8>> | _] when Name =/= <<""/utf8>> -> + {ok, {Name, Input}}; + + [<<"]"/utf8>> | _] when Name =/= <<""/utf8>> -> + {ok, {Name, Input}}; + + [<<","/utf8>> | _] when Name =/= <<""/utf8>> -> + {error, {unexpected, <<","/utf8>>, <<"="/utf8>>}}; + + [<<"\n"/utf8>> | _] when Name =/= <<""/utf8>> -> + {error, {unexpected, <<"\n"/utf8>>, <<"="/utf8>>}}; + + [<<"\r\n"/utf8>> | _] when Name =/= <<""/utf8>> -> + {error, {unexpected, <<"\r\n"/utf8>>, <<"="/utf8>>}}; + + [<<"\n"/utf8>> | _] -> + {error, {unexpected, <<"\n"/utf8>>, <<"key"/utf8>>}}; + + [<<"\r\n"/utf8>> | _] -> + {error, {unexpected, <<"\r\n"/utf8>>, <<"key"/utf8>>}}; + + [<<"]"/utf8>> | _] -> + {error, {unexpected, <<"]"/utf8>>, <<"key"/utf8>>}}; + + [<<","/utf8>> | _] -> + {error, {unexpected, <<","/utf8>>, <<"key"/utf8>>}}; + + [G | Input@2] -> + parse_key_bare(Input@2, <<Name/binary, G/binary>>); + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"key"/utf8>>}} + end. + +-spec skip_line_whitespace(list(binary())) -> list(binary()). +skip_line_whitespace(Input) -> + gleam@list:drop_while( + Input, + fun(G) -> (G =:= <<" "/utf8>>) orelse (G =:= <<"\t"/utf8>>) end + ). + +-spec parse_key_segment(list(binary())) -> {ok, {binary(), list(binary())}} | + {error, parse_error()}. +parse_key_segment(Input) -> + Input@1 = skip_line_whitespace(Input), + case Input@1 of + [<<"="/utf8>> | _] -> + {error, {unexpected, <<"="/utf8>>, <<"Key"/utf8>>}}; + + [<<"\n"/utf8>> | _] -> + {error, {unexpected, <<"\n"/utf8>>, <<"Key"/utf8>>}}; + + [<<"\r\n"/utf8>> | _] -> + {error, {unexpected, <<"\r\n"/utf8>>, <<"Key"/utf8>>}}; + + [<<"["/utf8>> | _] -> + {error, {unexpected, <<"["/utf8>>, <<"Key"/utf8>>}}; + + [<<"\""/utf8>> | Input@2] -> + parse_key_quoted(Input@2, <<"\""/utf8>>, <<""/utf8>>); + + [<<"'"/utf8>> | Input@3] -> + parse_key_quoted(Input@3, <<"'"/utf8>>, <<""/utf8>>); + + _ -> + parse_key_bare(Input@1, <<""/utf8>>) + end. + +-spec skip_whitespace(list(binary())) -> list(binary()). +skip_whitespace(Input) -> + case Input of + [<<" "/utf8>> | Input@1] -> + skip_whitespace(Input@1); + + [<<"\t"/utf8>> | Input@2] -> + skip_whitespace(Input@2); + + [<<"\n"/utf8>> | Input@3] -> + skip_whitespace(Input@3); + + [<<"\r\n"/utf8>> | Input@4] -> + skip_whitespace(Input@4); + + Input@5 -> + Input@5 + end. + +-spec drop_comments(list(binary()), list(binary())) -> list(binary()). +drop_comments(Input, Acc) -> + case Input of + [<<"#"/utf8>> | Input@1] -> + _pipe = Input@1, + _pipe@1 = gleam@list:drop_while( + _pipe, + fun(G) -> G /= <<"\n"/utf8>> end + ), + drop_comments(_pipe@1, Acc); + + [G@1 | Input@2] -> + drop_comments(Input@2, [G@1 | Acc]); + + [] -> + gleam@list:reverse(Acc) + end. + +-spec do( + {ok, {LQR, list(binary())}} | {error, parse_error()}, + fun((LQR, list(binary())) -> {ok, LQU} | {error, parse_error()}) +) -> {ok, LQU} | {error, parse_error()}. +do(Result, Next) -> + case Result of + {ok, {A, Input}} -> + Next(A, Input); + + {error, E} -> + {error, E} + end. + +-spec parse_key(list(binary()), list(binary())) -> {ok, + {list(binary()), list(binary())}} | + {error, parse_error()}. +parse_key(Input, Segments) -> + do( + parse_key_segment(Input), + fun(Segment, Input@1) -> + Segments@1 = [Segment | Segments], + Input@2 = skip_line_whitespace(Input@1), + case Input@2 of + [<<"."/utf8>> | Input@3] -> + parse_key(Input@3, Segments@1); + + _ -> + {ok, {gleam@list:reverse(Segments@1), Input@2}} + end + end + ). + +-spec expect( + list(binary()), + binary(), + fun((list(binary())) -> {ok, {LQZ, list(binary())}} | {error, parse_error()}) +) -> {ok, {LQZ, list(binary())}} | {error, parse_error()}. +expect(Input, Expected, Next) -> + case Input of + [G | Input@1] when G =:= Expected -> + Next(Input@1); + + [G@1 | _] -> + {error, {unexpected, G@1, Expected}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, Expected}} + end. + +-spec parse_table_header(list(binary())) -> {ok, + {list(binary()), list(binary())}} | + {error, parse_error()}. +parse_table_header(Input) -> + Input@1 = skip_line_whitespace(Input), + do( + parse_key(Input@1, []), + fun(Key, Input@2) -> + expect( + Input@2, + <<"]"/utf8>>, + fun(Input@3) -> + Input@4 = skip_line_whitespace(Input@3), + expect_end_of_line( + Input@4, + fun(Input@5) -> {ok, {Key, Input@5}} end + ) + end + ) + end + ). + +-spec parse_hex(list(binary()), integer(), sign()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_hex(Input, Number, Sign) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_hex(Input@1, Number, Sign); + + [<<"0"/utf8>> | Input@2] -> + parse_hex(Input@2, (Number * 16) + 0, Sign); + + [<<"1"/utf8>> | Input@3] -> + parse_hex(Input@3, (Number * 16) + 1, Sign); + + [<<"2"/utf8>> | Input@4] -> + parse_hex(Input@4, (Number * 16) + 2, Sign); + + [<<"3"/utf8>> | Input@5] -> + parse_hex(Input@5, (Number * 16) + 3, Sign); + + [<<"4"/utf8>> | Input@6] -> + parse_hex(Input@6, (Number * 16) + 4, Sign); + + [<<"5"/utf8>> | Input@7] -> + parse_hex(Input@7, (Number * 16) + 5, Sign); + + [<<"6"/utf8>> | Input@8] -> + parse_hex(Input@8, (Number * 16) + 6, Sign); + + [<<"7"/utf8>> | Input@9] -> + parse_hex(Input@9, (Number * 16) + 7, Sign); + + [<<"8"/utf8>> | Input@10] -> + parse_hex(Input@10, (Number * 16) + 8, Sign); + + [<<"9"/utf8>> | Input@11] -> + parse_hex(Input@11, (Number * 16) + 9, Sign); + + [<<"a"/utf8>> | Input@12] -> + parse_hex(Input@12, (Number * 16) + 10, Sign); + + [<<"b"/utf8>> | Input@13] -> + parse_hex(Input@13, (Number * 16) + 11, Sign); + + [<<"c"/utf8>> | Input@14] -> + parse_hex(Input@14, (Number * 16) + 12, Sign); + + [<<"d"/utf8>> | Input@15] -> + parse_hex(Input@15, (Number * 16) + 13, Sign); + + [<<"e"/utf8>> | Input@16] -> + parse_hex(Input@16, (Number * 16) + 14, Sign); + + [<<"f"/utf8>> | Input@17] -> + parse_hex(Input@17, (Number * 16) + 15, Sign); + + [<<"A"/utf8>> | Input@18] -> + parse_hex(Input@18, (Number * 16) + 10, Sign); + + [<<"B"/utf8>> | Input@19] -> + parse_hex(Input@19, (Number * 16) + 11, Sign); + + [<<"C"/utf8>> | Input@20] -> + parse_hex(Input@20, (Number * 16) + 12, Sign); + + [<<"D"/utf8>> | Input@21] -> + parse_hex(Input@21, (Number * 16) + 13, Sign); + + [<<"E"/utf8>> | Input@22] -> + parse_hex(Input@22, (Number * 16) + 14, Sign); + + [<<"F"/utf8>> | Input@23] -> + parse_hex(Input@23, (Number * 16) + 15, Sign); + + Input@24 -> + Number@1 = case Sign of + positive -> + Number; + + negative -> + - Number + end, + {ok, {{int, Number@1}, Input@24}} + end. + +-spec parse_octal(list(binary()), integer(), sign()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_octal(Input, Number, Sign) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_octal(Input@1, Number, Sign); + + [<<"0"/utf8>> | Input@2] -> + parse_octal(Input@2, (Number * 8) + 0, Sign); + + [<<"1"/utf8>> | Input@3] -> + parse_octal(Input@3, (Number * 8) + 1, Sign); + + [<<"2"/utf8>> | Input@4] -> + parse_octal(Input@4, (Number * 8) + 2, Sign); + + [<<"3"/utf8>> | Input@5] -> + parse_octal(Input@5, (Number * 8) + 3, Sign); + + [<<"4"/utf8>> | Input@6] -> + parse_octal(Input@6, (Number * 8) + 4, Sign); + + [<<"5"/utf8>> | Input@7] -> + parse_octal(Input@7, (Number * 8) + 5, Sign); + + [<<"6"/utf8>> | Input@8] -> + parse_octal(Input@8, (Number * 8) + 6, Sign); + + [<<"7"/utf8>> | Input@9] -> + parse_octal(Input@9, (Number * 8) + 7, Sign); + + Input@10 -> + Number@1 = case Sign of + positive -> + Number; + + negative -> + - Number + end, + {ok, {{int, Number@1}, Input@10}} + end. + +-spec parse_binary(list(binary()), integer(), sign()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_binary(Input, Number, Sign) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_binary(Input@1, Number, Sign); + + [<<"0"/utf8>> | Input@2] -> + parse_binary(Input@2, (Number * 2) + 0, Sign); + + [<<"1"/utf8>> | Input@3] -> + parse_binary(Input@3, (Number * 2) + 1, Sign); + + Input@4 -> + Number@1 = case Sign of + positive -> + Number; + + negative -> + - Number + end, + {ok, {{int, Number@1}, Input@4}} + end. + +-spec parse_exponent(list(binary()), float(), sign(), integer(), sign()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_exponent(Input, N, N_sign, Ex, Ex_sign) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_exponent(Input@1, N, N_sign, Ex, Ex_sign); + + [<<"0"/utf8>> | Input@2] -> + parse_exponent(Input@2, N, N_sign, Ex * 10, Ex_sign); + + [<<"1"/utf8>> | Input@3] -> + parse_exponent(Input@3, N, N_sign, (Ex * 10) + 1, Ex_sign); + + [<<"2"/utf8>> | Input@4] -> + parse_exponent(Input@4, N, N_sign, (Ex * 10) + 2, Ex_sign); + + [<<"3"/utf8>> | Input@5] -> + parse_exponent(Input@5, N, N_sign, (Ex * 10) + 3, Ex_sign); + + [<<"4"/utf8>> | Input@6] -> + parse_exponent(Input@6, N, N_sign, (Ex * 10) + 4, Ex_sign); + + [<<"5"/utf8>> | Input@7] -> + parse_exponent(Input@7, N, N_sign, (Ex * 10) + 5, Ex_sign); + + [<<"6"/utf8>> | Input@8] -> + parse_exponent(Input@8, N, N_sign, (Ex * 10) + 6, Ex_sign); + + [<<"7"/utf8>> | Input@9] -> + parse_exponent(Input@9, N, N_sign, (Ex * 10) + 7, Ex_sign); + + [<<"8"/utf8>> | Input@10] -> + parse_exponent(Input@10, N, N_sign, (Ex * 10) + 8, Ex_sign); + + [<<"9"/utf8>> | Input@11] -> + parse_exponent(Input@11, N, N_sign, (Ex * 10) + 9, Ex_sign); + + Input@12 -> + Number = case N_sign of + positive -> + N; + + negative -> + N * -1.0 + end, + Exponent = gleam@int:to_float(case Ex_sign of + positive -> + Ex; + + negative -> + - Ex + end), + Multiplier@1 = case gleam@float:power(10.0, Exponent) of + {ok, Multiplier} -> + Multiplier; + + {error, _} -> + 1.0 + end, + {ok, {{float, Number * Multiplier@1}, Input@12}} + end. + +-spec parse_float(list(binary()), float(), sign(), float()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_float(Input, Number, Sign, Unit) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_float(Input@1, Number, Sign, Unit); + + [<<"0"/utf8>> | Input@2] -> + parse_float(Input@2, Number, Sign, Unit * 0.1); + + [<<"1"/utf8>> | Input@3] -> + parse_float(Input@3, Number + (1.0 * Unit), Sign, Unit * 0.1); + + [<<"2"/utf8>> | Input@4] -> + parse_float(Input@4, Number + (2.0 * Unit), Sign, Unit * 0.1); + + [<<"3"/utf8>> | Input@5] -> + parse_float(Input@5, Number + (3.0 * Unit), Sign, Unit * 0.1); + + [<<"4"/utf8>> | Input@6] -> + parse_float(Input@6, Number + (4.0 * Unit), Sign, Unit * 0.1); + + [<<"5"/utf8>> | Input@7] -> + parse_float(Input@7, Number + (5.0 * Unit), Sign, Unit * 0.1); + + [<<"6"/utf8>> | Input@8] -> + parse_float(Input@8, Number + (6.0 * Unit), Sign, Unit * 0.1); + + [<<"7"/utf8>> | Input@9] -> + parse_float(Input@9, Number + (7.0 * Unit), Sign, Unit * 0.1); + + [<<"8"/utf8>> | Input@10] -> + parse_float(Input@10, Number + (8.0 * Unit), Sign, Unit * 0.1); + + [<<"9"/utf8>> | Input@11] -> + parse_float(Input@11, Number + (9.0 * Unit), Sign, Unit * 0.1); + + [<<"e"/utf8>>, <<"+"/utf8>> | Input@12] -> + parse_exponent(Input@12, Number, Sign, 0, positive); + + [<<"e"/utf8>>, <<"-"/utf8>> | Input@13] -> + parse_exponent(Input@13, Number, Sign, 0, negative); + + [<<"e"/utf8>> | Input@14] -> + parse_exponent(Input@14, Number, Sign, 0, positive); + + [<<"E"/utf8>>, <<"+"/utf8>> | Input@15] -> + parse_exponent(Input@15, Number, Sign, 0, positive); + + [<<"E"/utf8>>, <<"-"/utf8>> | Input@16] -> + parse_exponent(Input@16, Number, Sign, 0, negative); + + [<<"E"/utf8>> | Input@17] -> + parse_exponent(Input@17, Number, Sign, 0, positive); + + Input@18 -> + Number@1 = case Sign of + positive -> + Number; + + negative -> + Number * -1.0 + end, + {ok, {{float, Number@1}, Input@18}} + end. + +-spec parse_string(list(binary()), binary()) -> {ok, {toml(), list(binary())}} | + {error, parse_error()}. +parse_string(Input, String) -> + case Input of + [<<"\""/utf8>> | Input@1] -> + {ok, {{string, String}, Input@1}}; + + [<<"\\"/utf8>>, <<"t"/utf8>> | Input@2] -> + parse_string(Input@2, <<String/binary, "\t"/utf8>>); + + [<<"\\"/utf8>>, <<"n"/utf8>> | Input@3] -> + parse_string(Input@3, <<String/binary, "\n"/utf8>>); + + [<<"\\"/utf8>>, <<"r"/utf8>> | Input@4] -> + parse_string(Input@4, <<String/binary, "\r"/utf8>>); + + [<<"\\"/utf8>>, <<"\""/utf8>> | Input@5] -> + parse_string(Input@5, <<String/binary, "\""/utf8>>); + + [<<"\\"/utf8>>, <<"\\"/utf8>> | Input@6] -> + parse_string(Input@6, <<String/binary, "\\"/utf8>>); + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"\""/utf8>>}}; + + [<<"\n"/utf8>> | _] -> + {error, {unexpected, <<"\n"/utf8>>, <<"\""/utf8>>}}; + + [<<"\r\n"/utf8>> | _] -> + {error, {unexpected, <<"\r\n"/utf8>>, <<"\""/utf8>>}}; + + [G | Input@7] -> + parse_string(Input@7, <<String/binary, G/binary>>) + end. + +-spec parse_multi_line_string(list(binary()), binary()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_multi_line_string(Input, String) -> + case Input of + [<<"\""/utf8>>, <<"\""/utf8>>, <<"\""/utf8>> | Input@1] -> + {ok, {{string, String}, Input@1}}; + + [<<"\\"/utf8>>, <<"\n"/utf8>> | Input@2] -> + parse_multi_line_string(skip_whitespace(Input@2), String); + + [<<"\\"/utf8>>, <<"\r\n"/utf8>> | Input@3] -> + parse_multi_line_string(skip_whitespace(Input@3), String); + + [<<"\r\n"/utf8>> | Input@4] when String =:= <<""/utf8>> -> + parse_multi_line_string(Input@4, String); + + [<<"\n"/utf8>> | Input@5] when String =:= <<""/utf8>> -> + parse_multi_line_string(Input@5, String); + + [<<"\r\n"/utf8>> | Input@6] when String =:= <<""/utf8>> -> + parse_multi_line_string(Input@6, String); + + [<<"\\"/utf8>>, <<"t"/utf8>> | Input@7] -> + parse_multi_line_string(Input@7, <<String/binary, "\t"/utf8>>); + + [<<"\\"/utf8>>, <<"n"/utf8>> | Input@8] -> + parse_multi_line_string(Input@8, <<String/binary, "\n"/utf8>>); + + [<<"\\"/utf8>>, <<"r"/utf8>> | Input@9] -> + parse_multi_line_string(Input@9, <<String/binary, "\r"/utf8>>); + + [<<"\\"/utf8>>, <<"\""/utf8>> | Input@10] -> + parse_multi_line_string(Input@10, <<String/binary, "\""/utf8>>); + + [<<"\\"/utf8>>, <<"\\"/utf8>> | Input@11] -> + parse_multi_line_string(Input@11, <<String/binary, "\\"/utf8>>); + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"\""/utf8>>}}; + + [G | Input@12] -> + parse_multi_line_string(Input@12, <<String/binary, G/binary>>) + end. + +-spec parse_multi_line_literal_string(list(binary()), binary()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_multi_line_literal_string(Input, String) -> + case Input of + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"\""/utf8>>}}; + + [<<"'"/utf8>>, <<"'"/utf8>>, <<"'"/utf8>>, <<"'"/utf8>> | _] -> + {error, {unexpected, <<"''''"/utf8>>, <<"'''"/utf8>>}}; + + [<<"'"/utf8>>, <<"'"/utf8>>, <<"'"/utf8>> | Input@1] -> + {ok, {{string, String}, Input@1}}; + + [<<"\n"/utf8>> | Input@2] when String =:= <<""/utf8>> -> + parse_multi_line_literal_string(Input@2, String); + + [<<"\r\n"/utf8>> | Input@3] when String =:= <<""/utf8>> -> + parse_multi_line_literal_string(Input@3, String); + + [G | Input@4] -> + parse_multi_line_literal_string( + Input@4, + <<String/binary, G/binary>> + ) + end. + +-spec parse_literal_string(list(binary()), binary()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_literal_string(Input, String) -> + case Input of + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"\""/utf8>>}}; + + [<<"\n"/utf8>> | _] -> + {error, {unexpected, <<"\n"/utf8>>, <<"'"/utf8>>}}; + + [<<"\r\n"/utf8>> | _] -> + {error, {unexpected, <<"\r\n"/utf8>>, <<"'"/utf8>>}}; + + [<<"'"/utf8>> | Input@1] -> + {ok, {{string, String}, Input@1}}; + + [G | Input@2] -> + parse_literal_string(Input@2, <<String/binary, G/binary>>) + end. + +-spec parse_time_ms(list(binary()), integer(), integer()) -> {ok, + {{integer(), integer()}, list(binary())}} | + {error, parse_error()}. +parse_time_ms(Input, Seconds, Ms) -> + case Input of + [<<"0"/utf8>> | Input@1] when Ms < 100000 -> + parse_time_ms(Input@1, Seconds, (Ms * 10) + 0); + + [<<"1"/utf8>> | Input@2] when Ms < 100000 -> + parse_time_ms(Input@2, Seconds, (Ms * 10) + 1); + + [<<"2"/utf8>> | Input@3] when Ms < 100000 -> + parse_time_ms(Input@3, Seconds, (Ms * 10) + 2); + + [<<"3"/utf8>> | Input@4] when Ms < 100000 -> + parse_time_ms(Input@4, Seconds, (Ms * 10) + 3); + + [<<"4"/utf8>> | Input@5] when Ms < 100000 -> + parse_time_ms(Input@5, Seconds, (Ms * 10) + 4); + + [<<"5"/utf8>> | Input@6] when Ms < 100000 -> + parse_time_ms(Input@6, Seconds, (Ms * 10) + 5); + + [<<"6"/utf8>> | Input@7] when Ms < 100000 -> + parse_time_ms(Input@7, Seconds, (Ms * 10) + 6); + + [<<"7"/utf8>> | Input@8] when Ms < 100000 -> + parse_time_ms(Input@8, Seconds, (Ms * 10) + 7); + + [<<"8"/utf8>> | Input@9] when Ms < 100000 -> + parse_time_ms(Input@9, Seconds, (Ms * 10) + 8); + + [<<"9"/utf8>> | Input@10] when Ms < 100000 -> + parse_time_ms(Input@10, Seconds, (Ms * 10) + 9); + + _ -> + {ok, {{Seconds, Ms}, Input}} + end. + +-spec parse_number_under_60(list(binary()), binary()) -> {ok, + {integer(), list(binary())}} | + {error, parse_error()}. +parse_number_under_60(Input, Expected) -> + case Input of + [<<"0"/utf8>>, <<"0"/utf8>> | Input@1] -> + {ok, {0, Input@1}}; + + [<<"0"/utf8>>, <<"1"/utf8>> | Input@2] -> + {ok, {1, Input@2}}; + + [<<"0"/utf8>>, <<"2"/utf8>> | Input@3] -> + {ok, {2, Input@3}}; + + [<<"0"/utf8>>, <<"3"/utf8>> | Input@4] -> + {ok, {3, Input@4}}; + + [<<"0"/utf8>>, <<"4"/utf8>> | Input@5] -> + {ok, {4, Input@5}}; + + [<<"0"/utf8>>, <<"5"/utf8>> | Input@6] -> + {ok, {5, Input@6}}; + + [<<"0"/utf8>>, <<"6"/utf8>> | Input@7] -> + {ok, {6, Input@7}}; + + [<<"0"/utf8>>, <<"7"/utf8>> | Input@8] -> + {ok, {7, Input@8}}; + + [<<"0"/utf8>>, <<"8"/utf8>> | Input@9] -> + {ok, {8, Input@9}}; + + [<<"0"/utf8>>, <<"9"/utf8>> | Input@10] -> + {ok, {9, Input@10}}; + + [<<"1"/utf8>>, <<"0"/utf8>> | Input@11] -> + {ok, {10, Input@11}}; + + [<<"1"/utf8>>, <<"1"/utf8>> | Input@12] -> + {ok, {11, Input@12}}; + + [<<"1"/utf8>>, <<"2"/utf8>> | Input@13] -> + {ok, {12, Input@13}}; + + [<<"1"/utf8>>, <<"3"/utf8>> | Input@14] -> + {ok, {13, Input@14}}; + + [<<"1"/utf8>>, <<"4"/utf8>> | Input@15] -> + {ok, {14, Input@15}}; + + [<<"1"/utf8>>, <<"5"/utf8>> | Input@16] -> + {ok, {15, Input@16}}; + + [<<"1"/utf8>>, <<"6"/utf8>> | Input@17] -> + {ok, {16, Input@17}}; + + [<<"1"/utf8>>, <<"7"/utf8>> | Input@18] -> + {ok, {17, Input@18}}; + + [<<"1"/utf8>>, <<"8"/utf8>> | Input@19] -> + {ok, {18, Input@19}}; + + [<<"1"/utf8>>, <<"9"/utf8>> | Input@20] -> + {ok, {19, Input@20}}; + + [<<"2"/utf8>>, <<"0"/utf8>> | Input@21] -> + {ok, {20, Input@21}}; + + [<<"2"/utf8>>, <<"1"/utf8>> | Input@22] -> + {ok, {21, Input@22}}; + + [<<"2"/utf8>>, <<"2"/utf8>> | Input@23] -> + {ok, {22, Input@23}}; + + [<<"2"/utf8>>, <<"3"/utf8>> | Input@24] -> + {ok, {23, Input@24}}; + + [<<"2"/utf8>>, <<"4"/utf8>> | Input@25] -> + {ok, {24, Input@25}}; + + [<<"2"/utf8>>, <<"5"/utf8>> | Input@26] -> + {ok, {25, Input@26}}; + + [<<"2"/utf8>>, <<"6"/utf8>> | Input@27] -> + {ok, {26, Input@27}}; + + [<<"2"/utf8>>, <<"7"/utf8>> | Input@28] -> + {ok, {27, Input@28}}; + + [<<"2"/utf8>>, <<"8"/utf8>> | Input@29] -> + {ok, {28, Input@29}}; + + [<<"2"/utf8>>, <<"9"/utf8>> | Input@30] -> + {ok, {29, Input@30}}; + + [<<"3"/utf8>>, <<"0"/utf8>> | Input@31] -> + {ok, {30, Input@31}}; + + [<<"3"/utf8>>, <<"1"/utf8>> | Input@32] -> + {ok, {31, Input@32}}; + + [<<"3"/utf8>>, <<"2"/utf8>> | Input@33] -> + {ok, {32, Input@33}}; + + [<<"3"/utf8>>, <<"3"/utf8>> | Input@34] -> + {ok, {33, Input@34}}; + + [<<"3"/utf8>>, <<"4"/utf8>> | Input@35] -> + {ok, {34, Input@35}}; + + [<<"3"/utf8>>, <<"5"/utf8>> | Input@36] -> + {ok, {35, Input@36}}; + + [<<"3"/utf8>>, <<"6"/utf8>> | Input@37] -> + {ok, {36, Input@37}}; + + [<<"3"/utf8>>, <<"7"/utf8>> | Input@38] -> + {ok, {37, Input@38}}; + + [<<"3"/utf8>>, <<"8"/utf8>> | Input@39] -> + {ok, {38, Input@39}}; + + [<<"3"/utf8>>, <<"9"/utf8>> | Input@40] -> + {ok, {39, Input@40}}; + + [<<"4"/utf8>>, <<"0"/utf8>> | Input@41] -> + {ok, {40, Input@41}}; + + [<<"4"/utf8>>, <<"1"/utf8>> | Input@42] -> + {ok, {41, Input@42}}; + + [<<"4"/utf8>>, <<"2"/utf8>> | Input@43] -> + {ok, {42, Input@43}}; + + [<<"4"/utf8>>, <<"3"/utf8>> | Input@44] -> + {ok, {43, Input@44}}; + + [<<"4"/utf8>>, <<"4"/utf8>> | Input@45] -> + {ok, {44, Input@45}}; + + [<<"4"/utf8>>, <<"5"/utf8>> | Input@46] -> + {ok, {45, Input@46}}; + + [<<"4"/utf8>>, <<"6"/utf8>> | Input@47] -> + {ok, {46, Input@47}}; + + [<<"4"/utf8>>, <<"7"/utf8>> | Input@48] -> + {ok, {47, Input@48}}; + + [<<"4"/utf8>>, <<"8"/utf8>> | Input@49] -> + {ok, {48, Input@49}}; + + [<<"4"/utf8>>, <<"9"/utf8>> | Input@50] -> + {ok, {49, Input@50}}; + + [<<"5"/utf8>>, <<"0"/utf8>> | Input@51] -> + {ok, {50, Input@51}}; + + [<<"5"/utf8>>, <<"1"/utf8>> | Input@52] -> + {ok, {51, Input@52}}; + + [<<"5"/utf8>>, <<"2"/utf8>> | Input@53] -> + {ok, {52, Input@53}}; + + [<<"5"/utf8>>, <<"3"/utf8>> | Input@54] -> + {ok, {53, Input@54}}; + + [<<"5"/utf8>>, <<"4"/utf8>> | Input@55] -> + {ok, {54, Input@55}}; + + [<<"5"/utf8>>, <<"5"/utf8>> | Input@56] -> + {ok, {55, Input@56}}; + + [<<"5"/utf8>>, <<"6"/utf8>> | Input@57] -> + {ok, {56, Input@57}}; + + [<<"5"/utf8>>, <<"7"/utf8>> | Input@58] -> + {ok, {57, Input@58}}; + + [<<"5"/utf8>>, <<"8"/utf8>> | Input@59] -> + {ok, {58, Input@59}}; + + [<<"5"/utf8>>, <<"9"/utf8>> | Input@60] -> + {ok, {59, Input@60}}; + + [G | _] -> + {error, {unexpected, G, Expected}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, Expected}} + end. + +-spec parse_hour_minute(list(binary())) -> {ok, + {{integer(), integer()}, list(binary())}} | + {error, parse_error()}. +parse_hour_minute(Input) -> + do(case Input of + [<<"0"/utf8>>, <<"0"/utf8>>, <<":"/utf8>> | Input@1] -> + {ok, {0, Input@1}}; + + [<<"0"/utf8>>, <<"1"/utf8>>, <<":"/utf8>> | Input@2] -> + {ok, {1, Input@2}}; + + [<<"0"/utf8>>, <<"2"/utf8>>, <<":"/utf8>> | Input@3] -> + {ok, {2, Input@3}}; + + [<<"0"/utf8>>, <<"3"/utf8>>, <<":"/utf8>> | Input@4] -> + {ok, {3, Input@4}}; + + [<<"0"/utf8>>, <<"4"/utf8>>, <<":"/utf8>> | Input@5] -> + {ok, {4, Input@5}}; + + [<<"0"/utf8>>, <<"5"/utf8>>, <<":"/utf8>> | Input@6] -> + {ok, {5, Input@6}}; + + [<<"0"/utf8>>, <<"6"/utf8>>, <<":"/utf8>> | Input@7] -> + {ok, {6, Input@7}}; + + [<<"0"/utf8>>, <<"7"/utf8>>, <<":"/utf8>> | Input@8] -> + {ok, {7, Input@8}}; + + [<<"0"/utf8>>, <<"8"/utf8>>, <<":"/utf8>> | Input@9] -> + {ok, {8, Input@9}}; + + [<<"0"/utf8>>, <<"9"/utf8>>, <<":"/utf8>> | Input@10] -> + {ok, {9, Input@10}}; + + [<<"1"/utf8>>, <<"0"/utf8>>, <<":"/utf8>> | Input@11] -> + {ok, {10, Input@11}}; + + [<<"1"/utf8>>, <<"1"/utf8>>, <<":"/utf8>> | Input@12] -> + {ok, {11, Input@12}}; + + [<<"1"/utf8>>, <<"2"/utf8>>, <<":"/utf8>> | Input@13] -> + {ok, {12, Input@13}}; + + [<<"1"/utf8>>, <<"3"/utf8>>, <<":"/utf8>> | Input@14] -> + {ok, {13, Input@14}}; + + [<<"1"/utf8>>, <<"4"/utf8>>, <<":"/utf8>> | Input@15] -> + {ok, {14, Input@15}}; + + [<<"1"/utf8>>, <<"5"/utf8>>, <<":"/utf8>> | Input@16] -> + {ok, {15, Input@16}}; + + [<<"1"/utf8>>, <<"6"/utf8>>, <<":"/utf8>> | Input@17] -> + {ok, {16, Input@17}}; + + [<<"1"/utf8>>, <<"7"/utf8>>, <<":"/utf8>> | Input@18] -> + {ok, {17, Input@18}}; + + [<<"1"/utf8>>, <<"8"/utf8>>, <<":"/utf8>> | Input@19] -> + {ok, {18, Input@19}}; + + [<<"1"/utf8>>, <<"9"/utf8>>, <<":"/utf8>> | Input@20] -> + {ok, {19, Input@20}}; + + [<<"2"/utf8>>, <<"0"/utf8>>, <<":"/utf8>> | Input@21] -> + {ok, {20, Input@21}}; + + [<<"2"/utf8>>, <<"1"/utf8>>, <<":"/utf8>> | Input@22] -> + {ok, {21, Input@22}}; + + [<<"2"/utf8>>, <<"2"/utf8>>, <<":"/utf8>> | Input@23] -> + {ok, {22, Input@23}}; + + [<<"2"/utf8>>, <<"3"/utf8>>, <<":"/utf8>> | Input@24] -> + {ok, {23, Input@24}}; + + [G | _] -> + {error, {unexpected, G, <<"time"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"time"/utf8>>}} + end, fun(Hours, Input@25) -> + do( + parse_number_under_60(Input@25, <<"minutes"/utf8>>), + fun(Minutes, Input@26) -> {ok, {{Hours, Minutes}, Input@26}} end + ) + end). + +-spec parse_time_s_ms(list(binary())) -> {ok, + {{integer(), integer()}, list(binary())}} | + {error, parse_error()}. +parse_time_s_ms(Input) -> + case Input of + [<<":"/utf8>> | Input@1] -> + do( + parse_number_under_60(Input@1, <<"seconds"/utf8>>), + fun(Seconds, Input@2) -> case Input@2 of + [<<"."/utf8>> | Input@3] -> + parse_time_ms(Input@3, Seconds, 0); + + _ -> + {ok, {{Seconds, 0}, Input@2}} + end end + ); + + _ -> + {ok, {{0, 0}, Input}} + end. + +-spec parse_time_minute(list(binary()), integer()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_time_minute(Input, Hours) -> + do( + parse_number_under_60(Input, <<"minutes"/utf8>>), + fun(Minutes, Input@1) -> + do( + parse_time_s_ms(Input@1), + fun(_use0, Input@2) -> + {Seconds, Ms} = _use0, + Time = {time_value, Hours, Minutes, Seconds, Ms}, + {ok, {{time, Time}, Input@2}} + end + ) + end + ). + +-spec parse_time_value(list(binary())) -> {ok, {time(), list(binary())}} | + {error, parse_error()}. +parse_time_value(Input) -> + do( + parse_hour_minute(Input), + fun(_use0, Input@1) -> + {Hours, Minutes} = _use0, + do( + parse_time_s_ms(Input@1), + fun(_use0@1, Input@2) -> + {Seconds, Ms} = _use0@1, + Time = {time_value, Hours, Minutes, Seconds, Ms}, + {ok, {Time, Input@2}} + end + ) + end + ). + +-spec parse_offset_hours(list(binary()), sign()) -> {ok, + {offset(), list(binary())}} | + {error, parse_error()}. +parse_offset_hours(Input, Sign) -> + do( + parse_hour_minute(Input), + fun(_use0, Input@1) -> + {Hours, Minutes} = _use0, + {ok, {{offset, Sign, Hours, Minutes}, Input@1}} + end + ). + +-spec parse_offset(list(binary())) -> {ok, {offset(), list(binary())}} | + {error, parse_error()}. +parse_offset(Input) -> + case Input of + [<<"Z"/utf8>> | Input@1] -> + {ok, {{offset, positive, 0, 0}, Input@1}}; + + [<<"+"/utf8>> | Input@2] -> + parse_offset_hours(Input@2, positive); + + [<<"-"/utf8>> | Input@3] -> + parse_offset_hours(Input@3, negative); + + _ -> + {ok, {local, Input}} + end. + +-spec parse_date_end(list(binary()), integer(), integer(), integer()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_date_end(Input, Year, Month, Day) -> + Date = {date_value, Year, Month, Day}, + case Input of + [<<" "/utf8>> | Input@1] -> + do( + parse_time_value(Input@1), + fun(Time, Input@2) -> + do( + parse_offset(Input@2), + fun(Offset, Input@3) -> + {ok, + {{date_time, + {date_time_value, Date, Time, Offset}}, + Input@3}} + end + ) + end + ); + + [<<"T"/utf8>> | Input@1] -> + do( + parse_time_value(Input@1), + fun(Time, Input@2) -> + do( + parse_offset(Input@2), + fun(Offset, Input@3) -> + {ok, + {{date_time, + {date_time_value, Date, Time, Offset}}, + Input@3}} + end + ) + end + ); + + _ -> + {ok, {{date, Date}, Input}} + end. + +-spec parse_date_day(list(binary()), integer(), integer()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_date_day(Input, Year, Month) -> + case Input of + [<<"0"/utf8>>, <<"1"/utf8>> | Input@1] -> + parse_date_end(Input@1, Year, Month, 1); + + [<<"0"/utf8>>, <<"2"/utf8>> | Input@2] -> + parse_date_end(Input@2, Year, Month, 2); + + [<<"0"/utf8>>, <<"3"/utf8>> | Input@3] -> + parse_date_end(Input@3, Year, Month, 3); + + [<<"0"/utf8>>, <<"4"/utf8>> | Input@4] -> + parse_date_end(Input@4, Year, Month, 4); + + [<<"0"/utf8>>, <<"5"/utf8>> | Input@5] -> + parse_date_end(Input@5, Year, Month, 5); + + [<<"0"/utf8>>, <<"6"/utf8>> | Input@6] -> + parse_date_end(Input@6, Year, Month, 6); + + [<<"0"/utf8>>, <<"7"/utf8>> | Input@7] -> + parse_date_end(Input@7, Year, Month, 7); + + [<<"0"/utf8>>, <<"8"/utf8>> | Input@8] -> + parse_date_end(Input@8, Year, Month, 8); + + [<<"0"/utf8>>, <<"9"/utf8>> | Input@9] -> + parse_date_end(Input@9, Year, Month, 9); + + [<<"1"/utf8>>, <<"0"/utf8>> | Input@10] -> + parse_date_end(Input@10, Year, Month, 10); + + [<<"1"/utf8>>, <<"1"/utf8>> | Input@11] -> + parse_date_end(Input@11, Year, Month, 11); + + [<<"1"/utf8>>, <<"2"/utf8>> | Input@12] -> + parse_date_end(Input@12, Year, Month, 12); + + [<<"1"/utf8>>, <<"3"/utf8>> | Input@13] -> + parse_date_end(Input@13, Year, Month, 13); + + [<<"1"/utf8>>, <<"4"/utf8>> | Input@14] -> + parse_date_end(Input@14, Year, Month, 14); + + [<<"1"/utf8>>, <<"5"/utf8>> | Input@15] -> + parse_date_end(Input@15, Year, Month, 15); + + [<<"1"/utf8>>, <<"6"/utf8>> | Input@16] -> + parse_date_end(Input@16, Year, Month, 16); + + [<<"1"/utf8>>, <<"7"/utf8>> | Input@17] -> + parse_date_end(Input@17, Year, Month, 17); + + [<<"1"/utf8>>, <<"8"/utf8>> | Input@18] -> + parse_date_end(Input@18, Year, Month, 18); + + [<<"1"/utf8>>, <<"9"/utf8>> | Input@19] -> + parse_date_end(Input@19, Year, Month, 19); + + [<<"2"/utf8>>, <<"0"/utf8>> | Input@20] -> + parse_date_end(Input@20, Year, Month, 20); + + [<<"2"/utf8>>, <<"1"/utf8>> | Input@21] -> + parse_date_end(Input@21, Year, Month, 21); + + [<<"2"/utf8>>, <<"2"/utf8>> | Input@22] -> + parse_date_end(Input@22, Year, Month, 22); + + [<<"2"/utf8>>, <<"3"/utf8>> | Input@23] -> + parse_date_end(Input@23, Year, Month, 23); + + [<<"2"/utf8>>, <<"4"/utf8>> | Input@24] -> + parse_date_end(Input@24, Year, Month, 24); + + [<<"2"/utf8>>, <<"5"/utf8>> | Input@25] -> + parse_date_end(Input@25, Year, Month, 25); + + [<<"2"/utf8>>, <<"6"/utf8>> | Input@26] -> + parse_date_end(Input@26, Year, Month, 26); + + [<<"2"/utf8>>, <<"7"/utf8>> | Input@27] -> + parse_date_end(Input@27, Year, Month, 27); + + [<<"2"/utf8>>, <<"8"/utf8>> | Input@28] -> + parse_date_end(Input@28, Year, Month, 28); + + [<<"2"/utf8>>, <<"9"/utf8>> | Input@29] -> + parse_date_end(Input@29, Year, Month, 29); + + [<<"3"/utf8>>, <<"0"/utf8>> | Input@30] -> + parse_date_end(Input@30, Year, Month, 30); + + [<<"3"/utf8>>, <<"1"/utf8>> | Input@31] -> + parse_date_end(Input@31, Year, Month, 31); + + [G | _] -> + {error, {unexpected, G, <<"date day"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"date day"/utf8>>}} + end. + +-spec parse_date(list(binary()), integer()) -> {ok, {toml(), list(binary())}} | + {error, parse_error()}. +parse_date(Input, Year) -> + case Input of + [<<"0"/utf8>>, <<"1"/utf8>>, <<"-"/utf8>> | Input@1] -> + parse_date_day(Input@1, Year, 1); + + [<<"0"/utf8>>, <<"2"/utf8>>, <<"-"/utf8>> | Input@2] -> + parse_date_day(Input@2, Year, 2); + + [<<"0"/utf8>>, <<"3"/utf8>>, <<"-"/utf8>> | Input@3] -> + parse_date_day(Input@3, Year, 3); + + [<<"0"/utf8>>, <<"4"/utf8>>, <<"-"/utf8>> | Input@4] -> + parse_date_day(Input@4, Year, 4); + + [<<"0"/utf8>>, <<"5"/utf8>>, <<"-"/utf8>> | Input@5] -> + parse_date_day(Input@5, Year, 5); + + [<<"0"/utf8>>, <<"6"/utf8>>, <<"-"/utf8>> | Input@6] -> + parse_date_day(Input@6, Year, 6); + + [<<"0"/utf8>>, <<"7"/utf8>>, <<"-"/utf8>> | Input@7] -> + parse_date_day(Input@7, Year, 7); + + [<<"0"/utf8>>, <<"8"/utf8>>, <<"-"/utf8>> | Input@8] -> + parse_date_day(Input@8, Year, 8); + + [<<"0"/utf8>>, <<"9"/utf8>>, <<"-"/utf8>> | Input@9] -> + parse_date_day(Input@9, Year, 9); + + [<<"1"/utf8>>, <<"0"/utf8>>, <<"-"/utf8>> | Input@10] -> + parse_date_day(Input@10, Year, 10); + + [<<"1"/utf8>>, <<"1"/utf8>>, <<"-"/utf8>> | Input@11] -> + parse_date_day(Input@11, Year, 11); + + [<<"1"/utf8>>, <<"2"/utf8>>, <<"-"/utf8>> | Input@12] -> + parse_date_day(Input@12, Year, 12); + + [G | _] -> + {error, {unexpected, G, <<"date month"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"date month"/utf8>>}} + end. + +-spec parse_number(list(binary()), integer(), sign()) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_number(Input, Number, Sign) -> + case Input of + [<<"_"/utf8>> | Input@1] -> + parse_number(Input@1, Number, Sign); + + [<<"0"/utf8>> | Input@2] -> + parse_number(Input@2, (Number * 10) + 0, Sign); + + [<<"1"/utf8>> | Input@3] -> + parse_number(Input@3, (Number * 10) + 1, Sign); + + [<<"2"/utf8>> | Input@4] -> + parse_number(Input@4, (Number * 10) + 2, Sign); + + [<<"3"/utf8>> | Input@5] -> + parse_number(Input@5, (Number * 10) + 3, Sign); + + [<<"4"/utf8>> | Input@6] -> + parse_number(Input@6, (Number * 10) + 4, Sign); + + [<<"5"/utf8>> | Input@7] -> + parse_number(Input@7, (Number * 10) + 5, Sign); + + [<<"6"/utf8>> | Input@8] -> + parse_number(Input@8, (Number * 10) + 6, Sign); + + [<<"7"/utf8>> | Input@9] -> + parse_number(Input@9, (Number * 10) + 7, Sign); + + [<<"8"/utf8>> | Input@10] -> + parse_number(Input@10, (Number * 10) + 8, Sign); + + [<<"9"/utf8>> | Input@11] -> + parse_number(Input@11, (Number * 10) + 9, Sign); + + [<<"-"/utf8>> | Input@12] -> + parse_date(Input@12, Number); + + [<<":"/utf8>> | Input@13] when Number < 24 -> + parse_time_minute(Input@13, Number); + + [<<"."/utf8>> | Input@14] -> + parse_float(Input@14, gleam@int:to_float(Number), Sign, 0.1); + + [<<"e"/utf8>>, <<"+"/utf8>> | Input@15] -> + parse_exponent( + Input@15, + gleam@int:to_float(Number), + Sign, + 0, + positive + ); + + [<<"e"/utf8>>, <<"-"/utf8>> | Input@16] -> + parse_exponent( + Input@16, + gleam@int:to_float(Number), + Sign, + 0, + negative + ); + + [<<"e"/utf8>> | Input@17] -> + parse_exponent( + Input@17, + gleam@int:to_float(Number), + Sign, + 0, + positive + ); + + [<<"E"/utf8>>, <<"+"/utf8>> | Input@18] -> + parse_exponent( + Input@18, + gleam@int:to_float(Number), + Sign, + 0, + positive + ); + + [<<"E"/utf8>>, <<"-"/utf8>> | Input@19] -> + parse_exponent( + Input@19, + gleam@int:to_float(Number), + Sign, + 0, + negative + ); + + [<<"E"/utf8>> | Input@20] -> + parse_exponent( + Input@20, + gleam@int:to_float(Number), + Sign, + 0, + positive + ); + + Input@21 -> + Number@1 = case Sign of + positive -> + Number; + + negative -> + - Number + end, + {ok, {{int, Number@1}, Input@21}} + end. + +-spec reverse_arrays_of_tables(toml()) -> toml(). +reverse_arrays_of_tables(Toml) -> + case Toml of + {array_of_tables, Tables} -> + {array_of_tables, reverse_arrays_of_tables_array(Tables, [])}; + + {table, Table} -> + {table, reverse_arrays_of_tables_table(Table)}; + + _ -> + Toml + end. + +-spec reverse_arrays_of_tables_table(gleam@dict:dict(binary(), toml())) -> gleam@dict:dict(binary(), toml()). +reverse_arrays_of_tables_table(Table) -> + gleam@map:map_values(Table, fun(_, V) -> reverse_arrays_of_tables(V) end). + +-spec reverse_arrays_of_tables_array( + list(gleam@dict:dict(binary(), toml())), + list(gleam@dict:dict(binary(), toml())) +) -> list(gleam@dict:dict(binary(), toml())). +reverse_arrays_of_tables_array(Array, Acc) -> + case Array of + [] -> + Acc; + + [First | Rest] -> + First@1 = reverse_arrays_of_tables_table(First), + reverse_arrays_of_tables_array(Rest, [First@1 | Acc]) + end. + +-spec parse_inline_table_property( + list(binary()), + gleam@dict:dict(binary(), toml()) +) -> {ok, {gleam@dict:dict(binary(), toml()), list(binary())}} | + {error, parse_error()}. +parse_inline_table_property(Input, Properties) -> + Input@1 = skip_whitespace(Input), + do( + parse_key(Input@1, []), + fun(Key, Input@2) -> + Input@3 = skip_line_whitespace(Input@2), + expect( + Input@3, + <<"="/utf8>>, + fun(Input@4) -> + Input@5 = skip_line_whitespace(Input@4), + do( + parse_value(Input@5), + fun(Value, Input@6) -> + case insert(Properties, Key, Value) of + {ok, Properties@1} -> + {ok, {Properties@1, Input@6}}; + + {error, E} -> + {error, E} + end + end + ) + end + ) + end + ). + +-spec parse_value(list(binary())) -> {ok, {toml(), list(binary())}} | + {error, parse_error()}. +parse_value(Input) -> + case Input of + [<<"t"/utf8>>, <<"r"/utf8>>, <<"u"/utf8>>, <<"e"/utf8>> | Input@1] -> + {ok, {{bool, true}, Input@1}}; + + [<<"f"/utf8>>, + <<"a"/utf8>>, + <<"l"/utf8>>, + <<"s"/utf8>>, + <<"e"/utf8>> | + Input@2] -> + {ok, {{bool, false}, Input@2}}; + + [<<"n"/utf8>>, <<"a"/utf8>>, <<"n"/utf8>> | Input@3] -> + {ok, {{nan, positive}, Input@3}}; + + [<<"+"/utf8>>, <<"n"/utf8>>, <<"a"/utf8>>, <<"n"/utf8>> | Input@4] -> + {ok, {{nan, positive}, Input@4}}; + + [<<"-"/utf8>>, <<"n"/utf8>>, <<"a"/utf8>>, <<"n"/utf8>> | Input@5] -> + {ok, {{nan, negative}, Input@5}}; + + [<<"i"/utf8>>, <<"n"/utf8>>, <<"f"/utf8>> | Input@6] -> + {ok, {{infinity, positive}, Input@6}}; + + [<<"+"/utf8>>, <<"i"/utf8>>, <<"n"/utf8>>, <<"f"/utf8>> | Input@7] -> + {ok, {{infinity, positive}, Input@7}}; + + [<<"-"/utf8>>, <<"i"/utf8>>, <<"n"/utf8>>, <<"f"/utf8>> | Input@8] -> + {ok, {{infinity, negative}, Input@8}}; + + [<<"["/utf8>> | Input@9] -> + parse_array(Input@9, []); + + [<<"{"/utf8>> | Input@10] -> + parse_inline_table(Input@10, gleam@map:new()); + + [<<"0"/utf8>>, <<"x"/utf8>> | Input@11] -> + parse_hex(Input@11, 0, positive); + + [<<"+"/utf8>>, <<"0"/utf8>>, <<"x"/utf8>> | Input@12] -> + parse_hex(Input@12, 0, positive); + + [<<"-"/utf8>>, <<"0"/utf8>>, <<"x"/utf8>> | Input@13] -> + parse_hex(Input@13, 0, negative); + + [<<"0"/utf8>>, <<"o"/utf8>> | Input@14] -> + parse_octal(Input@14, 0, positive); + + [<<"+"/utf8>>, <<"0"/utf8>>, <<"o"/utf8>> | Input@15] -> + parse_octal(Input@15, 0, positive); + + [<<"-"/utf8>>, <<"0"/utf8>>, <<"o"/utf8>> | Input@16] -> + parse_octal(Input@16, 0, negative); + + [<<"0"/utf8>>, <<"b"/utf8>> | Input@17] -> + parse_binary(Input@17, 0, positive); + + [<<"+"/utf8>>, <<"0"/utf8>>, <<"b"/utf8>> | Input@18] -> + parse_binary(Input@18, 0, positive); + + [<<"-"/utf8>>, <<"0"/utf8>>, <<"b"/utf8>> | Input@19] -> + parse_binary(Input@19, 0, negative); + + [<<"+"/utf8>> | Input@20] -> + parse_number(Input@20, 0, positive); + + [<<"-"/utf8>> | Input@21] -> + parse_number(Input@21, 0, negative); + + [<<"0"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"1"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"2"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"3"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"4"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"5"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"6"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"7"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"8"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"9"/utf8>> | _] -> + parse_number(Input, 0, positive); + + [<<"\""/utf8>>, <<"\""/utf8>>, <<"\""/utf8>> | Input@22] -> + parse_multi_line_string(Input@22, <<""/utf8>>); + + [<<"\""/utf8>> | Input@23] -> + parse_string(Input@23, <<""/utf8>>); + + [<<"'"/utf8>>, <<"'"/utf8>>, <<"'"/utf8>> | Input@24] -> + parse_multi_line_literal_string(Input@24, <<""/utf8>>); + + [<<"'"/utf8>> | Input@25] -> + parse_literal_string(Input@25, <<""/utf8>>); + + [G | _] -> + {error, {unexpected, G, <<"value"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"value"/utf8>>}} + end. + +-spec parse_inline_table(list(binary()), gleam@dict:dict(binary(), toml())) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_inline_table(Input, Properties) -> + Input@1 = skip_whitespace(Input), + case Input@1 of + [<<"}"/utf8>> | Input@2] -> + {ok, {{inline_table, Properties}, Input@2}}; + + _ -> + case parse_inline_table_property(Input@1, Properties) of + {ok, {Properties@1, Input@3}} -> + Input@4 = skip_whitespace(Input@3), + case Input@4 of + [<<"}"/utf8>> | Input@5] -> + {ok, {{inline_table, Properties@1}, Input@5}}; + + [<<","/utf8>> | Input@6] -> + Input@7 = skip_whitespace(Input@6), + parse_inline_table(Input@7, Properties@1); + + [G | _] -> + {error, {unexpected, G, <<"}"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"}"/utf8>>}} + end; + + {error, E} -> + {error, E} + end + end. + +-spec parse_key_value(list(binary()), gleam@dict:dict(binary(), toml())) -> {ok, + {gleam@dict:dict(binary(), toml()), list(binary())}} | + {error, parse_error()}. +parse_key_value(Input, Toml) -> + do( + parse_key(Input, []), + fun(Key, Input@1) -> + Input@2 = skip_line_whitespace(Input@1), + expect( + Input@2, + <<"="/utf8>>, + fun(Input@3) -> + Input@4 = skip_line_whitespace(Input@3), + do( + parse_value(Input@4), + fun(Value, Input@5) -> case insert(Toml, Key, Value) of + {ok, Toml@1} -> + {ok, {Toml@1, Input@5}}; + + {error, E} -> + {error, E} + end end + ) + end + ) + end + ). + +-spec parse_table(list(binary()), gleam@dict:dict(binary(), toml())) -> {ok, + {gleam@dict:dict(binary(), toml()), list(binary())}} | + {error, parse_error()}. +parse_table(Input, Toml) -> + Input@1 = skip_whitespace(Input), + case Input@1 of + [<<"["/utf8>> | _] -> + {ok, {Toml, Input@1}}; + + [] -> + {ok, {Toml, Input@1}}; + + _ -> + case parse_key_value(Input@1, Toml) of + {ok, {Toml@1, Input@2}} -> + case skip_line_whitespace(Input@2) of + [] -> + {ok, {Toml@1, []}}; + + [<<"\n"/utf8>> | In] -> + parse_table(In, Toml@1); + + [<<"\r\n"/utf8>> | In] -> + parse_table(In, Toml@1); + + [G | _] -> + {error, {unexpected, G, <<"\n"/utf8>>}} + end; + + E -> + E + end + end. + +-spec parse_array_of_tables(list(binary())) -> {ok, + {{list(binary()), gleam@dict:dict(binary(), toml())}, list(binary())}} | + {error, parse_error()}. +parse_array_of_tables(Input) -> + Input@1 = skip_line_whitespace(Input), + do( + parse_key(Input@1, []), + fun(Key, Input@2) -> + expect( + Input@2, + <<"]"/utf8>>, + fun(Input@3) -> + expect( + Input@3, + <<"]"/utf8>>, + fun(Input@4) -> + do( + parse_table(Input@4, gleam@map:new()), + fun(Table, Input@5) -> + {ok, {{Key, Table}, Input@5}} + end + ) + end + ) + end + ) + end + ). + +-spec parse_table_and_header(list(binary())) -> {ok, + {{list(binary()), gleam@dict:dict(binary(), toml())}, list(binary())}} | + {error, parse_error()}. +parse_table_and_header(Input) -> + do( + parse_table_header(Input), + fun(Key, Input@1) -> + do( + parse_table(Input@1, gleam@map:new()), + fun(Table, Input@2) -> {ok, {{Key, Table}, Input@2}} end + ) + end + ). + +-spec parse_tables(list(binary()), gleam@dict:dict(binary(), toml())) -> {ok, + gleam@dict:dict(binary(), toml())} | + {error, parse_error()}. +parse_tables(Input, Toml) -> + case Input of + [<<"["/utf8>>, <<"["/utf8>> | Input@1] -> + case parse_array_of_tables(Input@1) of + {error, E} -> + {error, E}; + + {ok, {{Key, Table}, Input@2}} -> + case insert(Toml, Key, {array_of_tables, [Table]}) of + {ok, Toml@1} -> + parse_tables(Input@2, Toml@1); + + {error, E@1} -> + {error, E@1} + end + end; + + [<<"["/utf8>> | Input@3] -> + case parse_table_and_header(Input@3) of + {error, E@2} -> + {error, E@2}; + + {ok, {{Key@1, Table@1}, Input@4}} -> + case insert(Toml, Key@1, {table, Table@1}) of + {ok, Toml@2} -> + parse_tables(Input@4, Toml@2); + + {error, E@3} -> + {error, E@3} + end + end; + + [G | _] -> + {error, {unexpected, G, <<"["/utf8>>}}; + + [] -> + {ok, Toml} + end. + +-spec parse(binary()) -> {ok, gleam@dict:dict(binary(), toml())} | + {error, parse_error()}. +parse(Input) -> + Input@1 = gleam@string:to_graphemes(Input), + Input@2 = drop_comments(Input@1, []), + Input@3 = skip_whitespace(Input@2), + do( + parse_table(Input@3, gleam@map:new()), + fun(Toml, Input@4) -> case parse_tables(Input@4, Toml) of + {ok, Toml@1} -> + {ok, reverse_arrays_of_tables_table(Toml@1)}; + + {error, E} -> + {error, E} + end end + ). + +-spec parse_array(list(binary()), list(toml())) -> {ok, + {toml(), list(binary())}} | + {error, parse_error()}. +parse_array(Input, Elements) -> + Input@1 = skip_whitespace(Input), + case Input@1 of + [<<"]"/utf8>> | Input@2] -> + {ok, {{array, gleam@list:reverse(Elements)}, Input@2}}; + + _ -> + do( + parse_value(Input@1), + fun(Element, Input@3) -> + Elements@1 = [Element | Elements], + Input@4 = skip_whitespace(Input@3), + case Input@4 of + [<<"]"/utf8>> | Input@5] -> + {ok, + {{array, gleam@list:reverse(Elements@1)}, + Input@5}}; + + [<<","/utf8>> | Input@6] -> + Input@7 = skip_whitespace(Input@6), + parse_array(Input@7, Elements@1); + + [G | _] -> + {error, {unexpected, G, <<"]"/utf8>>}}; + + [] -> + {error, {unexpected, <<"EOF"/utf8>>, <<"]"/utf8>>}} + end + end + ) + end. diff --git a/aoc2023/build/dev/erlang/tom/ebin/tom.app b/aoc2023/build/dev/erlang/tom/ebin/tom.app new file mode 100644 index 0000000..ade9be1 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/ebin/tom.app @@ -0,0 +1,7 @@ +{application, tom, [ + {vsn, "0.2.1"}, + {applications, [gleam_stdlib]}, + {description, "A pure Gleam TOML parser!"}, + {modules, []}, + {registered, []} +]}. diff --git a/aoc2023/build/dev/erlang/tom/ebin/tom.beam b/aoc2023/build/dev/erlang/tom/ebin/tom.beam Binary files differnew file mode 100644 index 0000000..f6a990a --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/ebin/tom.beam diff --git a/aoc2023/build/dev/erlang/tom/include/tom_DateTimeValue.hrl b/aoc2023/build/dev/erlang/tom/include/tom_DateTimeValue.hrl new file mode 100644 index 0000000..3b1e660 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_DateTimeValue.hrl @@ -0,0 +1,5 @@ +-record(date_time_value, { + date :: tom:date(), + time :: tom:time(), + offset :: tom:offset() +}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_DateValue.hrl b/aoc2023/build/dev/erlang/tom/include/tom_DateValue.hrl new file mode 100644 index 0000000..c41f901 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_DateValue.hrl @@ -0,0 +1 @@ +-record(date_value, {year :: integer(), month :: integer(), day :: integer()}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_KeyAlreadyInUse.hrl b/aoc2023/build/dev/erlang/tom/include/tom_KeyAlreadyInUse.hrl new file mode 100644 index 0000000..930df26 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_KeyAlreadyInUse.hrl @@ -0,0 +1 @@ +-record(key_already_in_use, {key :: list(binary())}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_NotFound.hrl b/aoc2023/build/dev/erlang/tom/include/tom_NotFound.hrl new file mode 100644 index 0000000..19c9a17 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_NotFound.hrl @@ -0,0 +1 @@ +-record(not_found, {key :: list(binary())}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_Offset.hrl b/aoc2023/build/dev/erlang/tom/include/tom_Offset.hrl new file mode 100644 index 0000000..a58a8e1 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_Offset.hrl @@ -0,0 +1,5 @@ +-record(offset, { + direction :: tom:sign(), + hours :: integer(), + minutes :: integer() +}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_TimeValue.hrl b/aoc2023/build/dev/erlang/tom/include/tom_TimeValue.hrl new file mode 100644 index 0000000..e1275de --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_TimeValue.hrl @@ -0,0 +1,6 @@ +-record(time_value, { + hour :: integer(), + minute :: integer(), + second :: integer(), + millisecond :: integer() +}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_Unexpected.hrl b/aoc2023/build/dev/erlang/tom/include/tom_Unexpected.hrl new file mode 100644 index 0000000..ab1091c --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_Unexpected.hrl @@ -0,0 +1 @@ +-record(unexpected, {got :: binary(), expected :: binary()}). diff --git a/aoc2023/build/dev/erlang/tom/include/tom_WrongType.hrl b/aoc2023/build/dev/erlang/tom/include/tom_WrongType.hrl new file mode 100644 index 0000000..ae57352 --- /dev/null +++ b/aoc2023/build/dev/erlang/tom/include/tom_WrongType.hrl @@ -0,0 +1,5 @@ +-record(wrong_type, { + key :: list(binary()), + expected :: binary(), + got :: binary() +}). |