Few more problems

master
MitchellHansen 8 years ago
parent 13a163e81d
commit b3831fb360

@ -10,16 +10,37 @@
# 1/8 = 0.125
# 1/9 = 0.(1)
# 1/10 = 0.1
#
# Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
#
# Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
def longest_permutation(input):
def longest_permutation(denominator):
mod_list = []
modulo = 1.0
while True:
modulo *= 10
if modulo in mod_list:
break
mod_list.append(modulo)
modulo %= denominator
return len(mod_list)
longest_perm = 0
longest_perm_denominator = 0
for i in range(1, 1000):
perm_num = longest_permutation(i)
return input
if longest_perm < perm_num:
longest_perm = perm_num
longest_perm_denominator = i
i = str(1.0/7.0)
print(i)
if "142857" in i:
print(True)
print(longest_perm_denominator)
print(longest_perm)

@ -0,0 +1,43 @@
import math
# n^2 + a*n + b , where |a|<1000 and |b|<1000
def is_prime(number):
if number == 1:
return False
prime = True
i = 2
while i < math.sqrt(number) + 1:
if number % i == 0:
prime = False # found a factor, not prime
break
else:
i += 1
return prime
largest_n = 0
largest_n_a = 0
largest_n_b = 0
for a in range(-1000, 1000):
for b in range(-1000, 1000):
n = 1
while True:
if not is_prime(abs(n*n + a*n + b)):
break
else:
n += 1
if n > largest_n:
largest_n = n
largest_n_a = a
largest_n_b = b
print("{0}, {1}".format(a, b))
print(largest_n)
print(largest_n_a)
print(largest_n_b)

@ -0,0 +1,29 @@
# What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
# top right
tr_sum = 1
for i in range(1, 501):
tr_sum += pow(i * 2 + 1, 2)
# bottom right
br_sum = 1
br_tmp = 1
for i in range(1, 501):
br_tmp += 2 + 8 * (i-1)
br_sum += br_tmp
# bottom left
bl_sum = 1
for i in range(1, 501):
bl_sum += pow(i * 2, 2) + 1
# top left
tl_sum = 1
tl_tmp = 1
for i in range(1, 501):
tl_tmp += (i-1) * 8 + 6
tl_sum += tl_tmp
# I guess the problem is looking to not repeat the center case to take away 3
print(tl_sum + bl_sum + br_sum + tr_sum - 3)

@ -0,0 +1,12 @@
import itertools
set_list = set()
permutation_list = list(itertools.product(range(2, 101), range(2, 101)))
for i in permutation_list:
set_list.add(pow(i[0], i[1]))
print(len(set_list))

@ -0,0 +1,15 @@
total_sum = 0
# just gonna take a wild guess and say there aren't any more higher than 1 million
for i in range(2, 1000000):
num_str = str(i)
sum = 0
for ch in num_str:
sum += pow(int(ch), 5)
if sum == i:
print(i)
total_sum += i
print("Total sum {0}".format(total_sum))

@ -0,0 +1,45 @@
# solving this recursively is an interesting solution
import itertools
set_list = set()
permutation_list = list(itertools.combinations(list([1, 2, 5, 10, 20, 50, 100, 200]), 2))
success_count = 0
def recursive_coin_add(value, ciel):
if value == ciel:
global success_count
success_count += 1
return
if 1 + value <= ciel:
recursive_coin_add(1 + value, ciel)
if 2 + value <= ciel:
recursive_coin_add(2 + value, ciel)
if 5 + value <= ciel:
recursive_coin_add(5 + value, ciel)
if 10 + value <= ciel:
recursive_coin_add(10 + value, ciel)
if 20 + value <= ciel:
recursive_coin_add(20 + value, ciel)
if 50 + value <= ciel:
recursive_coin_add(50 + value, ciel)
if 100 + value <= ciel:
recursive_coin_add(100 + value, ciel)
if 200 + value <= ciel:
recursive_coin_add(200 + value, ciel)
recursive_coin_add(0, 200)
print(success_count)
Loading…
Cancel
Save