Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Ramanujan’s taxi Problem. S. Ramanujan was an Indian mathematician who became

ID: 3811318 • Letter: 1

Question

1.Ramanujan’s taxi Problem. S. Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him in the hospital one day, Hardy remarked that the number of his taxi was 1729, a rather dull number. To which Ramanujan replied, "No, Hardy! No, Hardy! It is a very interesting number. It is the smallest number expressible as the sum of two cubes in two different ways." Verify this claim by composing a program that takes a command line argument n and writes all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways. In other words, find distinct positive integers a, b, c, and d such that a3 + b3 = c3 + d3. Note: You MUST provide solutions for both for loop and while loop. And your output MUST have the following format: $ python ramanujanfor.py 2000 1729 = 1^3 + 12^3 = 9^3 + 10^3 $ python ramanujanfor.py 10000 1729 = 1^3 + 12^3 = 9^3 + 10^3 4104 = 2^3 + 16^3 = 9^3 + 15^3

2. Euler's sum-of-powers conjecture. In 1769 Leonhard Euler formulated a generalized version of Fermat's Last Theorem, conjecturing that at least n n-th powers are needed to obtain a sum that is itself a nth power, for n > 2. Compose a program to disprove Euler's conjecture (which stood until 1967), using a quintuply nested loop to find four positive integers whose 5th power sums to the 5th power of another positive integer. That is, find five distinct positive integers a, b, c, d, and e such that a5 + b5 + c5 + d5 = e5. Hint: review chapter 4-7 for nested loops. Note: You MUST provide solutions for both for loop and while loop. And your output MUST have the following format: $ python eulerSum.py 200 27^5 + 84^5 + 110^5 + 133^5 = 144^5

3. Checksums. The International Standard Book Number (ISBN) is a 10 digit code that uniquely specifies a book. The rightmost digit is a checksum digit which can be uniquely determined from the other 9 digits from the condition that d1 + 2d2 + 3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith digit from the right). The checksum digit d1 can be any value from 0 to 10: the ISBN convention is to use the value 'X' to denote 10. Example: the checksum digit corresponding to 020131452 is 5 since is the only value of d1 between 0 and and 10 for which d1 + 2*2 + 3*5 + 4*4 + 5*1 + 6*3 + 7*1 + 8*0 + 9*2 + 10*0 is a multiple of 11. Compose a program that takes a 9-digit integer as a command-line argument, computes the checksum, and writes the 10-digit ISBN number. It's OK if the program doesn't write any leading 0’s.

Standard Book Numbering (SBN) D Check digit ISBN 81752576610 ISBN-10 Your output siyaofus-MacBook-Pro: homework 1 siyaofu$ python ISBN.py 030640615 The full ISBN number is 0306406152 siyaofus-MacBook-Pro: homework 1 siyaofu$ python ISBN.py 020 131452 The full ISBN number is 0201314525 siyaofus-MacBook-Pro: homework1 siyaofu$

Explanation / Answer

Ans: The following are the three programs in python explained with comments

(1).

# importing package defaultdict

from collections import defaultdict

N =700

ntriples = 3 # for original Ramanujan problem

# result

results = defaultdict(list)

# range of x in 1 to N

for x in range(1, N):

#equation

x3 = x ** 3

for y in range(x+1, N): # y range x+1 to N

results[x3 + y ** 3].append((x, y)) # result

for key in sorted(results.keys()):

if len(results[key]) == ntriples:

print key, results[key]

(2).

def eulers_sum_of_powers():

max_n = 250

# pw_5 for n range()

pow_5 = [n**5 for n range(max_n)]

pow5_to_n = {n**5: n for n in range(max_n)}

for x0 in range(1, max_n):

for x1 in range(1, x0): # x1 range between 1 to x0

for x2 in range(1, x1): # x2 range 1 to x1

for x3 in range(1, x2): # x3 range 1 to x2

pow_5_sum = sum(pow_5[i] for i in (x0, x1, x2, x3))

if pow_5_sum in pow5_to_n:

# for y value

y = pow5_to_n[pow_5_sum]

return (x0, x1, x2, x3, y)

print("%i**5 + %i**5 + %i**5 + %i**5 == %i**5" % eulers_sum_of_powers())

(3).

while True:

ISBN=input("Enter 10 digit number for ISBN check digit: ")

while len(ISBN)!= 10:

print("check whether you entered 10 digits.")

# enter your ten digit number

ISBN=int(input("Enter 10 digit number again: "))

continue

else:

# for D1

D1 =int(ISBN[0])*11

# for D2

D2 =int(ISBN[1])*10

# for D3

D3 =int(ISBN[2])*9

# for D4

D4 =int(ISBN[3])*8

# for D4

D5 =int(ISBN[4])*7

# for D6

D6 =int(ISBN[5])*6

# for D7

D7 =int(ISBN[6])*5

# for D8

D8 =int(ISBN[7])*4

# for D9

D9 =int(ISBN[8])*3

# for D10

D10=int(ISBN[9])*2

# sum of all

Sum=(D1+D2+D3+D4+D5+D6+D7+D8+D9+D10)

Mod=Sum%11

D11=11-Mod

if D11==10:

D11='X'

# ISBN number calculation

ISBNNumber=str(ISBN)+str(D11)

print("The 11 digit ISBN Number obtained is *" + ISBNNumber + "*")

def close():

close=input ("Do you like to close the program or try once more 'y' for Yes and 'n' for No:")

while len(close)==1:

if input == "n":s

# returns ISBN

return (ISBN)

elif input == "y":

exit()

close()#

close = input("Do you like to try one more? If yes then Enter 'y' for Yes and 'n' for No: ")

# n means no and closes the program

if close.lower() in ("n", "no"):

print("Exiting")

break

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote