eulertest.py 4.34 KB
Newer Older
Nayuki Minase's avatar
Nayuki Minase committed
1 2
# 
# Test suite for Project Euler all Python solutions
3
# Copyright (c) Project Nayuki. All rights reserved.
Nayuki Minase's avatar
Nayuki Minase committed
4
# 
5
# https://www.nayuki.io/page/project-euler-solutions
Nayuki Minase's avatar
Nayuki Minase committed
6 7 8
# https://github.com/nayuki/Project-Euler-solutions
# 

9 10 11 12
import importlib, time


def main():
13
	totaltime = 0.0  # In seconds
14 15 16
	for (prob, expectans) in sorted(ANSWERS.items()):
		module = importlib.import_module("p{:03d}".format(prob))
		starttime = time.time()
17
		actualans = module.compute()  # Must return a string
18
		elapsedtime = time.time() - starttime
19
		totaltime += elapsedtime
20 21 22
		print("Problem {:03d}: {:7d} ms{}".format(
			prob, int(round(elapsedtime * 1000)),
			"" if actualans == expectans else "    *** FAIL ***"))
23
	print("Total computation time: {} ms".format(int(round(totaltime * 1000))))
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


ANSWERS = {
	  1: "233168",
	  2: "4613732",
	  3: "6857",
	  4: "906609",
	  5: "232792560",
	  6: "25164150",
	  7: "104743",
	  8: "23514624000",
	  9: "31875000",
	 10: "142913828922",
	 11: "70600674",
	 12: "76576500",
	 13: "5537376230",
	 14: "837799",
	 15: "137846528820",
	 16: "1366",
	 17: "21124",
	 18: "1074",
	 19: "171",
	 20: "648",
	 21: "31626",
	 22: "871198282",
	 23: "4179871",
	 24: "2783915460",
	 25: "4782",
	 26: "983",
	 27: "-59231",
	 28: "669171001",
	 29: "9183",
	 30: "443839",
	 31: "73682",
	 32: "45228",
	 33: "100",
	 34: "40730",
	 35: "55",
	 36: "872187",
	 37: "748317",
	 38: "932718654",
	 39: "840",
	 40: "210",
67 68 69
	 41: "7652413",
	 42: "162",
	 43: "16695334890",
70
	 44: "5482660",
71 72 73 74
	 45: "1533776805",
	 46: "5777",
	 47: "134043",
	 48: "9110846700",
75
	 49: "296962999629",
76
	 50: "997651",
77
	 51: "121313",
78 79
	 52: "142857",
	 53: "4075",
80
	 54: "376",
81 82 83
	 55: "249",
	 56: "972",
	 57: "153",
84
	 58: "26241",
85
	 59: "107359",
86
	 60: "26033",
87
	 61: "28684",
88
	 62: "127035954683",
89
	 63: "49",
90
	 64: "1322",
91
	 65: "272",
92
	 66: "661",
93
	 67: "7273",
94
	 68: "6531031914842725",
95 96 97 98
	 69: "510510",
	 70: "8319823",
	 71: "428570",
	 72: "303963552391",
99 100 101
	 73: "7295372",
	 74: "402",
	 75: "161667",
102 103
	 76: "190569291",
	 77: "71",
104 105
	 78: "55374",
	 79: "73162890",
106 107
	 80: "40886",
	 81: "427337",
108 109
	 82: "260324",
	 83: "425185",
110
	 84: "101524",
111
	 85: "2772",
112
	 86: "1818",
113
	 87: "1097343",
114
	 88: "7587457",
115
	 89: "743",
116
	 90: "1217",
117 118
	 91: "14234",
	 92: "8581146",
119
	 93: "1258",
120
	 94: "518408346",
121
	 95: "14316",
122
	 96: "24702",
123
	 97: "8739992577",
124
	 98: "18769",
125
	 99: "709",
126
	100: "756872327473",
127
	101: "37076114526",
128
	102: "228",
129
	103: "20313839404245",
130
	104: "329468",
131
	105: "73702",
132
	106: "21384",
133
	107: "259679",
134 135
	108: "180180",
	109: "38182",
136
	111: "612407567715",
137 138 139 140 141 142
	112: "1587000",
	113: "51161058134250",
	114: "16475640049",
	115: "168",
	116: "20492570929",
	117: "100808458960497",
143
	118: "44680",
144
	119: "248155780267521",
145
	120: "333082500",
146 147
	121: "2269",
	122: "1582",
148 149
	123: "21035",
	124: "21417",
150 151
	125: "2906969179",
	127: "18407904",
152 153
	128: "14516824220",
	129: "1000023",
154
	130: "149253",
155 156
	132: "843296",
	133: "453647705",
157 158
	134: "18613426663617118",
	135: "4989",
159
	139: "10057761",
160
	142: "1006193",
161
	145: "608720",
162
	146: "676333270",
163
	149: "52852124",
164 165
	150: "-271248680",
	151: "0.464399",
166
	155: "3857447",
167 168 169
	160: "16576",
	162: "3D58725572C62302",
	164: "378158756814587",
170
	166: "7130034",
171
	169: "178653872807",
172
	171: "142989277",
173
	172: "227485267000992000",
174
	173: "1572729",
175
	174: "209566",
176
	178: "126461847755",
177
	179: "986262",
178
	182: "399788195976",
179
	186: "2325629",
180
	187: "17427258",
181 182
	188: "95962097",
	191: "1918080160",
183
	197: "1.710637717",
184 185
	203: "34029210557338",
	204: "2944730",
186
	205: "0.5731441",
187
	206: "1389019170",
188
	208: "331951449665644800",
189
	211: "1922364685",
190
	214: "1677366278943",
191
	215: "806844323190414",
192
	216: "5437849",
193
	218: "0",
194
	222: "1590933",
195
	225: "2009",
196 197
	231: "7526965179680",
	243: "892371480",
198
	249: "9275262564250418",
199
	250: "1425480602091519",
200
	265: "209110240768",
201
	267: "0.999992836187",
202
	271: "4617456485273129588",
203
	280: "430.088247",
204
	287: "313135496",
205
	301: "2178309",
206
	303: "1111981904675169",
207
	304: "283988410192",
208
	315: "13625242",
209
	323: "6.3551758451",
210
	329: "199740353/29386561536000",
211
	345: "13938",
212
	346: "336108797689259276",
213
	347: "11109800204052",
214
	348: "1004195061",
215
	357: "1739023853137",
216
	381: "139602943319822",
217
	387: "696067597313468",
218
	401: "281632621",
219
	407: "39782849136421",
220
	425: "46479497324",
221
	429: "98792821",
Nayuki's avatar
Nayuki committed
222
	451: "153651073760956",
223
	493: "6.818741802",
224
	500: "35407281",
225
	518: "100315739184392",
226
	549: "476001479068717",
227
	587: "2240",
228 229 230 231 232
}


if __name__ == "__main__":
	main()