Enigmatic Code

Programming Enigma Puzzles

Enigma 1728: Problem tackling

From New Scientist #2895, 15th December 2012 [link]

Joe was in his school’s rugby team. While practising tackling, Joe remembers standing on the goal line 25 feet from his friend Ken, who was by the corner flag. When the master blew his whistle, Ken ran along the touchline and Joe had to try to tackle him. Ken runs at half a mile an hour faster than Joe, who could only manage 12 miles an hour. So Joe never caught up with Ken.

What was the nearest Joe came to Ken?

It is pleasing that Enigma 1728 should be published on 12.12.12, as 1728 = 12³.

[enigma1728]

Advertisements

14 responses to “Enigma 1728: Problem tackling

  1. Jim Randell 12 December 2012 at 6:05 pm

    Assuming I understand they layout of rugby pitches correctly. This is a solution that uses the functions I recently added to the enigma.py library to find numerical approximations of functions. (It is implemented using a Golden Section Search minimiser). It runs in 45ms.

    from math import sin, cos, tan, radians, sqrt
    from enigma import find_min, printf
    
    # convert mph to fps
    def fps(s):
      return (s * 22.0) / 15.0
    
    # Joe runs at 12 mph
    vj = fps(12.0)
    
    # Ken runs at 12.5 mph
    vk = fps(12.5)
    
    # min distance for an angle of theta
    def min_d(theta):
      a = radians(theta)
    
      # distance at time t if J runs at an angle of theta
      def d(t):
        dk = 25.0 / tan(a) - vk * t
        dj = 25.0 / sin(a) - vj * t
        return sqrt(dk ** 2 + dj ** 2 - 2 * dk * dj * cos(a))
    
      r = find_min(d, 0.0, 120.0)
      return r.fv
    
    r = find_min(min_d, 0.0, 90.0)
    printf("min distance = {r.fv} at theta = {r.v}")
    

    Solution: Assuming Joe manages the minimum achievable distance, the closest he comes to Ken is 7 ft.

    • Jim Randell 12 December 2012 at 11:17 pm

      Here’s a symbolic solution using SymPy.

      from sympy import symbols, solve, Rational, sqrt
      from enigma import printf
      
      # convert mph to fps
      def fps(s):
        return s * Rational(22, 15)
      
      # Joe runs at 12 mph
      vj = fps(12)
      
      # Ken runs at 12.5 mph
      vk = fps(Rational(25, 2))
      
      # distance at time t if J runs at a y velocity of vjy
      def d(t, vjy):
        ky = vk * t
        vjx = sqrt(vj ** 2 - vjy ** 2)
        (jx, jy) = (25 - vjx * t, vjy * t)
        return sqrt(jx ** 2 + (ky - jy) ** 2)
      
      (t, v) = symbols('t v')
      # differentiate the distance
      eq1 = d(t, v).diff(t)
      # and solve to find when the distance is at a minimum
      for r1 in solve(eq1, t):
        # so the min distance (for a y velocity of v) is...
        eq2 = d(r1, v).simplify()
      
        # so now we need the minimum of that, so we differentiate it...
        for r2 in solve(eq2.diff(v), v):
          # and find the value for the minimum distance
          m = eq2.subs(v, r2)
          # and the x,y components of J's velocity
          x = sqrt(vj ** 2 - r2 ** 2)
          printf("min distance = {m} at vjx/vjy = {q}", q=x/r2)
      
    • Jim Randell 16 January 2013 at 10:46 am

      Enigma 1728By using the observation that the minimum distance occurs when J is travelling directly towards K, you can deduce the equation for the minimum distance as:

      d = 25 / sin(θ) – 24 / tan(θ)

      or more generally:

      d = g(1/sin(θ) – r/tan(θ))

      where r is the ratio vj / vk and g is the initial distance between Joe and Ken.

      By differentiation we find this is minimised in the case where cos(θ) = r.

      And the solution follows.

  2. ahmet sarqcoglu 14 December 2012 at 6:18 pm

    hi, can we use any programming language here?

    • Jim Randell 14 December 2012 at 7:53 pm

      If you’d like to share a programmatic solution, then feel free. In whatever language you choose. (See the “Notes” page for some tips on posting source code in WordPress).

      At the moment I tend to post my solutions in Python as I find it lends itself to concise readable code (but then I initially started writing solutions in the somewhat more esoteric Perl), and is freely available on many platforms (and even pre-installed on some), but it’s always interesting to see other languages too, and assuming it’s reasonably self-explanatory I should be able to understand the algorithm.

  3. ahmet saracoğlu 15 December 2012 at 12:39 pm
     private double ConvertTo(double velocity)
            {
                return velocity * 5280 / 3600;
            }
            
            private void button1_Click(object sender, EventArgs e)
            {
                double radian = Math.PI / 180, angle = 0, distanceX = 0;
                double YKen = 0, YJoe = 0, feet = 0, Vken = 12.5, VJoe = 12, VJx = 0, VJy = 0, t = 0,
                    difference = 0, min = 25, ang = 0, tmin = 0, distant = 0;
                string fortext = "";
    
                TextWriter tw = new StreamWriter("enigma.txt");
    
              
                // close the stream
                
    
                Vken=ConvertTo(Vken);
                VJoe = ConvertTo(VJoe);
    
                for (angle = 0; angle < 90; angle++)
                {
                    VJx = VJoe * Math.Cos(angle * radian);
                    VJy = VJoe * Math.Sin(angle * radian);
    
                   
    
                    fortext = fortext +"ANGLE:"+angle.ToString() + "\r\n";
    
                    for (distanceX = 0; distanceX <= 25; distanceX+=1)
                    {
                        t = distanceX / VJx;
                        YJoe = VJy * t;
                        YKen = Vken * t;
                        difference = Math.Sqrt(Math.Pow((YKen-YJoe),2)+Math.Pow((25-distanceX),2));
    
    
                        fortext = fortext + " TIME PASSED:" + t.ToString();
                        fortext = fortext + " DISTANCE:" + difference.ToString() + "\r\n";
    
                        if (difference < min)
                        {
                            distant = distanceX;
                            min = difference;
                            ang = angle;
                            tmin = t;
                        }
                    }
                }
                button1.Text = min.ToString()+ "  "+ang.ToString()+" "+tmin.ToString();
    
                
                tw.WriteLine(fortext);
                tw.Close();
    
            }
    
  4. ahmet saracoğlu 15 December 2012 at 5:19 pm

    This is the first python program whose belong to me, I have learned today a little

    def ConvertTo(velocity):
    	return velocity*5280/3600
    
    def FindMinDistance(Vken,VJoe):
    	import math
    	minumum=25
    	rdn=math.pi/180  #convert to radian,
    	Vk=ConvertTo(Vken) #miles/hour is converted to feet/seconds with that function
            Vj=ConvertTo(VJoe)
            for angle in range(0,89):
    		Vjx=VJoe*math.cos(angle*rdn)# Joe has velocity at x axis, and this is calculated
    		Vjy=VJoe*math.sin(angle*rdn)
    		for distanceX in range (0,25):
    			t=distanceX/Vjx #Joe is running distanceX feet and time elapsed.
    			Yjoe=Vjy*t
    			Yken=Vken*t #Ken's distance to his starting point for 't' time
    		        difference = math.sqrt(math.pow((Yken-Yjoe),2)+math.pow((25-distanceX),2))#Distance between them
    		        if (difference < minumum):  minumum = difference
    		        ang = angle# Joe's velocity vector angle
    		        tmin = t
    			print minumum
    
    • Jim Randell 18 December 2012 at 11:29 pm

      I think that’s a good start. Python is fairly easy to pick up (especially if you already know some other programming language), and has relatively few gotchas (although division using the / operator is one of them).

  5. arthurvause 17 December 2012 at 11:53 am

    Converting the speeds to feet per second, this diagram derives the distance between Joe and Ken.

    Then let Wolfram Alpha work out the minimum distance.

  6. Hugh Casement 13 June 2016 at 10:08 am

    In roughly 4.675 seconds Ken runs 600/7 feet and Joe 24/25 as far.
    I think I’m right in saying that if their starting positions (and roles) were reversed, the diagram would be the same triangle. In about 4.87 seconds Ken would run the extra 7, making 625/7 ft = 25/24 times as much as Joe’s 600/7.
    Of course it all assumes that rugby players are more intelligent than the dog that always runs directly towards its master: this old dog can’t work out the equation of the pursuit curve.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: