Skip to content

Commit

Permalink
cli: Add "problem generate-input" and "problem trivial-solve" commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jackrosenthal committed Feb 16, 2024
1 parent fcea1ea commit b9a7eaa
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions algobowl/cli/problem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import concurrent.futures
import io
import random
import sys
from pathlib import Path

Expand Down Expand Up @@ -101,3 +102,24 @@ def _verify_output(output_file):
click.echo(message)

sys.exit(rv)


@problem.command(help="Generate an input")
@click.option("--seed", type=int, help="Seed to use. Default: use SystemRandom.")
@click.pass_obj
def generate_input(cli, seed):
if seed:
rng = random.Random(seed)
else:
rng = random.SystemRandom()
iput = cli.problem.get_module().Input.generate(rng)
iput.write(sys.stdout)


@problem.command(help="Trivially solve an input")
@click.argument("input_file", type=Path)
@click.pass_obj
def trivial_solve(cli, input_file):
iput = _parse_input(cli, input_file)
output = iput.trivial_solve()
output.write(sys.stdout)

0 comments on commit b9a7eaa

Please sign in to comment.