Teaser 2799: Desert patrol
From The Sunday Times, 15th May 2016 [link] [link]
Pat is at Base Camp in the desert. There is enough fuel at the base for his vehicle to travel 420 miles, but the vehicle can hold (in its tank and in cans) at most enough fuel for 105 miles. On any journey he can leave some fuel in cans at any point and then pick up some or all of it whenever he passes in future. He has worked out that there is just enough fuel for him to reach the Main Camp.
How far is it between the two camps?
[teaser2799]
Jim Randell 10:11 am on 1 July 2021 Permalink |
This is a similar idea to Enigma 1732, except that this is for a 1 way journey.
See: Jeep Problem [ @wikipedia ].
This Python program runs in 54ms.
Run: [ @replit ]
from enigma import (Rational, irange, inf, printf) Q = Rational() # choose an implementation of rationals T = 420 # total amount of fuel available R = 105 # range # consider amount of fuel required for a maximal distance in k trips f = d = 0 for k in irange(1, inf): f += R d += R * Q(1, 2 * k - 1) printf("{k} trips, fuel = {f}, distance = {x:.2f} ({d})", x=float(d)) # stop when the fuel required reaches (or exceeds) the available fuel if not (f < T): breakSolution: The distance between the camps is 176 miles.
The journey will require 4 trips:
LikeLike
Frits 1:44 pm on 8 July 2021 Permalink |
Similar (next one R=315, T = 5*R)
T = 420 # total amount of fuel available R = 105 # range k = T // R # number of trips # number of times traject <n-1>th depot to the <n>th depot is travelled V = lambda k, n : 2 * (k - n) + 1 # T / R = k = 4 so 4 trips can be made setting up 3 depots. # The traject <n-1>th depot to the <n>th depot (n = 1..3) is travelled # V(n) = 2 * (k - n) + 1 times (where 0th depot is the base camp) so we need # to split R into V(n) equal parts and store V(n) - 2 parts at the depot # leaving 2 parts to reach and return from the <n>th depot # this means the <n>th depot is sum (i=1..n, R / V(n)) miles from base camp # consider amount of fuel required for a maximal distance in k trips print("answer:", R + sum(R // V(k, n) for n in range(1, k)), "miles")LikeLike
Frits 3:39 pm on 8 July 2021 Permalink |
or
from math import log def H(n): """Returns an approximate value of n-th harmonic number. http://en.wikipedia.org/wiki/Harmonic_number """ # Euler-Mascheroni constant gamma = 0.57721566490153286060651209008240243104215933593992 return gamma + log(n) + 0.5 / n - 1 / (12 * n**2) + 1 / (120 * n**4) R = 105 n = 4 print("answer:", round((H(2 * n - 1) - 0.5 * H(n - 1)) * R), "miles")LikeLike
Frits 1:43 pm on 17 July 2021 Permalink |
Different order:
LikeLike