Belodon (belodon v0.2.0)

View Source

Belodon 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 (:part1 or :part2), processes the input, and then invokes the corresponding execute/1 function 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

hello()

@spec hello() :: :world

Hello world.

Examples

iex> Belodon.hello()
:world

solve(module, part, opts \\ [])

@spec solve(module(), :part1 | :part2, keyword()) :: any()

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:

  1. Extract Identifiers: Uses a regular expression to find numbers in the module name.
  2. Clean Up: Trims any leading zeros from the extracted year and day.
  3. Fetch Input: Retrieves the problem input using Belodon.Input.get/3, passing the day.
  4. Execution: Processes the input similar to the direct flow and calls the appropriate solution.

Parameters

  • module: The module containing the solution submodules (Part1 and Part2) with embedded year and day.
  • part: An atom, either :part1 or :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.

test(module, input, part, opts \\ [])

@spec test(module(), binary(), :part1 | :part2, keyword()) :: any()

Processes a raw input string and executes the corresponding solution function.

The process involves:

  1. Preparation: The input is split into a list of lines and the last (potentially empty) line is removed.
  2. Execution: Based on the part parameter, it dynamically quotes and evaluates code to call the execute/1 function from the given module's respective nested module (Part1 or Part2).

Parameters

  • module: The module that contains nested submodules (Part1 and Part2) with an execute/1 function.
  • input: A multi-line string with the problem input.
  • part: An atom: either :part1 or :part2, which selects the corresponding solution.
  • opts: A keyword list, where each value is passed to the main function.