2020-09-11 17:33:43 -06:00
|
|
|
#! /usr/bin/python3
|
2020-09-11 13:03:19 -06:00
|
|
|
|
2020-09-11 17:33:43 -06:00
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import shutil
|
|
|
|
import sys
|
2020-09-11 13:03:19 -06:00
|
|
|
|
2020-09-11 17:33:43 -06:00
|
|
|
parser = argparse.ArgumentParser("Generate a puzzle")
|
|
|
|
parser.add_argument("--file", dest="file", help="File to provide, instead of puzzle")
|
|
|
|
parser.add_argument("--answer", dest="answer", help="Answer to check, instead of providing puzzle")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
seed = hash(os.getenv("SEED"))
|
|
|
|
random.seed(seed)
|
|
|
|
|
|
|
|
words = ["apple", "pear", "peach", "tangerine", "orange", "potato", "carrot", "pea"]
|
|
|
|
answer = ' '.join(random.sample(words, 4))
|
|
|
|
|
|
|
|
if args.file:
|
|
|
|
f = open(args.file, "rb")
|
|
|
|
shutil.copyfileobj(f, sys.stdout.buffer)
|
|
|
|
elif args.answer:
|
|
|
|
if args.answer == answer:
|
|
|
|
print("correct")
|
|
|
|
else:
|
|
|
|
print("incorrect")
|
|
|
|
else:
|
|
|
|
number = random.randint(20, 500)
|
|
|
|
obj = {
|
|
|
|
"Pre": {
|
|
|
|
"Authors": ["neale"],
|
|
|
|
"Body": (
|
|
|
|
"<p>Dynamic puzzles are provided with a JSON-generating <code>mkpuzzles</code> program in the puzzle directory.</p>"
|
|
|
|
"<p>You can write <code>mkpuzzles</code> in any language you like. This puzzle was written in Python 3.</p>"
|
|
|
|
"<p>Here is some salad:<img src='salad.jpg'></p>"
|
|
|
|
),
|
|
|
|
"Attachments": ["salad.jpg"],
|
|
|
|
},
|
|
|
|
"Answers": [
|
|
|
|
answer,
|
2020-09-11 13:03:19 -06:00
|
|
|
],
|
2020-09-11 17:33:43 -06:00
|
|
|
"Debug": {
|
|
|
|
"Summary": "Dynamic puzzles",
|
|
|
|
"Hints": [
|
|
|
|
"Check the debug output to get the answer." ,
|
|
|
|
],
|
|
|
|
"Errors": [],
|
|
|
|
"Log": [
|
|
|
|
"%d is a positive integer" % number,
|
|
|
|
],
|
|
|
|
}
|
2020-09-11 13:03:19 -06:00
|
|
|
}
|
2020-09-11 17:33:43 -06:00
|
|
|
json.dump(obj, sys.stdout)
|