USAMTS Checker App
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
871 B

12 months ago
  1. from flask import Flask, render_template, request
  2. import solver
  3. app = Flask(__name__)
  4. @app.route("/", methods=["GET", "POST"])
  5. def index():
  6. if request.method == "GET":
  7. return render_template("page.html")
  8. else:
  9. try:
  10. M = int(request.form["M"])
  11. N = int(request.form["N"])
  12. except ValueError:
  13. return render_template("page.html", invalid=True)
  14. if not (1 <= M <= 40 and 1 <= N <= 40):
  15. return render_template("page.html", invalid=True)
  16. g = solver.construct(M, N)
  17. if g is None:
  18. return render_template("page.html", nosol=True, M=M, N=N)
  19. else:
  20. image, works = g.plot()
  21. return render_template("page.html", image=image, works=works, M=M, N=N)
  22. if __name__ == "__main__":
  23. app.run(
  24. host="0.0.0.0",
  25. port=8000
  26. )