Enigmatic Code

Programming Enigma Puzzles

Puzzle #206: All square

From New Scientist #3423, 28th January 2023 [link] [link]

“What ho!” boomed Aunt Nicola. I could tell she was about to talk cricket at me. “Have you been following the test match between Pythagorea and Lagrangia?”

“Auntie, you know I prefer Navier-Stokes to Ben Stokes”. “Well”, she said, “you might be interested — there’s maths involved! In their first innings, Lagrangia’s total score was a square number”.

“Innings?” I asked. “It’s the word for a team’s turn to bat. They each have two. In their first, the Pythagoreans also got a square number, but they were more than 300 behind!”

“That sounds insurmountable”. “You might think so”, she said. “Then, when Lagrangia batted again, they added a different square number — less than 50 — so that their lead and overall total were also square numbers”.

“Goodness”. “But the Pythagoreans battled back in their second innings”, she continued, “and the game ended dramatically in a tie”.

I then knew enough to work out the totals of the four innings in order. What were they?



2 responses to “Puzzle #206: All square

  1. Jim Randell 28 January 2023 at 9:04 am

    The scores in both of L’s innings are squares that sum to a square. So they can be derived from a Pythagorean triple.

    And P’s innings are also squares that sum to the same total.

    This Python program runs in 64ms. (The internal runtime is 127µs).

    Run: [ @replit ]

    from enigma import (pythagorean_triples, group, unpack, sq, printf)
    # group pythagorean triples by hypotenuse
    g = group(pythagorean_triples(50), by=unpack(lambda x, y, z: z))
    # consider possible final totals
    for (z, ts) in g.items():
      if len(ts) < 2: continue
      T = sq(z)
      # L's 1st innings is >300 and 2nd innings is <50
      for (x1, y1, _) in ts:
        (L1, L2) = (sq(y1), sq(x1))
        if not (L1 > 300 and L2 < 50): continue
        # P's 1st innings is more than 300 less than L1, and different from L2
        for (x2, y2, _) in ts:
          (P1, P2) = (sq(x2), sq(y2))
          if not (L1 - P1 > 300 and P1 != L2): continue
          # output solution
          printf("T={T}: L1={L1} L2={L2}; P1={P1} P2={P2}")

    Solution: The innings were: L1=576, P1=225, L2=49, P2=400.

    Each team finished on a total of 625 runs.

    L: 576 + 49 = 625; (24² + 7² = 25²)
    P: 225 + 400 = 625; (15² + 20² = 25²)

  2. GeoffR 28 January 2023 at 10:59 am

    Interesting that Navier Stokes and Lagrange are mentioned in this teaser.

    Navier Stokes equations are important equations in Fluid Mechanics.

    The Clay Mathematics Institute has called this one of the seven most important open problems in mathematics and has offered a US$1 million prize for a solution or a counterexample.


    Lagrange was also an important mathematician.

    % A Solution in MiniZinc
    include "globals.mzn";
    % L1, P1 are 1st innings, L2, P2 are 2nd innings, L3, P3 are total scores
    var 1..961:P1; var 1..961:P2; var 1..961:P3;
    var 1..961:L1; var 1..961:L2; var 1..961:L3;
    % As final scores are the same, intermediate scores must be different
    constraint all_different([L1, L2, P1, P2]);
    % Pythagoreans were more than 300 behind after 1st innings
    % Lagrangian 2nd innings was less than 50
    constraint L2 < 50 /\ L1 - P1 > 300;
    % Tie for final scores
    constraint L1 + L2 == L3 /\ P1 + P2 == P3;
    constraint L3 == P3; 
    predicate is_sq(var int: y) =
    exists(z in 1..ceil(sqrt(int2float(ub(y))))) (z*z = y );
    % Lagrangian lead after L2 was a square number
    constraint is_sq(L1 + L2 - P1);
    constraint is_sq(L1) /\ is_sq(L2) /\ is_sq(L3);
    constraint is_sq(P1) /\ is_sq(P2) /\ is_sq(P3);
    solve satisfy;
    output ["Pythagoreans scores were " ++ show([P1, P2, P3])
    ++ "\n" ++ "Lagrangian scores were " ++ show([L1, L2, L3]) ]
    % Pythagoreans scores were [225, 400, 625]
    % Lagrangian scores were [576, 49, 625]
    % ----------
    % ==========

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: