-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
65 lines (61 loc) · 1.82 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
# Name: Latin Square Gen
# Author: Max Base
# Date: 2022/10/20
# Repository: https://github.com/basemax/LatinSquareGen
#
import sys
import time
from LatinSquareGen import count_latin
from LatinSquareGen import list_latin
def help():
print("LatinSquareGen - v1.0.0")
print("")
print("Commands:")
print("-h, --help\t Show help")
print("-v, --version\t Show version")
print("-c, --create-latin\t Create an ordinary latin square")
print("-rl, --create-random-latin\t Create a random latin square")
print("-cl, --count-latin\t Count all latin squares in an order")
print("")
# handle -h and --help
# handle -v and --version
# handle -c and --create-latin <n>
# handle -rl and --create-random-latin <n>
# handle -cl and --count-latin <n>
if len(sys.argv) == 1:
help()
sys.exit(1)
elif sys.argv[1] == "-h" or sys.argv[1] == "--help":
help()
elif sys.argv[1] == "-v" or sys.argv[1] == "--version":
print("LatinSquareGen - v1.0.0")
elif sys.argv[1] == "-c" or sys.argv[1] == "--create-latin":
if len(sys.argv) == 3:
order = int(sys.argv[2])
items = list_latin(order)
for item in items:
print(item)
else:
print("Invalid arguments")
help()
elif sys.argv[1] == "-rl" or sys.argv[1] == "--create-random-latin":
if len(sys.argv) == 3:
order = int(sys.argv[2])
items = list_latin(order)
for item in items:
print(item)
else:
print("Invalid arguments")
help()
elif sys.argv[1] == "-cl" or sys.argv[1] == "--count-latin":
if len(sys.argv) == 3:
order = int(sys.argv[2])
print(count_latin(order))
else:
print("Invalid arguments")
help()
else:
print("Unknown command")
help()
sys.exit(1)