#! /usr/bin/python3 import argparse import json import os import random import shutil import sys random.seed(os.getenv("SEED", "")) words = ["apple", "pear", "peach", "tangerine", "orange", "potato", "carrot", "pea"] answer = ' '.join(random.sample(words, 4)) def puzzle(): number = random.randint(20, 500) obj = { "Pre": { "Authors": ["neale"], "Body": ( "

Dynamic puzzles are provided with a JSON-generating mkpuzzles program in the puzzle directory.

" "

You can write mkpuzzles in any language you like. This puzzle was written in Python 3.

" "

Here is some salad:

" ), "Attachments": ["salad.jpg"], }, "Answers": [ answer, ], "Debug": { "Summary": "Dynamic puzzles", "Hints": [ "Check the debug output to get the answer." , ], "Errors": [], "Log": [ "%d is a positive integer" % number, ], } } json.dump(obj, sys.stdout) def open_file(filename): f = open(filename, "rb") shutil.copyfileobj(f, sys.stdout.buffer) def check_answer(check): if answer == check: print("correct") else: print("incorrect") if len(sys.argv) == 1: puzzle() elif sys.argv[1] == "file": open_file(sys.argv[2]) elif sys.argv[1] == "answer": check_answer(sys.argv[2]) else: raise RuntimeError("Unknown command: %s" % sys.argv[1])