Revisions
-
methane revised this gist
Apr 28, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,6 +31,6 @@ def solver(length, boards, counts): boards = set() while len(boards) != scale: boards.add(int((100000-1)*random.random())+1) boards = sorted(boards) sys.setrecursionlimit(scale+4) solver(length, boards, list()) -
methane revised this gist
Apr 28, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def solver(length, boards, counts): if solve(length, boards, counts): answer = " + ".join(["%d*%d" % tuple(x) for x in zip(counts, boards)]) print(answer + " == " + str(eval(answer))) print("Boards must have at least %d." % sum(counts)) if __name__ == "__main__": length = 10**10 -
sinya8282 revised this gist
Apr 27, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,15 +3,15 @@ def solve(rest, boards, counts): if boards == []: return rest == 0 board = boards[-1] count = rest / board rest = rest % board while count >= 0: if solve(rest, boards[0:-1], counts): counts.append(count) return True count -= 1 rest += board return False def solver(length, boards, counts): @@ -27,7 +27,7 @@ def solver(length, boards, counts): # big(?) scale problem :) 1000 boards(1~100000 meters. Too unevenness?) import random import sys scale = 10000 boards = set() while len(boards) != scale: boards.add(int((100000-1)*random.random())+1) -
sinya8282 revised this gist
Apr 27, 2011 . 1 changed file with 22 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,35 +1,36 @@ #http://googledevjp.blogspot.com/2011/04/google-code-jam-2011.html def solve(rest, boards, counts): if boards == []: return rest == 0 board = boards[-1] count = rest / board rest = rest % board while count >= 0: if solve(rest, boards[0:-1], counts): counts.append(count) return True count -= 1 rest += board return False def solver(length, boards, counts): if solve(length, boards, counts): answer = " + ".join(["%d*%d" % tuple(x) for x in zip(counts, boards)]) print(answer + " == " + str(eval(answer))) print("Boards must have at least %d." % reduce(lambda x,y:x+y, counts)) if __name__ == "__main__": length = 10**10 boards = sorted([233,456,787]) solver(length, boards, list()) # big(?) scale problem :) 1000 boards(1~100000 meters. Too unevenness?) import random import sys scale = 10000 boards = set() while len(boards) != scale: boards.add(int((100000-1)*random.random())+1) boards = sorted(list(boards)) sys.setrecursionlimit(scale+4) solver(length, boards, list()) -
sinya8282 created this gist
Apr 27, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #http://googledevjp.blogspot.com/2011/04/google-code-jam-2011.html def solve(rest, bords, counts): if bords == []: return rest == 0 bord = bords[-1] count = rest / bord rest = rest % bord while count >= 0: if solve(rest, bords[0:-1], counts): counts.append(count) return True count -= 1 rest += bord return False def solver(length, bords, counts): if solve(length, bords, counts): answer = " + ".join(["%d*%d" % tuple(x) for x in zip(counts, bords)]) print(answer + " = " + str(eval(answer))) print("Boards must have at least %d." % reduce(lambda x,y:x+y, counts)) if __name__ == "__main__": length = 10**10 bords = sorted([233,456,787]) counts = list() solver(length, bords, counts) # big(?) scale problem :) 500 bords(about ten thousands meters) import random bords = set() while len(bords) != 500: bords.add(int((100000-1)*random.random())+1) bords = sorted(list(bords)) counts = list() solver(length, bords, counts)