Belodon (belodon v0.3.0)
View SourceBelodon is a utility module designed to process inputs and dynamically execute problem-solving functions based on provided modules.
It supports two flows:
- Direct Input Flow: Takes a raw input string along with a part indicator (
:part1or:part2), processes the input, and then invokes the correspondingexecute/1function in the submodule. - Auto Input Flow: Extracts numerical identifiers (typically representing a year and day)
from the module's name, fetches input data via
Belodon.Input.get/3, and execute the solution.
Usage
To use this module, create your own module using mix belodon.create. Code will be generated in the
test folder using the module
Summary
Functions
Hello world.
Automatically retrieves the input based on the module's name and executes the solution.
Processes a raw input string and executes the corresponding solution function.
Functions
@spec hello() :: :world
Hello world.
Examples
iex> Belodon.hello()
:world
Automatically retrieves the input based on the module's name and executes the solution.
This function is tailored for scenarios where your module's name includes numerical identifiers (typically a year and a day). It performs the following steps:
- Extract Identifiers: Uses a regular expression to find numbers in the module name.
- Clean Up: Trims any leading zeros from the extracted year and day.
- Fetch Input: Retrieves the problem input using
Belodon.Input.get/3, passing the day. - Execution: Processes the input similar to the direct flow and calls the appropriate solution.
Parameters
module: The module containing the solution submodules (Part1andPart2) with embedded year and day.part: An atom, either:part1or:part2, to select which solution to run.opts: A keyword list, where each value is passed to the main function and to the file reader.
Processes a raw input string and executes the corresponding solution function.
The process involves:
- Preparation: The input is split into a list of lines and the last (potentially empty) line is removed.
- Execution: Based on the
partparameter, it dynamically quotes and evaluates code to call theexecute/1function from the given module's respective nested module (Part1orPart2).
Parameters
module: The module that contains nested submodules (Part1andPart2) with anexecute/1function.input: A multi-line string with the problem input.part: An atom: either:part1or:part2, which selects the corresponding solution.opts: A keyword list, where each value is passed to the main function.