challenges package

Submodules

challenges.challenge module

Core module of challenges

This module holds the base class of all challenges.

class challenges.challenge.Challenge[source]

Base class of all challenges

Idea of this class is the Template Method Design Pattern (GOF).

The main() method controls the overall workflow by calling the worker methods read(), build(), calc() and format() in that order. Typically the main() method is not changed.

The workers need to be extended or implemented by the inheriting challenge implementations.

  • read(): This method is typically not changed.
  • build(): Abstract method that needs implementation.
  • calc(): Abstract method. The implementation holds or calls the algorithm

of the challenge. * format(): Needs implementation for advanced challenges.

The other functions are library methods to support the implementation of the workers. Most of them support extraction of data from the input lines or formatting the output.

br = '\n'

Line breaks as expected by the most graders.

build()[source]

Set up the model from the input lines.

This method must be implemented. Reads from self.lines. Fills self.model.

calc()[source]

Main algorithm of the challenge.

This method must be implemented. Here the interesting stuff happens. Best practice is to delegate to functions, that are named by the algorithms used or even to other classes that implement the algorithm.

Reads from self.model. Fills self.result.

edge_pattern = '^(\\d+)->(\\d+)(:(\\d+))?$'

Regex to exctract graph edges.

A default setting used by methods that extract edges from input lines. May need adjustment for differnt kind of edge input formats.

format()[source]

Foramt the output string.

In simple cases this method can be used as is. In other cases it needs to be reimplemented.

Reads from self.result. Fills self.output.

static format_list_of_integers(integers, joint=', ')[source]
format_path(integers, backwards=False)[source]
line(number)[source]
line_break = '\n'

Line breaks as expected by the most graders.

line_to_edge(nr)[source]
line_to_floats(line_nr)[source]
line_to_integers(line_nr)[source]
lines()[source]

A list of lines that will be filled by the method read().

main()[source]

Control the workflow of the challenge.

This method usually doesn’t need a different implementation. This workflow is the common character of all challenges.

The methods share data via instance variables. The overall input is injected into self.sample. The overall output is read from self.result.

model = None

The imported data model.

A flexible namespace object to take up any kind of data. In simple cases this may be completely overwritten, i.e by a list or dict.

output = None

The output string.

The string representation of the resulting model as expected by the grader.

read()[source]

Extract the input string self.sample into self.lines.

Typically this method can be used as is.

read_edges(first=0, last=None)[source]
result = None

The resulting data model.

A flexible namespace object to take up any kind of data. In simple cases this may be completely overwritten, i.e by a list or dict.

sample = 'sample'

Holds a minimal example of the input.

This variable should always be overwritten in the derived class by a smallest example of the challenges input. It is expected by the challenge runner (–klass option) as well as by unit tests to be present.

split_pattern = '\\s+|\\s?,\\s?'

Regex pattern to split input lines.

Used by some of the input parsing functions. By default it splits by whitespace and/or comma. If the input is separated differently like colons or semicolons it needs adjustment in the inheriting class.

challenges.conf module

class challenges.conf.Conf[source]
get_challenge()[source]
get_challenge_class()[source]
get_challenge_dir()[source]
get_challenge_file()[source]
get_challenges()[source]
static get_class(class_)[source]
get_full_qualified_challenge_class()[source]
get_full_qualified_unittest_class()[source]
get_input_file()[source]
get_latest_at_root()[source]
get_latest_file()[source]
get_result_file()[source]
get_sample_file()[source]
get_unittest()[source]
get_unittest_file()[source]
parse_arguments()[source]
print_help()[source]

challenges.main module

challenges.main.main()[source]

challenges.runner module

class challenges.runner.Runner(conf)[source]
list_challenges()[source]
main()[source]
read_file()[source]
run_challenge()[source]
run_unittest()[source]
set_sample(challenge)[source]
write(challenge)[source]

challenges.scaffold module

class challenges.scaffold.Scaffold(conf)[source]
get_class_content()[source]
get_unittest_content()[source]
scaffold()[source]

Module contents