-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (61 loc) · 2.85 KB
/
main.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
66
67
68
69
70
71
72
73
import sys
import argparse
import logging
import time
from fileParser.fileReader import fileToArray
from Coins.minCoinCalculator import minCoinCalculator
# getParameters - Use of argparse for get the parameters of the command line.
# We define -time for time mode (shows how much time it cost ), -tabulation for
# tabulation mode (do memoization and tabulation at the same time) and an integer
# for the parameter value.
def getParameters():
parser = argparse.ArgumentParser()
parser.add_argument("-time","--time", help="Use -t for enable time mode: calculate the time",
action="store_true")
parser.add_argument("-tabulation","--tabulation", help="Print tabulation implementation result",
action="store_true")
parser.add_argument('integers', metavar='N', type=int, nargs='+',
help='an integer')
parser.add_argument("File", help="File to open",type=str)
args = parser.parse_args()
global tabul
tabul = 0
global timer
timer = 0
global fileArray
fileArray = ""
if not args.integers:
logging.exception("Value is required")
sys.exit(2)
if args.File:
fileArray = args.File
print(fileArray)
if args.tabulation:
tabul = 1
if args.time:
timer = 1
return args.integers[0]
if __name__ == '__main__':
value = getParameters()
Coins = fileToArray(fileArray)
if tabul == 1:
if timer == 1:
start = round(time.time() * 1000)
result = minCoinCalculator(Coins).minCoinsMemoization(value)
print("MEMOIZATION: Number of coins needed is: " + str(result) + " TIME: "+ str(round(round(time.time() * 1000) - start)) + "ms")
start = round(time.time() * 1000)
result = minCoinCalculator(Coins).minCoinsMemoization(value)
print("TABULATION: Number of coins needed is: " + str(result) + " TIME: "+ str(round(round(time.time() * 1000) - start)) + "ms")
else:
result = minCoinCalculator(Coins).minCoinsMemoization(value)
print("MEMOIZATION: Number of coins needed is: " + str(result))
result = minCoinCalculator(Coins).minCoinsTabulation(value)
print("TABULATION: Number of coins needed is: " + str(result))
else:
if timer == 1:
start = round(time.time() * 1000)
result = minCoinCalculator(Coins).minCoinsMemoization(value)
print("Number of coins needed is: " + str(result) + " TIME: "+ str(round(round(time.time() * 1000) - start)) + "ms")
else:
result = minCoinCalculator(Coins).minCoinsMemoization(value)
print("Number of coins needed is: " + str(result))