Mr. Zngg cashed a check for D dollars and C cents at the Bank of Dinkydonk. The teller accidentally reversed the figures and gave him C dollars and D cents. Suppose he got more than N times the original amount, but not more than N+1 times.
(1) For what check value can Mr. Zngg spend the least money and end up with exactly N times the original amount?
(2) For what check value must Mr. Zngg spend the most money in order to end up with exactly N times the original amount?
(3) For what check value can Mr. Zngg spend an amount of money closest to his original check and end up with exactly N times the right amount? [The amount of the check will determine the value of N, which must be a positive integer. D and C are both 2-digit numbers.]
(1): If the original check was $12.37, he received $37.12 which is 3.0008084074373484 the amount of the check.
If he were to spend 1 penny, the ratio would be 37.11 / 12.37 = 3 = N
(2): If the original check was for $49.99, he received $99.49 which is 1.9901980396079213 the amount of the check.
If he were to spend $49.50, the ratio would be 49.99 / 49.99 = 1 = N
(3): If the original check was for $33.67, he received $67.33 which is 1.9997029997029998 the amount of the check.
If he were to spend $33.66, the ratio would be 33.67 / 33.67 = 1 = N
program output:
0.00999999999999801 [12, 37]
49.49999999999999 [49, 99]
0.010000000000005116 [33, 67]
"""
least = 10000
most = 0
closest = 10000
check_least = [10,10]
check_most = [10,10]
check_closest = [10,10]
for D in range(10,100):
for C in range(D,100):
if C == D:
continue
actual = D + C/100
received = C + D/100
ratio = received/actual
N = int(ratio)
spend = received - actual * N
if spend < least:
least = spend
check_least = [D,C]
if spend > most:
most = spend
check_most = [D,C]
if abs(spend - actual) < closest:
closest = abs(spend - actual)
check_closest = [D,C]
print(least, check_least)
print(most, check_most)
print(closest, check_closest)
|
Posted by Larry
on 2024-02-11 14:38:37 |