def solve6(): lp = LossyPrinter(1) peters_dices = [1 for n in range(9)] peter_win = 0 cnt_games = 0 try: while True: lp.try_print("%s" % peters_dices) peters_dices = inc_dices(peters_dices, 0, 4) peters_score = reduce(lambda x,y: x + y, peters_dices) colins_dices = [1 for n in range(6)] try: while True: colins_dices = inc_dices(colins_dices, 0, 6) colins_score = reduce(lambda x,y: x + y, colins_dices) cnt_games += 1 if peters_score > colins_score: peter_win += 1 except NoMoreDices: pass except NoMoreDices: pass print "cnt_games: %s" % cnt_games print "peter_win: %s" % peter_win print("%.7f" % (peter_win / float(cnt_games)))
def solve(): import sys from euler_tools.misc import LossyPrinter lp = LossyPrinter(1) answer = 0 #~ max_value = 10000000000 for n in range(1000): lp.try_print(n) answer = lossy_add(answer, lossy_pow(n, n, max_value), max_value) print answer
def solve2(peter_head_cnt, peter_dice_cnt, colin_head_cnt, colin_dice_cnt): lp = LossyPrinter(1) peter_win = 0 cnt_games = 0 ende = datetime.datetime.now() + datetime.timedelta(seconds=30) while datetime.datetime.now() < ende: #~ for n in range(100000): cnt_games += 1 peter = throw_dices(peter_head_cnt, peter_dice_cnt) colin = throw_dices(colin_head_cnt, colin_dice_cnt) #~ print "%s, %s" % (peter, if peter > colin: peter_win += 1 # 0.4120098 lp.try_print("%.7f" % (peter_win / float(cnt_games))) return peter_win / float(cnt_games)
def solve(): lp = LossyPrinter(1) problem_space = 20 #~ start = timeit.time.time() #~ divisors = [2, 3, 5, 7, 9, 11, 13, 17, 19] #~ divisors = [2, 3, 5, 7, 9, 11, 13, 17] # 20, 19, 18, 17, 16, 15, 14, 13, 12, 11 divisors = range(problem_space, problem_space / 2, -1) #~ divisors = range(2, problem_space + 1) #~ divisors.reverse() for n in xrange(problem_space, 1000000000, problem_space): lp.try_print("Testing: %s" % n) success = True for m in divisors: #~ print "%s %% %s = %s" % (n, m, n % m) if n % m != 0: success = False break if success: print "SUCCESS: %s" % n break
import math from euler_tools.misc import StopWatch, LossyPrinter #~ N: 102239423 lp = LossyPrinter(1) try: for n in range(3, math.factorial(9)): #~ n = 145 #~ n = 2 #~ while True: n += 1 lp.try_print(n) sum = 0 for digit in str(n): digit = int(digit) #~ print digit, math.factorial(digit) sum += math.factorial(digit) if sum > n: break if sum == n: print "Found one: %s" % n #~ if sum > n: #~ print "No" #~ print "Sum: %s" % sum except KeyboardInterrupt: print "\nN: %s" % n