diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/p0_tutorial/addition.py b/p0_tutorial/addition.py index 656f67b..898ed7d 100644 --- a/p0_tutorial/addition.py +++ b/p0_tutorial/addition.py @@ -19,4 +19,4 @@ Run python autograder.py def add(a, b): "Return the sum of a and b" "*** YOUR CODE HERE ***" - return 0 + return a + b diff --git a/p0_tutorial/autograder.py b/p0_tutorial/autograder.py index 4abe64d..13eab09 100644 --- a/p0_tutorial/autograder.py +++ b/p0_tutorial/autograder.py @@ -85,8 +85,8 @@ def readCommand(argv): # confirm we should author solution files def confirmGenerate(): - print 'WARNING: this action will overwrite any solution files.' - print 'Are you sure you want to proceed? (yes/no)' + print('WARNING: this action will overwrite any solution files.') + print('Are you sure you want to proceed? (yes/no)') while True: ans = sys.stdin.readline().strip() if ans == 'yes': @@ -94,7 +94,7 @@ def confirmGenerate(): elif ans == 'no': sys.exit(0) else: - print 'please answer either "yes" or "no"' + print('please answer either "yes" or "no"') # TODO: Fix this so that it tracebacks work correctly @@ -126,7 +126,7 @@ def loadModuleString(moduleSource): #f = StringIO(moduleCodeDict[k]) #tmp = imp.load_module(k, f, k, (".py", "r", imp.PY_SOURCE)) tmp = imp.new_module(k) - exec moduleCodeDict[k] in tmp.__dict__ + exec(moduleCodeDict[k], tmp.__dict__) setModuleName(tmp, k) return tmp @@ -187,12 +187,12 @@ def splitStrings(d): def printTest(testDict, solutionDict): pp = pprint.PrettyPrinter(indent=4) - print "Test case:" + print("Test case:") for line in testDict["__raw_lines__"]: - print " |", line - print "Solution:" + print(" |", line) + print("Solution:") for line in solutionDict["__raw_lines__"]: - print " |", line + print(" |", line) def runTest(testName, moduleDict, printTestCase=False, display=None): @@ -236,7 +236,7 @@ def getTestSubdirs(testParser, testRoot, questionToGrade): if questionToGrade != None: questions = getDepends(testParser, testRoot, questionToGrade) if len(questions) > 1: - print 'Note: due to dependencies, the following tests will be run: %s' % ' '.join(questions) + print('Note: due to dependencies, the following tests will be run: %s' % ' '.join(questions)) return questions if 'order' in problemDict: return problemDict['order'].split() @@ -269,8 +269,8 @@ def evaluate(generateSolutions, testRoot, moduleDict, exceptionMap=ERROR_HINT_MA questionDicts[q] = questionDict # load test cases into question - tests = filter(lambda t: re.match('[^#~.].*\.test\Z', t), os.listdir(subdir_path)) - tests = map(lambda t: re.match('(.*)\.test\Z', t).group(1), tests) + tests = [t for t in os.listdir(subdir_path) if re.match('[^#~.].*\.test\Z', t)] + tests = [re.match('(.*)\.test\Z', t).group(1) for t in tests] for t in sorted(tests): test_file = os.path.join(subdir_path, '%s.test' % t) solution_file = os.path.join(subdir_path, '%s.solution' % t) diff --git a/p0_tutorial/buyLotsOfFruit.py b/p0_tutorial/buyLotsOfFruit.py index 38fdb03..4f1fb47 100644 --- a/p0_tutorial/buyLotsOfFruit.py +++ b/p0_tutorial/buyLotsOfFruit.py @@ -32,12 +32,15 @@ def buyLotsOfFruit(orderList): Returns cost of order """ - totalCost = 0.0 - "*** YOUR CODE HERE ***" - return totalCost - + try: + return sum([fruitPrices[fruit] * quantity + for fruit, quantity in orderList]) + except KeyError: + print("Unexpected fruit!") + return None + # Main Method if __name__ == '__main__': "This code runs when you invoke the script from the command line" orderList = [ ('apples', 2.0), ('pears', 3.0), ('limes', 4.0) ] - print 'Cost of', orderList, 'is', buyLotsOfFruit(orderList) + print('Cost of', orderList, 'is', buyLotsOfFruit(orderList)) diff --git a/p0_tutorial/grading.py b/p0_tutorial/grading.py index b63c877..d8347c0 100644 --- a/p0_tutorial/grading.py +++ b/p0_tutorial/grading.py @@ -18,6 +18,7 @@ import cgi import time import sys import json +import html import traceback import pdb from collections import defaultdict @@ -46,7 +47,7 @@ class Grades: self.prereqs = defaultdict(set) #print 'Autograder transcript for %s' % self.project - print 'Starting on %d-%d at %d:%02d:%02d' % self.start + print('Starting on %d-%d at %d:%02d:%02d' % self.start) def addPrereq(self, question, prereq): self.prereqs[question].add(prereq) @@ -59,25 +60,24 @@ class Grades: completedQuestions = set([]) for q in self.questions: - print '\nQuestion %s' % q - print '=' * (9 + len(q)) - print + print('\nQuestion %s' % q) + print('=' * (9 + len(q))) + print() self.currentQuestion = q incompleted = self.prereqs[q].difference(completedQuestions) if len(incompleted) > 0: prereq = incompleted.pop() - print \ -"""*** NOTE: Make sure to complete Question %s before working on Question %s, + print("""*** NOTE: Make sure to complete Question %s before working on Question %s, *** because Question %s builds upon your answer for Question %s. -""" % (prereq, q, q, prereq) +""" % (prereq, q, q, prereq)) continue if self.mute: util.mutePrint() try: util.TimeoutFunction(getattr(gradingModule, q),1800)(self) # Call the question's function #TimeoutFunction(getattr(gradingModule, q),1200)(self) # Call the question's function - except Exception, inst: + except Exception as inst: self.addExceptionMessage(q, inst, traceback) self.addErrorHints(exceptionMap, inst, q[1]) except: @@ -88,18 +88,18 @@ class Grades: if self.points[q] >= self.maxes[q]: completedQuestions.add(q) - print '\n### Question %s: %d/%d ###\n' % (q, self.points[q], self.maxes[q]) + print('\n### Question %s: %d/%d ###\n' % (q, self.points[q], self.maxes[q])) - print '\nFinished at %d:%02d:%02d' % time.localtime()[3:6] - print "\nProvisional grades\n==================" + print('\nFinished at %d:%02d:%02d' % time.localtime()[3:6]) + print("\nProvisional grades\n==================") for q in self.questions: - print 'Question %s: %d/%d' % (q, self.points[q], self.maxes[q]) - print '------------------' - print 'Total: %d/%d' % (self.points.totalCount(), sum(self.maxes.values())) + print('Question %s: %d/%d' % (q, self.points[q], self.maxes[q])) + print('------------------') + print('Total: %d/%d' % (self.points.totalCount(), sum(self.maxes.values()))) if bonusPic and self.points.totalCount() == 25: - print """ + print(""" ALL HAIL GRANDPAC. LONG LIVE THE GHOSTBUSTING KING. @@ -130,11 +130,11 @@ class Grades: @@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@ -""" - print """ +""") + print(""" Your grades are NOT yet registered. To register your grades, make sure to follow your instructor's guidelines to receive credit on your project. -""" +""") if self.edxOutput: self.produceOutput() @@ -289,13 +289,13 @@ to follow your instructor's guidelines to receive credit on your project. if not raw: # We assume raw messages, formatted for HTML, are printed separately if self.mute: util.unmutePrint() - print '*** ' + message + print('*** ' + message) if self.mute: util.mutePrint() - message = cgi.escape(message) + message = html.escape(message) self.messages[self.currentQuestion].append(message) def addMessageToEmail(self, message): - print "WARNING**** addMessageToEmail is deprecated %s" % message + print("WARNING**** addMessageToEmail is deprecated %s" % message) for line in message.split('\n'): pass #print '%%% ' + line + ' %%%' diff --git a/p0_tutorial/shop.py b/p0_tutorial/shop.py index adddba6..f14c55d 100644 --- a/p0_tutorial/shop.py +++ b/p0_tutorial/shop.py @@ -24,7 +24,7 @@ class FruitShop: """ self.fruitPrices = fruitPrices self.name = name - print 'Welcome to %s fruit shop' % (name) + print('Welcome to %s fruit shop' % (name)) def getCostPerPound(self, fruit): """ diff --git a/p0_tutorial/shopAroundTown.py b/p0_tutorial/shopAroundTown.py index 23bf44d..2c37533 100644 --- a/p0_tutorial/shopAroundTown.py +++ b/p0_tutorial/shopAroundTown.py @@ -102,7 +102,7 @@ if __name__ == '__main__': ('shop2', 'shop3') : 1 } fruitTown = town.Town(shops, distances) - print "Orders:", orders + print("Orders:", orders) for price in (1, 3, 5, -1): - print "At gas price", price, "the best route is:", \ - shopAroundTown(orders, fruitTown, price) + print("At gas price", price, "the best route is:", \ + shopAroundTown(orders, fruitTown, price)) diff --git a/p0_tutorial/shopSmart.py b/p0_tutorial/shopSmart.py index 63833b6..6f32f34 100644 --- a/p0_tutorial/shopSmart.py +++ b/p0_tutorial/shopSmart.py @@ -28,8 +28,10 @@ def shopSmart(orderList, fruitShops): orderList: List of (fruit, numPound) tuples fruitShops: List of FruitShops """ - "*** YOUR CODE HERE ***" - return None + + prices = [(shop.getPriceOfOrder(orderList), shop) + for shop in fruitShops] + return min(prices)[1] if __name__ == '__main__': "This code runs when you invoke the script from the command line" @@ -39,6 +41,6 @@ if __name__ == '__main__': dir2 = {'apples': 1.0, 'oranges': 5.0} shop2 = shop.FruitShop('shop2',dir2) shops = [shop1, shop2] - print "For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName() + print("For orders ", orders, ", the best shop is", shopSmart(orders, shops).getName()) orders = [('apples',3.0)] - print "For orders: ", orders, ", the best shop is", shopSmart(orders, shops).getName() + print("For orders: ", orders, ", the best shop is", shopSmart(orders, shops).getName()) diff --git a/p0_tutorial/submission_autograder.py b/p0_tutorial/submission_autograder.py index 8c7d7a9..e7b1eae 100644 --- a/p0_tutorial/submission_autograder.py +++ b/p0_tutorial/submission_autograder.py @@ -15,7 +15,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from __future__ import print_function + from codecs import open """ diff --git a/p0_tutorial/testClasses.py b/p0_tutorial/testClasses.py index 6f95533..39ee87c 100644 --- a/p0_tutorial/testClasses.py +++ b/p0_tutorial/testClasses.py @@ -24,7 +24,7 @@ import sys class Question(object): def raiseNotDefined(self): - print 'Method not implemented: %s' % inspect.stack()[1][3] + print('Method not implemented: %s' % inspect.stack()[1][3]) sys.exit(1) def __init__(self, questionDict, display): @@ -145,7 +145,7 @@ class NumberPassedQuestion(Question): class TestCase(object): def raiseNotDefined(self): - print 'Method not implemented: %s' % inspect.stack()[1][3] + print('Method not implemented: %s' % inspect.stack()[1][3]) sys.exit(1) def getPath(self): diff --git a/p0_tutorial/testParser.py b/p0_tutorial/testParser.py index ceedeaf..17f3485 100644 --- a/p0_tutorial/testParser.py +++ b/p0_tutorial/testParser.py @@ -68,7 +68,7 @@ class TestParser(object): test['__emit__'].append(("multiline", m.group(1))) i += 1 continue - print 'error parsing test file: %s' % self.path + print('error parsing test file: %s' % self.path) sys.exit(1) return test diff --git a/p0_tutorial/textDisplay.py b/p0_tutorial/textDisplay.py index e920ad4..8e25a46 100644 --- a/p0_tutorial/textDisplay.py +++ b/p0_tutorial/textDisplay.py @@ -37,7 +37,7 @@ class NullGraphics: time.sleep(SLEEP_TIME) def draw(self, state): - print state + print(state) def updateDistributions(self, dist): pass @@ -64,7 +64,7 @@ class PacmanGraphics: self.turn += 1 if DISPLAY_MOVES: ghosts = [pacman.nearestPoint(state.getGhostPosition(i)) for i in range(1, numAgents)] - print "%4d) P: %-8s" % (self.turn, str(pacman.nearestPoint(state.getPacmanPosition()))),'| Score: %-5d' % state.score,'| Ghosts:', ghosts + print("%4d) P: %-8s" % (self.turn, str(pacman.nearestPoint(state.getPacmanPosition()))),'| Score: %-5d' % state.score,'| Ghosts:', ghosts) if self.turn % DRAW_EVERY == 0: self.draw(state) self.pause() @@ -75,7 +75,7 @@ class PacmanGraphics: time.sleep(SLEEP_TIME) def draw(self, state): - print state + print(state) def finish(self): pass diff --git a/p0_tutorial/town.py b/p0_tutorial/town.py index 60d561a..7723cba 100644 --- a/p0_tutorial/town.py +++ b/p0_tutorial/town.py @@ -78,7 +78,7 @@ class Town: if not route: return 0 totalDistance = self.getDistance('home', route[0]) - for i in xrange(len(route) - 1): + for i in range(len(route) - 1): totalDistance += self.getDistance(route[i], route[i+1]) totalDistance += self.getDistance(route[-1], 'home') return totalDistance diff --git a/p0_tutorial/tutorialTestClasses.py b/p0_tutorial/tutorialTestClasses.py index 5d42d37..3d20d78 100644 --- a/p0_tutorial/tutorialTestClasses.py +++ b/p0_tutorial/tutorialTestClasses.py @@ -28,7 +28,7 @@ class EvalTest(testClasses.TestCase): def evalCode(self, moduleDict): bindings = dict(moduleDict) - exec self.preamble in bindings + exec(self.preamble, bindings) return str(eval(self.test, bindings)) def execute(self, grades, moduleDict, solutionDict): diff --git a/p0_tutorial/util.py b/p0_tutorial/util.py index 5b066ed..e350440 100644 --- a/p0_tutorial/util.py +++ b/p0_tutorial/util.py @@ -29,101 +29,101 @@ import sys import inspect import heapq, random -import cStringIO +import io class FixedRandom: def __init__(self): - fixedState = (3, (2147483648L, 507801126L, 683453281L, 310439348L, 2597246090L, \ - 2209084787L, 2267831527L, 979920060L, 3098657677L, 37650879L, 807947081L, 3974896263L, \ - 881243242L, 3100634921L, 1334775171L, 3965168385L, 746264660L, 4074750168L, 500078808L, \ - 776561771L, 702988163L, 1636311725L, 2559226045L, 157578202L, 2498342920L, 2794591496L, \ - 4130598723L, 496985844L, 2944563015L, 3731321600L, 3514814613L, 3362575829L, 3038768745L, \ - 2206497038L, 1108748846L, 1317460727L, 3134077628L, 988312410L, 1674063516L, 746456451L, \ - 3958482413L, 1857117812L, 708750586L, 1583423339L, 3466495450L, 1536929345L, 1137240525L, \ - 3875025632L, 2466137587L, 1235845595L, 4214575620L, 3792516855L, 657994358L, 1241843248L, \ - 1695651859L, 3678946666L, 1929922113L, 2351044952L, 2317810202L, 2039319015L, 460787996L, \ - 3654096216L, 4068721415L, 1814163703L, 2904112444L, 1386111013L, 574629867L, 2654529343L, \ - 3833135042L, 2725328455L, 552431551L, 4006991378L, 1331562057L, 3710134542L, 303171486L, \ - 1203231078L, 2670768975L, 54570816L, 2679609001L, 578983064L, 1271454725L, 3230871056L, \ - 2496832891L, 2944938195L, 1608828728L, 367886575L, 2544708204L, 103775539L, 1912402393L, \ - 1098482180L, 2738577070L, 3091646463L, 1505274463L, 2079416566L, 659100352L, 839995305L, \ - 1696257633L, 274389836L, 3973303017L, 671127655L, 1061109122L, 517486945L, 1379749962L, \ - 3421383928L, 3116950429L, 2165882425L, 2346928266L, 2892678711L, 2936066049L, 1316407868L, \ - 2873411858L, 4279682888L, 2744351923L, 3290373816L, 1014377279L, 955200944L, 4220990860L, \ - 2386098930L, 1772997650L, 3757346974L, 1621616438L, 2877097197L, 442116595L, 2010480266L, \ - 2867861469L, 2955352695L, 605335967L, 2222936009L, 2067554933L, 4129906358L, 1519608541L, \ - 1195006590L, 1942991038L, 2736562236L, 279162408L, 1415982909L, 4099901426L, 1732201505L, \ - 2934657937L, 860563237L, 2479235483L, 3081651097L, 2244720867L, 3112631622L, 1636991639L, \ - 3860393305L, 2312061927L, 48780114L, 1149090394L, 2643246550L, 1764050647L, 3836789087L, \ - 3474859076L, 4237194338L, 1735191073L, 2150369208L, 92164394L, 756974036L, 2314453957L, \ - 323969533L, 4267621035L, 283649842L, 810004843L, 727855536L, 1757827251L, 3334960421L, \ - 3261035106L, 38417393L, 2660980472L, 1256633965L, 2184045390L, 811213141L, 2857482069L, \ - 2237770878L, 3891003138L, 2787806886L, 2435192790L, 2249324662L, 3507764896L, 995388363L, \ - 856944153L, 619213904L, 3233967826L, 3703465555L, 3286531781L, 3863193356L, 2992340714L, \ - 413696855L, 3865185632L, 1704163171L, 3043634452L, 2225424707L, 2199018022L, 3506117517L, \ - 3311559776L, 3374443561L, 1207829628L, 668793165L, 1822020716L, 2082656160L, 1160606415L, \ - 3034757648L, 741703672L, 3094328738L, 459332691L, 2702383376L, 1610239915L, 4162939394L, \ - 557861574L, 3805706338L, 3832520705L, 1248934879L, 3250424034L, 892335058L, 74323433L, \ - 3209751608L, 3213220797L, 3444035873L, 3743886725L, 1783837251L, 610968664L, 580745246L, \ - 4041979504L, 201684874L, 2673219253L, 1377283008L, 3497299167L, 2344209394L, 2304982920L, \ - 3081403782L, 2599256854L, 3184475235L, 3373055826L, 695186388L, 2423332338L, 222864327L, \ - 1258227992L, 3627871647L, 3487724980L, 4027953808L, 3053320360L, 533627073L, 3026232514L, \ - 2340271949L, 867277230L, 868513116L, 2158535651L, 2487822909L, 3428235761L, 3067196046L, \ - 3435119657L, 1908441839L, 788668797L, 3367703138L, 3317763187L, 908264443L, 2252100381L, \ - 764223334L, 4127108988L, 384641349L, 3377374722L, 1263833251L, 1958694944L, 3847832657L, \ - 1253909612L, 1096494446L, 555725445L, 2277045895L, 3340096504L, 1383318686L, 4234428127L, \ - 1072582179L, 94169494L, 1064509968L, 2681151917L, 2681864920L, 734708852L, 1338914021L, \ - 1270409500L, 1789469116L, 4191988204L, 1716329784L, 2213764829L, 3712538840L, 919910444L, \ - 1318414447L, 3383806712L, 3054941722L, 3378649942L, 1205735655L, 1268136494L, 2214009444L, \ - 2532395133L, 3232230447L, 230294038L, 342599089L, 772808141L, 4096882234L, 3146662953L, \ - 2784264306L, 1860954704L, 2675279609L, 2984212876L, 2466966981L, 2627986059L, 2985545332L, \ - 2578042598L, 1458940786L, 2944243755L, 3959506256L, 1509151382L, 325761900L, 942251521L, \ - 4184289782L, 2756231555L, 3297811774L, 1169708099L, 3280524138L, 3805245319L, 3227360276L, \ - 3199632491L, 2235795585L, 2865407118L, 36763651L, 2441503575L, 3314890374L, 1755526087L, \ - 17915536L, 1196948233L, 949343045L, 3815841867L, 489007833L, 2654997597L, 2834744136L, \ - 417688687L, 2843220846L, 85621843L, 747339336L, 2043645709L, 3520444394L, 1825470818L, \ - 647778910L, 275904777L, 1249389189L, 3640887431L, 4200779599L, 323384601L, 3446088641L, \ - 4049835786L, 1718989062L, 3563787136L, 44099190L, 3281263107L, 22910812L, 1826109246L, \ - 745118154L, 3392171319L, 1571490704L, 354891067L, 815955642L, 1453450421L, 940015623L, \ - 796817754L, 1260148619L, 3898237757L, 176670141L, 1870249326L, 3317738680L, 448918002L, \ - 4059166594L, 2003827551L, 987091377L, 224855998L, 3520570137L, 789522610L, 2604445123L, \ - 454472869L, 475688926L, 2990723466L, 523362238L, 3897608102L, 806637149L, 2642229586L, \ - 2928614432L, 1564415411L, 1691381054L, 3816907227L, 4082581003L, 1895544448L, 3728217394L, \ - 3214813157L, 4054301607L, 1882632454L, 2873728645L, 3694943071L, 1297991732L, 2101682438L, \ - 3952579552L, 678650400L, 1391722293L, 478833748L, 2976468591L, 158586606L, 2576499787L, \ - 662690848L, 3799889765L, 3328894692L, 2474578497L, 2383901391L, 1718193504L, 3003184595L, \ - 3630561213L, 1929441113L, 3848238627L, 1594310094L, 3040359840L, 3051803867L, 2462788790L, \ - 954409915L, 802581771L, 681703307L, 545982392L, 2738993819L, 8025358L, 2827719383L, \ - 770471093L, 3484895980L, 3111306320L, 3900000891L, 2116916652L, 397746721L, 2087689510L, \ - 721433935L, 1396088885L, 2751612384L, 1998988613L, 2135074843L, 2521131298L, 707009172L, \ - 2398321482L, 688041159L, 2264560137L, 482388305L, 207864885L, 3735036991L, 3490348331L, \ - 1963642811L, 3260224305L, 3493564223L, 1939428454L, 1128799656L, 1366012432L, 2858822447L, \ - 1428147157L, 2261125391L, 1611208390L, 1134826333L, 2374102525L, 3833625209L, 2266397263L, \ - 3189115077L, 770080230L, 2674657172L, 4280146640L, 3604531615L, 4235071805L, 3436987249L, \ - 509704467L, 2582695198L, 4256268040L, 3391197562L, 1460642842L, 1617931012L, 457825497L, \ - 1031452907L, 1330422862L, 4125947620L, 2280712485L, 431892090L, 2387410588L, 2061126784L, \ - 896457479L, 3480499461L, 2488196663L, 4021103792L, 1877063114L, 2744470201L, 1046140599L, \ - 2129952955L, 3583049218L, 4217723693L, 2720341743L, 820661843L, 1079873609L, 3360954200L, \ - 3652304997L, 3335838575L, 2178810636L, 1908053374L, 4026721976L, 1793145418L, 476541615L, \ - 973420250L, 515553040L, 919292001L, 2601786155L, 1685119450L, 3030170809L, 1590676150L, \ - 1665099167L, 651151584L, 2077190587L, 957892642L, 646336572L, 2743719258L, 866169074L, \ - 851118829L, 4225766285L, 963748226L, 799549420L, 1955032629L, 799460000L, 2425744063L, \ - 2441291571L, 1928963772L, 528930629L, 2591962884L, 3495142819L, 1896021824L, 901320159L, \ - 3181820243L, 843061941L, 3338628510L, 3782438992L, 9515330L, 1705797226L, 953535929L, \ - 764833876L, 3202464965L, 2970244591L, 519154982L, 3390617541L, 566616744L, 3438031503L, \ - 1853838297L, 170608755L, 1393728434L, 676900116L, 3184965776L, 1843100290L, 78995357L, \ - 2227939888L, 3460264600L, 1745705055L, 1474086965L, 572796246L, 4081303004L, 882828851L, \ - 1295445825L, 137639900L, 3304579600L, 2722437017L, 4093422709L, 273203373L, 2666507854L, \ - 3998836510L, 493829981L, 1623949669L, 3482036755L, 3390023939L, 833233937L, 1639668730L, \ - 1499455075L, 249728260L, 1210694006L, 3836497489L, 1551488720L, 3253074267L, 3388238003L, \ - 2372035079L, 3945715164L, 2029501215L, 3362012634L, 2007375355L, 4074709820L, 631485888L, \ - 3135015769L, 4273087084L, 3648076204L, 2739943601L, 1374020358L, 1760722448L, 3773939706L, \ - 1313027823L, 1895251226L, 4224465911L, 421382535L, 1141067370L, 3660034846L, 3393185650L, \ - 1850995280L, 1451917312L, 3841455409L, 3926840308L, 1397397252L, 2572864479L, 2500171350L, \ - 3119920613L, 531400869L, 1626487579L, 1099320497L, 407414753L, 2438623324L, 99073255L, \ - 3175491512L, 656431560L, 1153671785L, 236307875L, 2824738046L, 2320621382L, 892174056L, \ - 230984053L, 719791226L, 2718891946L, 624L), None) + fixedState = (3, (2147483648, 507801126, 683453281, 310439348, 2597246090, \ + 2209084787, 2267831527, 979920060, 3098657677, 37650879, 807947081, 3974896263, \ + 881243242, 3100634921, 1334775171, 3965168385, 746264660, 4074750168, 500078808, \ + 776561771, 702988163, 1636311725, 2559226045, 157578202, 2498342920, 2794591496, \ + 4130598723, 496985844, 2944563015, 3731321600, 3514814613, 3362575829, 3038768745, \ + 2206497038, 1108748846, 1317460727, 3134077628, 988312410, 1674063516, 746456451, \ + 3958482413, 1857117812, 708750586, 1583423339, 3466495450, 1536929345, 1137240525, \ + 3875025632, 2466137587, 1235845595, 4214575620, 3792516855, 657994358, 1241843248, \ + 1695651859, 3678946666, 1929922113, 2351044952, 2317810202, 2039319015, 460787996, \ + 3654096216, 4068721415, 1814163703, 2904112444, 1386111013, 574629867, 2654529343, \ + 3833135042, 2725328455, 552431551, 4006991378, 1331562057, 3710134542, 303171486, \ + 1203231078, 2670768975, 54570816, 2679609001, 578983064, 1271454725, 3230871056, \ + 2496832891, 2944938195, 1608828728, 367886575, 2544708204, 103775539, 1912402393, \ + 1098482180, 2738577070, 3091646463, 1505274463, 2079416566, 659100352, 839995305, \ + 1696257633, 274389836, 3973303017, 671127655, 1061109122, 517486945, 1379749962, \ + 3421383928, 3116950429, 2165882425, 2346928266, 2892678711, 2936066049, 1316407868, \ + 2873411858, 4279682888, 2744351923, 3290373816, 1014377279, 955200944, 4220990860, \ + 2386098930, 1772997650, 3757346974, 1621616438, 2877097197, 442116595, 2010480266, \ + 2867861469, 2955352695, 605335967, 2222936009, 2067554933, 4129906358, 1519608541, \ + 1195006590, 1942991038, 2736562236, 279162408, 1415982909, 4099901426, 1732201505, \ + 2934657937, 860563237, 2479235483, 3081651097, 2244720867, 3112631622, 1636991639, \ + 3860393305, 2312061927, 48780114, 1149090394, 2643246550, 1764050647, 3836789087, \ + 3474859076, 4237194338, 1735191073, 2150369208, 92164394, 756974036, 2314453957, \ + 323969533, 4267621035, 283649842, 810004843, 727855536, 1757827251, 3334960421, \ + 3261035106, 38417393, 2660980472, 1256633965, 2184045390, 811213141, 2857482069, \ + 2237770878, 3891003138, 2787806886, 2435192790, 2249324662, 3507764896, 995388363, \ + 856944153, 619213904, 3233967826, 3703465555, 3286531781, 3863193356, 2992340714, \ + 413696855, 3865185632, 1704163171, 3043634452, 2225424707, 2199018022, 3506117517, \ + 3311559776, 3374443561, 1207829628, 668793165, 1822020716, 2082656160, 1160606415, \ + 3034757648, 741703672, 3094328738, 459332691, 2702383376, 1610239915, 4162939394, \ + 557861574, 3805706338, 3832520705, 1248934879, 3250424034, 892335058, 74323433, \ + 3209751608, 3213220797, 3444035873, 3743886725, 1783837251, 610968664, 580745246, \ + 4041979504, 201684874, 2673219253, 1377283008, 3497299167, 2344209394, 2304982920, \ + 3081403782, 2599256854, 3184475235, 3373055826, 695186388, 2423332338, 222864327, \ + 1258227992, 3627871647, 3487724980, 4027953808, 3053320360, 533627073, 3026232514, \ + 2340271949, 867277230, 868513116, 2158535651, 2487822909, 3428235761, 3067196046, \ + 3435119657, 1908441839, 788668797, 3367703138, 3317763187, 908264443, 2252100381, \ + 764223334, 4127108988, 384641349, 3377374722, 1263833251, 1958694944, 3847832657, \ + 1253909612, 1096494446, 555725445, 2277045895, 3340096504, 1383318686, 4234428127, \ + 1072582179, 94169494, 1064509968, 2681151917, 2681864920, 734708852, 1338914021, \ + 1270409500, 1789469116, 4191988204, 1716329784, 2213764829, 3712538840, 919910444, \ + 1318414447, 3383806712, 3054941722, 3378649942, 1205735655, 1268136494, 2214009444, \ + 2532395133, 3232230447, 230294038, 342599089, 772808141, 4096882234, 3146662953, \ + 2784264306, 1860954704, 2675279609, 2984212876, 2466966981, 2627986059, 2985545332, \ + 2578042598, 1458940786, 2944243755, 3959506256, 1509151382, 325761900, 942251521, \ + 4184289782, 2756231555, 3297811774, 1169708099, 3280524138, 3805245319, 3227360276, \ + 3199632491, 2235795585, 2865407118, 36763651, 2441503575, 3314890374, 1755526087, \ + 17915536, 1196948233, 949343045, 3815841867, 489007833, 2654997597, 2834744136, \ + 417688687, 2843220846, 85621843, 747339336, 2043645709, 3520444394, 1825470818, \ + 647778910, 275904777, 1249389189, 3640887431, 4200779599, 323384601, 3446088641, \ + 4049835786, 1718989062, 3563787136, 44099190, 3281263107, 22910812, 1826109246, \ + 745118154, 3392171319, 1571490704, 354891067, 815955642, 1453450421, 940015623, \ + 796817754, 1260148619, 3898237757, 176670141, 1870249326, 3317738680, 448918002, \ + 4059166594, 2003827551, 987091377, 224855998, 3520570137, 789522610, 2604445123, \ + 454472869, 475688926, 2990723466, 523362238, 3897608102, 806637149, 2642229586, \ + 2928614432, 1564415411, 1691381054, 3816907227, 4082581003, 1895544448, 3728217394, \ + 3214813157, 4054301607, 1882632454, 2873728645, 3694943071, 1297991732, 2101682438, \ + 3952579552, 678650400, 1391722293, 478833748, 2976468591, 158586606, 2576499787, \ + 662690848, 3799889765, 3328894692, 2474578497, 2383901391, 1718193504, 3003184595, \ + 3630561213, 1929441113, 3848238627, 1594310094, 3040359840, 3051803867, 2462788790, \ + 954409915, 802581771, 681703307, 545982392, 2738993819, 8025358, 2827719383, \ + 770471093, 3484895980, 3111306320, 3900000891, 2116916652, 397746721, 2087689510, \ + 721433935, 1396088885, 2751612384, 1998988613, 2135074843, 2521131298, 707009172, \ + 2398321482, 688041159, 2264560137, 482388305, 207864885, 3735036991, 3490348331, \ + 1963642811, 3260224305, 3493564223, 1939428454, 1128799656, 1366012432, 2858822447, \ + 1428147157, 2261125391, 1611208390, 1134826333, 2374102525, 3833625209, 2266397263, \ + 3189115077, 770080230, 2674657172, 4280146640, 3604531615, 4235071805, 3436987249, \ + 509704467, 2582695198, 4256268040, 3391197562, 1460642842, 1617931012, 457825497, \ + 1031452907, 1330422862, 4125947620, 2280712485, 431892090, 2387410588, 2061126784, \ + 896457479, 3480499461, 2488196663, 4021103792, 1877063114, 2744470201, 1046140599, \ + 2129952955, 3583049218, 4217723693, 2720341743, 820661843, 1079873609, 3360954200, \ + 3652304997, 3335838575, 2178810636, 1908053374, 4026721976, 1793145418, 476541615, \ + 973420250, 515553040, 919292001, 2601786155, 1685119450, 3030170809, 1590676150, \ + 1665099167, 651151584, 2077190587, 957892642, 646336572, 2743719258, 866169074, \ + 851118829, 4225766285, 963748226, 799549420, 1955032629, 799460000, 2425744063, \ + 2441291571, 1928963772, 528930629, 2591962884, 3495142819, 1896021824, 901320159, \ + 3181820243, 843061941, 3338628510, 3782438992, 9515330, 1705797226, 953535929, \ + 764833876, 3202464965, 2970244591, 519154982, 3390617541, 566616744, 3438031503, \ + 1853838297, 170608755, 1393728434, 676900116, 3184965776, 1843100290, 78995357, \ + 2227939888, 3460264600, 1745705055, 1474086965, 572796246, 4081303004, 882828851, \ + 1295445825, 137639900, 3304579600, 2722437017, 4093422709, 273203373, 2666507854, \ + 3998836510, 493829981, 1623949669, 3482036755, 3390023939, 833233937, 1639668730, \ + 1499455075, 249728260, 1210694006, 3836497489, 1551488720, 3253074267, 3388238003, \ + 2372035079, 3945715164, 2029501215, 3362012634, 2007375355, 4074709820, 631485888, \ + 3135015769, 4273087084, 3648076204, 2739943601, 1374020358, 1760722448, 3773939706, \ + 1313027823, 1895251226, 4224465911, 421382535, 1141067370, 3660034846, 3393185650, \ + 1850995280, 1451917312, 3841455409, 3926840308, 1397397252, 2572864479, 2500171350, \ + 3119920613, 531400869, 1626487579, 1099320497, 407414753, 2438623324, 99073255, \ + 3175491512, 656431560, 1153671785, 236307875, 2824738046, 2320621382, 892174056, \ + 230984053, 719791226, 2718891946, 624), None) self.random = random.Random() self.random.setstate(fixedState) @@ -295,8 +295,8 @@ class Counter(dict): """ Returns the key with the highest value. """ - if len(self.keys()) == 0: return None - all = self.items() + if len(list(self.keys())) == 0: return None + all = list(self.items()) values = [x[1] for x in all] maxIndex = values.index(max(values)) return all[maxIndex][0] @@ -313,7 +313,7 @@ class Counter(dict): >>> a.sortedKeys() ['second', 'third', 'first'] """ - sortedItems = self.items() + sortedItems = list(self.items()) compare = lambda x, y: sign(y[1] - x[1]) sortedItems.sort(cmp=compare) return [x[0] for x in sortedItems] @@ -333,7 +333,7 @@ class Counter(dict): """ total = float(self.totalCount()) if total == 0: return - for key in self.keys(): + for key in list(self.keys()): self[key] = self[key] / total def divideAll(self, divisor): @@ -391,7 +391,7 @@ class Counter(dict): >>> a['first'] 1 """ - for key, value in y.items(): + for key, value in list(y.items()): self[key] += value def __add__( self, y ): @@ -451,7 +451,7 @@ def raiseNotDefined(): line = inspect.stack()[1][2] method = inspect.stack()[1][3] - print "*** Method not implemented: %s at line %s of %s" % (method, line, fileName) + print("*** Method not implemented: %s at line %s of %s" % (method, line, fileName)) sys.exit(1) def normalize(vectorOrCounter): @@ -463,7 +463,7 @@ def normalize(vectorOrCounter): counter = vectorOrCounter total = float(counter.totalCount()) if total == 0: return counter - for key in counter.keys(): + for key in list(counter.keys()): value = counter[key] normalizedCounter[key] = value / total return normalizedCounter @@ -584,19 +584,19 @@ def lookup(name, namespace): module = __import__(moduleName) return getattr(module, objName) else: - modules = [obj for obj in namespace.values() if str(type(obj)) == ""] + modules = [obj for obj in list(namespace.values()) if str(type(obj)) == ""] options = [getattr(module, name) for module in modules if name in dir(module)] - options += [obj[1] for obj in namespace.items() if obj[0] == name ] + options += [obj[1] for obj in list(namespace.items()) if obj[0] == name ] if len(options) == 1: return options[0] - if len(options) > 1: raise Exception, 'Name conflict for %s' - raise Exception, '%s not found as a method or class' % name + if len(options) > 1: raise Exception('Name conflict for %s') + raise Exception('%s not found as a method or class' % name) def pause(): """ Pauses the output stream awaiting user feedback. """ - print "" - raw_input() + print("") + input() # code to handle timeouts