This is my assignment:
Find the triplet a, b, c ∈ {x | x ∈ Z and 450 > x > 0}
Such that the following relations is satisfied:
a = if b is even: c+11 BUT if b is odd: 2c-129
b = (a * c) mod 2377
- c = (Sum of b-7k from k=0 to a-1) + 142
This is what I've tried so far:
Alternative 1:
for a in range(1,449):
for b in range(1, 449):
for c in range(1, 449):
#a
if b%2==0:
a=c+11
elif b%2!=0:
a=2*c-129
#b
b = (a*c)%2377
#c
k = 0
c0=0
upper = a-1
for i in range(0, upper+1):
c0 = b-7*i
#k+=1
c = c0 + 142
print a, b, c
Alternative 2:
def a_func(x):
if (b_func(x)%2==0):
return c_func(x)+11
else:
return 2*c_func(x)-129
def b_func(x):
return a_func(x)*c_func(x) % 2377
def c_func(x):
k=0
c0=0
upper = a_func(x)-1
for i in range(0, upper+1):
c0 = b_func(x) - 7 * k
k+=1
return c0+142
def all(x):
return a_func(x), b_func(x), c_func(x)
for x in range(1, 449):
print all(x)
None of them seem to work.
Please show a little more effort. The first program prints 449*449*449 lines of output. There is clearly something totally wrong.
The idea behind the the task is, that you have to check, if the three equations hold or not.
So the main program can be of the following structure:
for a in range(1,449):
for b in range(1, 449):
for c in range(1, 449):
if equation_one_holds and equation_two_holds and equation_three_holds:
print a, b, c
Your task now is to implements the checks. As a hint, equation_two_holds
could be (b == (a * c) % 2377)
. The checks for equaltion_one_holds
and equation_three_holds
are a little bit more complicated, but with a little bit of effort, you can manage it.