Updates from Jim Randell Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 6:49 am on 11 March 2019 Permalink | Reply
    Tags:   

    Teaser 2937: Long division 

    From The Sunday Times, 6th January 2019 [link] [link]

    I wrote down a 2-digit number and a 5-digit number and then carried out a long division.

    I then erased all of the digits in the calculation, other than the 1’s, and so finished up with the image above.

    If I told you how many different digits I had erased, then you should be able to work out my two original numbers.

    What were my two original numbers?

    [teaser2937]

     
    • Jim Randell's avatar

      Jim Randell 6:52 am on 11 March 2019 Permalink | Reply

      Here’s a solution using the [[ SubstitutedDivision() ]] and [[ filter_unique() ]] functions from the enigma.py library.

      This program runs in 63ms. (Internal runtime is 7.2ms).

      Run: [ @replit ]

      from enigma import (SubstitutedDivision, filter_unique, printf)
      
      # the division sum
      p = SubstitutedDivision(
        "????1 / ?? = 1???",
        [ "?? - ?? = ?1", "?1? - 1?? = ??", "??? - ??? = 11", "111 - 111 = 0" ],
        digits=(0, 2, 3, 4, 5, 6, 7, 8, 9),
        verbose="T",  # show candidate solutions
      )
      
      # find solutions unique by the number of digits involved
      f = lambda s: len(set(s.s.values()))
      g = lambda s: (s.a, s.b)
      ss = filter_unique(p.solve(), f, g).unique
      
      # output solutions
      for s in ss:
        printf("SOLUTION: {s.a} / {s.b} = {s.c} [{n} digits]", n=f(s))
      

      Solution: The two original numbers were 37 and 58571.

      The diagram can describe 3 possible divisions:

      58201 ÷ 37 = 1573
      58571 ÷ 37 = 1583
      58941 ÷ 37 = 1593

      The first and third of these have 8 different digits in the long division sum, the second one uses 9 different digits and so gives the solution.

      Although the puzzle states that the erased digits are not 1 (and the program ensures this), there are no further solutions to the more general problem where the erased digits may be 1. We can see this by adding [[ 1 ]] in the [[ digits ]] specification on line 7 (or just removing that line completely to allow any digit to be used).

      Like

    • GeoffR's avatar

      GeoffR 7:16 pm on 14 March 2019 Permalink | Reply

      This solution found the same three possible solutions

      However, only the solution 58571 / 37 = 1583 had a unique number of digits erased by the setter, as the other two solutions had the same number of digits erased. The two digit number is therefore 37 and the five digit number is 58571.

      % A Solution in MiniZinc
      include "globals.mzn";                   
      
      %        w c d e         1 5 8 3
      %      ---------       ----------    
      %  a b)f g h i w    3 7)5 8 5 7 1
      %      a b              3 7
      %      ---              ---
      %      m 1 h            2 1 5
      %      w p q            1 8 5
      %      -----            -----          
      %        r s i            3 0 7
      %        t u v            2 9 6 
      %        -----            -----   
      %          1 1 1            1 1 1
      %          1 1 1            1 1 1 
      %          =====            =====
                                                                                                                                          
      int: w == 1;
      
      var 0..9: a; var 0..9: b; var 0..9: c; var 0..9: d; var 0..9 :e;
      var 0..9: f; var 0..9: g; var 0..9: h; var 0..9: i; var 0..9: j;
      var 0..9: k; var 0..9: m; var 0..9: p; var 0..9: q; var 0..9: r; 
      var 0..9: s; var 0..9: t; var 0..9: u; var 0..9: v;
       
      constraint a > 0 /\ j > 0 /\ m > 0 /\ r > 0 /\ t > 0;
      
      var 10..99: ab = 10*a + b;
      var 1000..1999: wcde = 1000*1 + c*100 + d*10 + e;
      var 10000..99999: fghiw = 10000*f + 1000*g + 100*h + 10*i + w;
      
      var 10..99: jk = 10*j + k;
      var 100..999: m1h = 100*m + 10^1 + h;
      var 100..199: wpq = 100*1 + 10*p + q;
      var 100..999: rsi = 100*r + 10*s + i;
      var 100..999: tuv = 100*t + 10*u + v;
      
      var 10..99: rs = 10*r + s;
      var 10..99: m1 = 10*m + 1;
      var 10..99: fg = 10*f + g;
      
      constraint ab * wcde == fghiw;
      constraint fg - ab == m1;
      constraint c * ab = wpq /\ m1h - wpq == rs;
      
      constraint d * ab == tuv /\ rsi - tuv == 11;
      constraint e * ab == 111;
      
      % variables used in programme - all erased by setter (but not including w = 1)
      var set of int: s1 = {a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v};  
      
      solve satisfy;
      
      output [ show(fghiw) ++ " / " ++ show (ab) ++ " = " ++ show(wcde) 
      ++ ", digit set used (exc w=1) = " ++ show(s1) ++ "\n"
      ++ "\n[a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v ]  "
      ++ "\n" ++  show ( [a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v ] )];  % excludes w = 1
      
      % 58201 / 37 = 1573, digit set used (exc w=1) = {0,2,3,5,7,8,9}
      % 7 no. digit variables used, not inc 1
      
      % [a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v ]  
      % [3, 7, 5, 7, 3, 5, 8, 2, 0, 2, 8, 5, 2, 7, 2, 5, 9]
      % % time elapsed: 0.02 s
      % ----------
      % 58571 / 37 = 1583, digit set used (exc w=1) = {0,2,3,5,6,7,8,9} - ANSWER
      % 8 no. digit variables used, not inc 1
      
      % [a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v ]  
      % [3, 7, 5, 8, 3, 5, 8, 5, 7, 2, 8, 5, 3, 0, 2, 9, 6]
      % % time elapsed: 0.02 s
      % ----------
      % 58941 / 37 = 1593, digit set used (exc w=1) = {2,3,4,5,7,8,9}
      % 7 no. digit variables used, not inc 1
      
      % [a, b, c, d, e, f, g, h, i, m, p, q, r, s, t, u, v ]  
      % [3, 7, 5, 9, 3, 5, 8, 9, 4, 2, 8, 5, 3, 4, 3, 3, 3]
      % % time elapsed: 0.02 s
      % ----------
      % ==========
      % Finished in 232msec
      
      
      

      Like

    • elbaz haviv's avatar

      elbaz haviv 1:10 pm on 30 August 2023 Permalink | Reply

      1593 x 37 and 1573 x 37 also fit the puzzle

      Like

      • Jim Randell's avatar

        Jim Randell 1:35 pm on 30 August 2023 Permalink | Reply

        As noted above these 2 candidate solutions are eliminated as they both have 7 different digits erased. The remaining candidate has 8 different erased digits, and so provides the required answer to the puzzle.

        Like

    • elbaz haviv's avatar

      elbaz haviv 4:18 pm on 30 August 2023 Permalink | Reply

      ok later I noticed that but I don’t find
      an edit future to correct my self.
      anyway Thank you.

      Like

  • Unknown's avatar

    Jim Randell 12:16 am on 10 March 2019 Permalink | Reply
    Tags:   

    Teaser 2946: Pentagonal gardens 

    From The Sunday Times, 10th March 2019 [link] [link]

    Adam and Eve have convex pentagonal gardens consisting of a square lawn and paving. Both gardens have more than one right-angled corner. All the sides of the gardens and lawns are the same whole number length in metres, but Adam’s garden has a larger total area. Eve has worked out that the difference in the areas of the gardens multiplied by the sum of the paved areas (both in square metres) is a five-digit number with five different digits.

    What is that number?

    [teaser2946]

     
    • Jim Randell's avatar

      Jim Randell 1:16 am on 10 March 2019 Permalink | Reply

      If I’ve understood this correctly there are only two ways to construct the gardens, and this gives a fairly limited set of integer sides. And only one of those gives a viable 5-digit number.

      I worked out 2 possible shapes for the gardens, where the lawn forms most of the perimeter:

      To make calculating the area easier I have split the lawn of A’s garden in two and inserted the paved area between. The areas are the same as if the lawn was a contiguous square.

      If we suppose the line segments making up the perimeter of the gardens are units, then both squares are unit squares and both triangles have a base of length 1.

      A’s triangle has a height of √(7)/2 and an area of √(7)/4. E’s triangle has a height of √(3)/2 and an area of √(3)/4.

      The difference in the total areas of the gardens is:

      (1 + √(7)/4) − (1 + √(3)/4) = (√7 − √3) / 4

      The sum of the paved areas is:

      √(7)/4 + √(3)/4 = (√7 + √3) / 4

      Multiplying these together we get:

      (√7 + √3) × (√7 − √3) / (4 × 4) = 1 / 4

      So, if the gardens were all of side x, the number N would be:

      N = (x^4) / 4

      For a 5-digit value for N there are only a few values of x to try, and this can be completed manually or programatically.

      This Python program runs in 77ms.

      Run: [ @repl.it ]

      from enigma import (irange, div, is_duplicate, printf)
      
      # consider 5 digit values for N
      for x in irange.round(pow(4 * 10000, 0.25), pow(4 * 99999, 0.25)):
        N = div(pow(x, 4), 4)
        if N is None or is_duplicate(N): continue
        # output solution
        printf("x={x} N={N}")
      

      Solution: The number is 16384.

      Like

      • Jim Randell's avatar

        Jim Randell 8:55 am on 10 March 2019 Permalink | Reply

        I’m pretty sure these are the only two possible shapes.

        If you imagine trying to form a set of 5 equal length linked rods into a convex pentagon with more than one right angle, then it is not possible with 3 right angles, so there must be exactly 2 right angles. And these are either on adjacent vertices or have one vertex between them.

        Either way, the remaining rods are forced into unique positions, giving the shapes A and E.

        Although note that with A there are many ways that a unit square can fit inside the pentagon (not necessarily touching the perimeter).

        Like

  • Unknown's avatar

    Jim Randell 9:30 am on 9 March 2019 Permalink | Reply
    Tags: by: T Verschoyle,   

    Brain-Teaser 462: [Crocodiles] 

    From The Sunday Times, 5th April 1970 [link]

    A friend of mine, who is headmistress of a small school, sends her fifteen girls for a walk every day in a crocodile of threes. She told me that she had for long been trying, unsuccessfully, to arrange that no two girls ever walked together in a trio more than once during a whole week; and she added that, denoting the girls by the first fifteen letters of the alphabet, she wanted A to walk with B and C on Sunday, and with the consecutive pairs of letters for the rest of the week, finishing with N and O on Saturday.

    “Well”, I replied, “if four more trios were specified, I could find a unique solution for your problem. But, if you want to work it out yourself, I shall help you by telling you B’s and C’s partners throughout the week:

    Mon: BHJ, CMN
    Tue: BIK, CLO
    Wed: BLN, CEF
    Thu: BMO, CDG
    Fri: BDF, CIJ
    Sat: BEG, CHK

    Furthermore, F, who is a bit of a snob as regards those lower in the alphabetical order, will be relieved to find that she does not have to walk with the two available furthest from herself in that order until Saturday.

    Now, you should be able to tell me with whom D walks on Sunday and on Wednesday.”

    This puzzle was originally published with no title.

    [teaser462]

     
    • Jim Randell's avatar

      Jim Randell 9:31 am on 9 March 2019 Permalink | Reply

      I’ve marked this puzzle as flawed for two reasons. Firstly when the solution was published it was acknowledged that there was not a unique answer, and secondly I’m not really sure that the constraint about F makes sense.

      My first thought was that it means that F partnered N and O (the two furthest along from F alphabetically) on Saturday, but N and O are already partnering A on Saturday. It does say the “two available furthest from herself”, so perhaps it means F partners L and M (the next furthest alphabetically), but L and M were partnering A on Friday, so can’t appear in a grouping on Saturday. In fact, according to the information we are given, the groups: ANO, BEG, CHK are already defined for Saturday, leaving DFIJLM, to be formed into viable groups. So maybe we are meant to partner F with J and M. This is the interpretation I ended up using, and it does generate the published answer(s). But I think there is still a problem (see below).

      This Python 3 program solves the puzzle recursively in 865ms.

      Run: [ @repl.it ]

      from itertools import combinations
      from enigma import unpack, partitions, join, update, flatten, printf
      
      # check no pairs are repeated
      def pairs(ps, ts):
        ps = ps.copy()
        for t in ts:
          for p in combinations(t, 2):
            if p in ps: return None
            ps.add(p)
        return ps
      
      # complete the groups, with pairs ps already used
      def solve(groups, ps):
        # find days with missing groups
        gs = list((k, vs) for (k, vs) in groups.items() if len(vs) < 5)
        if not gs:
          yield groups
        else:
          # choose the day with the fewest missing groups
          (k, vs) = min(gs, key=unpack(lambda k, vs: 5 - len(vs)))
          # form the remaining kids into groups
          for ts in partitions(kids.difference(*vs), 3):
            ts = list(join(sorted(t)) for t in ts)
            ps2 = pairs(ps, ts)
            if ps2:
              yield from solve(update(groups, [(k, sorted(vs + ts))]), ps2)
      
      # the kids
      kids = set("ABCDEFGHIJKLMNO")
      
      # the groupings we are given
      groups = dict(
        Sun=["ABC"],
        Mon=["ADE", "BHJ", "CMN"],
        Tue=["AFG", "BIK", "CLO"],
        Wed=["AHI", "BLN", "CEF"],
        Thu=["AJK", "BMO", "CDG"],
        Fri=["ALM", "BDF", "CIJ"],
        Sat=["ANO", "BEG", "CHK", "FJM"],
      )
      
      # check no pairing is duplicated among the given groups
      ps = pairs(set(), flatten(groups.values()))
      assert ps
      
      # solve for the remaining groups
      for gs in solve(groups, ps):
        # find the group on day d for child x
        get = lambda d, x: list(t for t in gs[d] if x in t)[0]
        # a measure for F's partners
        fn = lambda d: sum(int(x, 25) - 9 for x in get(d, 'F') if x != 'F')
        # output the groups
        for (k, vs) in gs.items():
          printf("{k}: {vs} [{m}]", vs=join(vs, sep=" "), m=fn(k))
        # D's groups on Sun and Wed
        printf("[D] Sun={S} Wed={W}", S=get("Sun", 'D'), W=get("Wed", 'D'))
        printf()
      

      Solution: There are two possible solutions: (1) D partners H and O on Sunday, and K and M on Wednesday; (2) D partners K and N on Sunday, and J and O on Wednesday.

      The full groupings look like this:

      Sun: ABC DHO EJL FKN GIM
      Mon: ADE BHJ CMN FIO GKL
      Tue: AFG BIK CLO DJN EHM
      Wed: AHI BLN CEF DKM GJO
      Thu: AJK BMO CDG EIN FHL
      Fri: ALM BDF CIJ EKO GHN
      Sat: ANO BEG CHK DIL FJM

      Sun: ABC DKN EIM FHO GJL
      Mon: ADE BHJ CMN FKL GIO
      Tue: AFG BIK CLO DHM EJN
      Wed: AHI BLN CEF DJO GKM
      Thu: AJK BMO CDG EHL FIN
      Fri: ALM BDF CIJ EKO GHN
      Sat: ANO BEG CHK DIL FJM

      And now we run into the problem with F, their “worst” day is suppose to be Saturday, when they partner J and M.

      But in the first case, F partners K and N on Sunday, each of these is one step further along the alphabet than Saturday’s partners, so is surely a less desirable situation. If we just sum the positions in the alphabet of her partners to get a measure of “badness”, the partnering I and O on Monday is also less desirable than Saturday.

      Using the same measure we find that in the second case, Sunday, Monday and Thursday all score as badly as Saturday for F.

      And if we use other measures (e.g. looking for the “best” of the two partners, or the “worst”) we find that in neither of these scenarios does Saturday does provide F with their worst partnering of the week.

      Further, if we consider all possible pairings for F on Saturday (and not a specific one) we find it is not possible to solve the puzzle so F has her worst day on Saturday.

      So maybe it would have just been better to say: “F doesn’t get on with her sisters, J and M. So she will be relieved to find she does not have to walk with them until Saturday”. Or just come straight out with it: “F walked with J and M on Saturday”. But that still leaves the problem of the two answers. Although an extra condition disallowing one of the groupings in one of the answers would sort that out.

      Like

  • Unknown's avatar

    Jim Randell 8:06 am on 8 March 2019 Permalink | Reply
    Tags: ,   

    Teaser 2938: Numerophobia 

    From The Sunday Times, 13th January 2019 [link] [link]

    In Letterland there are no numerals. They use the decimal system of counting just like we do but the digits 0-9 are represented by the first ten letters of the alphabet AJ inclusive but in no particular order. The following calculations are typical:

    A + G = C
    B × J = FH
    GE × AI = HDB

    What number is represented by ABCDEFGHIJ?

    As stated this puzzle does not have a unique solution.

    This puzzle was not included in the book The Sunday Times Teasers Book 1 (2021).

    [teaser2938]

     
    • Jim Randell's avatar

      Jim Randell 8:07 am on 8 March 2019 Permalink | Reply

      We can feed the alphametic expressions directly to the [[ SubstitutedExpression() ]] solver from the enigma.py library.

      This run-file executes in 125ms.

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      --answer="ABCDEFGHIJ"
      
      "A + G = C"
      "B * J = FH"
      "GE * AI = HDB"
      

      Solution: There are two solutions: ABCDEFGHIJ = 1840253697, and ABCDEFGHIJ = 3840951627.

      The two solutions arise as we can swap the values of (A, E) with (G, I). One of them is (1, 2) and the other is (3, 9).

      Apparently the setter was unaware that there were two solutions, which seems a bit odd as this kind of puzzle can very easily be checked. For example my own alphametic solver is available here [ https://repl.it/@jim_r/alphametic ]. Click “Run”, enter the expressions, and you get the two solutions straight away. [Note: As of 2024 code sharing via replit no longer works].

      Here’s an example transcript:

      Python 3.6.1 (default, Dec 2015, 13:05:11)
      [GCC 4.8.2] on linux
      expr[0] (or enter) >>> A + G = C
      expr[1] (or enter) >>> B * J = FH
      expr[2] (or enter) >>> GE * AI = HDB
      expr[3] (or enter) >>>
      (A + G = C) (B * J = FH) (GE * AI = HDB)
      (1 + 3 = 4) (8 * 7 = 56) (32 * 19 = 608) / A=1 B=8 C=4 D=0 E=2 F=5 G=3 H=6 I=9 J=7
      (3 + 1 = 4) (8 * 7 = 56) (19 * 32 = 608) / A=3 B=8 C=4 D=0 E=9 F=5 G=1 H=6 I=2 J=7
      [2 solutions]
      [timing] elapsed time: 0.0016964s (1.70ms)
      

      The published solution is:

      Teaser 2938
      There were two possible correct answers: 1840253697 or 3840951627.
      We apologise for any confusion.

      Like

    • GeoffR's avatar

      GeoffR 1:20 pm on 8 March 2019 Permalink | Reply

      % A solution in MinZinc 
      include "globals.mzn";
      
      var 0..9: A; var 0..9: B; var 0..9: C; var 0..9: D; var 0..9: E;
      var 0..9: F; var 0..9: G; var 0..9: H; var 0..9: I; var 0..9: J;
      
      constraint A != 0 /\ G != 0 /\ C != 0 /\ B != 0 
      /\ J != 0 /\ F != 0 /\ H != 0;
      
      constraint all_different ( [A,B,C,D,E,F,G,H,I,J] );
      
      var 10..99: FH = 10*F + H;
      var 10..99: GE = 10*G + E;
      var 10..99: AI = 10*A + I;
      var 100..999: HDB = 100*H + 10*D + B;
      
      constraint A + G == C;
      constraint B * J == FH;
      constraint GE * AI = HDB;
      
      solve satisfy;
      
      output [ "ABCDEFGHIJ = " ++ show(A),show(B),show(C),show(D),show(E),
      show(F),show(G),show(H),show(I),show(J) ];
      
      % ABCDEFGHIJ = 3840951627
      % ABCDEFGHIJ = 1840253697
      
      

      Like

  • Unknown's avatar

    Jim Randell 7:19 am on 7 March 2019 Permalink | Reply
    Tags: by: Dr J A Anderson   

    Brain-Teaser 461: [Grovelball] 

    From The Sunday Times, 29th March 1970 [link]

    The finals of the Ruritanian grovelball championships have just taken place between the four leading teams, each team playing the other three.

    The Archers won the championships, scoring fourteen grovels to one against, while the Bakers scored eight and conceded five.

    The Cobblers, who scored four grovels, conceded the same number as the Donkey-drivers, who failed to score in any of their three games.

    In no game were fewer than three grovels scored, and there were only two games which resulted in the same score.

    What were the scores in the Archers v. Bakers and Archers v. Cobblers games?

    This puzzle was originally published with no title.

    [teaser461]

     
    • Jim Randell's avatar

      Jim Randell 7:22 am on 7 March 2019 Permalink | Reply

      We first note that C and D conceded the same number of goals, say x. And the sum of all the goals scored must be the same as the sum of all the goals conceded:

      14 + 8 + 4 + 0 = 1 + 5 + x + x
      2x = 20
      x = 10

      From there we can use the [[ Football() ]] helper class from the enigma.py library to consider this as a “substituted table” problem. We get a fairly short program, but not especially quick, but it finds the solution in 886ms.

      Run: [ @repl.it ]

      from enigma import Football, digit_map, ordered
      
      # scoring system (all games are played)
      football = Football(games="wdl")
      
      # digits stand for themselves, A=10, E=14
      d = digit_map(0, 14)
      
      # the table (mostly empty)
      (table, gf, ga) = (dict(played="3333", w="???0"), "E840", "15AA")
      
      # consider match outcomes
      for (ms, _) in football.substituted_table(table, d=d):
      
        # find possible scorelines from the goals for/against columns
        for ss in football.substituted_table_goals(gf, ga, ms, d=d):
      
          # additional restrictions:
          # "in no game were fewer than 3 goals scored"
          if any(sum(s) < 3 for s in ss.values()): continue
      
          # "only two games had the same score"
          # so there are 5 different scores involved
          if len(set(ordered(*s) for s in ss.values())) != 5: continue
      
          # output the matches
          football.output_matches(ms, ss, teams="ABCD")
      

      Solution: A vs B = 4-1; A vs C = 7-0.

      There is only one possible set of scorelines:

      A vs B = 4-1
      A vs C = 7-0
      A vs D = 3-0
      B vs C = 3-1
      B vs D = 4-0
      C vs D = 3-0

      So A has 3w, B has 2w+1d, C has 1w, D has 0w.

      Like

  • Unknown's avatar

    Jim Randell 8:16 am on 6 March 2019 Permalink | Reply
    Tags:   

    Teaser 2939: Betting to win 

    From The Sunday Times, 20th January 2019 [link] [link]

    Two teams, A and B, play each other.

    A bookmaker was giving odds of 8-5 on a win for team A, 6-5 on a win for team B and X-Y for a draw (odds of X-Y mean that if £Y is bet and the bet is successful then £(X + Y) is returned to the punter). I don’t remember the values of X and Y, but I know that they were whole numbers less than 20.

    Unusually, the bookmaker miscalculated! I found that I was able to make bets of whole numbers of pounds on all three results and guarantee a profit of precisely 1 pound.

    What were the odds for a draw, and how much did I bet on that result?

    [teaser2939]

     
    • Jim Randell's avatar

      Jim Randell 8:17 am on 6 March 2019 Permalink | Reply

      If the integer stakes are p for A to win, q for B to win, r for a draw, we have:

      (13/5)p = p + q + r + 1
      (11/5)q = p + q + r + 1
      ((X + Y)/Y)r = p + q + r + 1

      which, given X and Y, we can solve as:

      p = 55(X + Y) / (23X – 120Y)
      q = 65(X + Y) / (23X – 120Y)
      r = 143Y / (23X – 120Y)

      and we want these to be integers.

      X and Y are limited to be integers between 1 and 19, so we can easily check all possibilities.

      This Python program runs in 72ms.

      Run: [ @repl.it ]

      from itertools import product
      from enigma import (irange, printf)
      
      # consider possible values for X, Y
      for (X, Y) in product(irange(1, 19), repeat=2):
        # calculate integer stakes:
        # p (for A to win)
        # q (for B to win)
        # r (for a draw)
        d = 23 * X - 120 * Y
        if not (d > 0): continue
        (p, x) = divmod(55 * (X + Y), d)
        if x != 0: continue
        (q, x) = divmod(65 * (X + Y), d)
        if x != 0: continue
        (r, x) = divmod(143 * Y, d)
        if x != 0: continue
      
        # output solution
        printf("X={X} Y={Y}, p={p} q={q} r={r}")
      
        # verify the winnings
        w = p + q + r + 1
        assert divmod(13 * p, 5) == (w, 0)
        assert divmod(11 * q, 5) == (w, 0)
        assert divmod((X + Y) * r, Y) == (w, 0)
      

      Solution: The odds for a draw were 11-2. The bet on a draw was £22.

      A variation: If the bets can be whole numbers of pennies, instead of whole numbers of pounds, then there is another solution where X-Y is 10-1 and the bets are £5.50 on A to win, £6.50 for B to win, £1.30 on a draw. The winnings are £14.30 for a total outlay of £13.30.

      Like

    • GeoffR's avatar

      GeoffR 8:22 am on 7 March 2019 Permalink | Reply

      % A solution in MinZinc 
      var 1..19: X; var 1..19: Y;
      
      % Integer stakes are p for A to win, q for B to win, and r for a draw
      % For bets of p, q and r, a return of (p + q + r + 1) makes a profit of £1
      var 1..100: p; var 1..100: q; var 1..100: r;
      
      constraint 13 * p = (p + q + r + 1) * 5;        % 8-5 odds for team A
      constraint 11 * q = (p + q + r + 1) * 5;        % 6-5 odds for team B
      constraint (X + Y )* r = (p + q + r + 1) * Y;   % X-Y odds for a draw
      
      solve satisfy;
      
      % X = 11; Y = 2; p = 55; q = 65; r = 22;
      % ==========
      % Finished in 195msec 
      % Odds for a draw were 11/2 and the stake for a draw was £22
      
      

      Like

  • Unknown's avatar

    Jim Randell 11:16 am on 5 March 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 460: [Crates of Boppo] 

    From The Sunday Times, 22nd March 1970 [link]

    Boppo is made up in 1 lb cans at 8s, 2 lb cans at 15s and 4 lb cans at 27s. The contents of crates vary, but every crate contains 60 cans of mixed three sizes with a total value of £45.

    The foreman himself had packed two such crates. He told new worker Rob, “Just go along and nail down those two open crates in the shed, Rob. The lorry’s waiting.”

    Rob found the two crates standing beside the weighing platform, and for no particular reason he weighed them. One was heavier than the other. “Huh! Calls ‘isself a foreman” he said, as he removed some cans from the heavier crate. “That’s it. Both the same now. Lucky I weighed ’em”. So he nailed them down and the lorry went off with them.

    He met the foreman. “You made a mistake with those crates, chum”, he said, “but it’s OK now. Here’s three spare cans.”

    “!!” said the foreman.

    What were the weights of the two crates the foreman had packed?

    This puzzle was originally published with no title.

    [teaser460]

     
    • Jim Randell's avatar

      Jim Randell 11:19 am on 5 March 2019 Permalink | Reply

      Before decimalisation £1 was the same as 20 shillings, so each crate has a monetary value of 900 shillings.

      I solved this using a similar approach to Enigma 486 (and borrowed some of the code too).

      This Python 3 program runs in 108ms.

      from enigma import (defaultdict, irange, subsets, printf)
      
      # express total <t> using denominations <ds>, min quantity 1
      def express(t, ds, s=[]):
        if not ds:
          if t == 0:
            yield s
        else:
          (d, *ds) = ds
          for i in irange(1, t // d):
            yield from express(t - d * i, ds, s + [i])
      
      # the weights and costs of the cans
      weights = (1, 2, 4)
      costs = (8, 15, 27)
      
      # find ways to split the cost of a crate into cans
      crates = defaultdict(list)
      for ns in express(900, costs):
        # but each crate has 60 cans
        if not (sum(ns) == 60): continue
        # calculate the total weight of the crate
        t = sum(n * w for (n, w) in zip(ns, weights))
        printf("[{ns} -> weight = {t}]")
        crates[t].append(ns)
      
      # possible weights of 3 cans to be removed
      w3s = defaultdict(list)
      for rs in subsets(weights, size=3, select='R'):
        w3s[sum(rs)].append(rs)
      
      # find two crates with weights that differ by 3 cans
      for (w1, w2) in subsets(sorted(crates.keys()), size=2):
        for rs in w3s[w2 - w1]:
          # check there are enough cans in the w2 crate
          if not any(all(not (r > n) for (r, n) in zip(rs, ns)) for ns in crates[w2]): continue
          # output solution
          printf("{w2} lb -> {w1} lb by removing {rs} x {weights} lb cans")
      

      Solution: The crates the foreman had packed weighed 122 lb and 126 lb.

      Rob reduced the weight of the 126 lb crate to 122 lb by removing 2× 1 lb cans and 1× 2 lb can.

      There are only 3 ways to pack the crates so they have 60 cans and are worth 900 shillings (900s) (where the is at least 1 of each type of can included):

      12× 1 lb @ 8s + 41× 2 lb @ 15s + 7× 4 lb @ 27s = 60 cans, 122 lb, 900s
      24× 1 lb @ 8s + 22× 2 lb @ 15s + 14× 4 lb @ 27s = 60 cans, 124 lb, 900s
      36× 1 lb @ 8s + 3× 2 lb @ 15s + 21× 4 lb @ 27s = 60 cans, 126 lb, 900s

      If we don’t require that all three weights of can are represented in the crate then we can make a crate with 60× 2 lb cans, which weighs 120 lb, and gives rise to multiple solutions.

      Like

    • GeoffR's avatar

      GeoffR 7:42 am on 6 March 2019 Permalink | Reply

      The only 3 ways to pack a crate are found in my MiniZinc programme as 122 lb, 124 lb and 126 lb

      The only way of removing 3 cans to make the crates equal is to remove 3 cans ( 2 of 1lb and 1 of 2lb = 4lb) to reduce the crate weighing 126 ilb to 122 lb.

      Therefore, the foreman had packed 122 lb and 126 lb into the two crates.

      var 1..60: n1; var 1..60: n2;  var 1..60: n3;   % Numbers of  three types of can
      var 1..200: wt;   %total weight of all cans in 1 crate
      
      constraint n1 + n2 + n3 == 60;  % Every crate contains 60 cans
      constraint n1 * 8 + n2 * 15 + n3 * 27 == 900;   %sh £45 * 20 = 900 shillings for 1 crate
      constraint wt = n1 * 1 + n2 * 2 + n3 * 4;
      
      solve satisfy;
      
      % n1 = 12;  n2 = 41;  n3 = 7;  wt = 122;
      %----------
      % n1 = 24;  n2 = 22;  n3 = 14;  wt = 124;
      % ----------
      % n1 = 36;  n2 = 3;  n3 = 21;  wt = 126;
      %----------
      %==========
      %Finished in 199msec
      
      

      Like

  • Unknown's avatar

    Jim Randell 9:32 am on 4 March 2019 Permalink | Reply
    Tags: by: Arithmedicus,   

    Brain-Teaser 459: [Grandchildren] 

    From The Sunday Times, 8th March 1970 [link]

    Grandpa was as pleased as Punch when he heard that his large flock of grandchildren would be there at his birthday party, but he couldn’t remember how many there were. So he wrote to his youngest daughter, who knew he liked problems, and got back the answer:

    “There are just enough children to arrange them in pairs in such a way that the square of the age of the first of a pair added to thrice the square of the age of the second give the same total for every pair. The eldest is still a teenager. You remember that I have twins one year old.”

    How many grandchildren are there?

    This puzzle was originally published with no title.

    [teaser459]

     
    • Jim Randell's avatar

      Jim Randell 9:33 am on 4 March 2019 Permalink | Reply

      I think the wording of this puzzle could be improved. Saying there are “just enough” children sounds like we are looking for the minimum number of children to satisfy the conditions, given that there are two ages of 1 amongst the children, and one teenager. So we already have three values that must be used in the pairs. The smallest potential set would be two pairs, and this is achievable, giving an answer of 4 children.

      But it appears this is not the solution the setter had in mind. Instead it seems we want the largest possible number of children that can be formed into different pairs that give the same value for the function. If we were to allow duplicate pairs (i.e. pairs of children with the same ages in the same order), then we could increase the number of children to be as large as we want.

      Instead this program looks to group the ages of pairs of children into sets that give the same value for the function. We then need a set that has two 1’s and also value between 13 and 19. Then we look for the maximum number of different pairs of children possible, and this is the answer that was published.

      This Python program runs in 81ms.

      Run: [ @repl.it ]

      from enigma import (defaultdict, irange, subsets, printf)
      
      ages = set(irange(1, 19))
      
      # record the pairs by total
      d = defaultdict(list)
      
      # consider pairs of ages
      for (a, b) in subsets(ages, size=2, select='M'):
        n = a**2 + 3 * b**2
        d[n].append((a, b))
      
      # consider the values found
      for k in sorted(d.keys()):
        ps = d[k]
        # look for pairs where 1 occurs twice
        if not (sum(p.count(1) for p in ps) == 2): continue
        # and the eldest is a teenager
        if not (max(max(p) for p in ps) > 12): continue
        # output solution
        printf("{k} -> {ps}")
      

      Solution: There are 12 grandchildren.

      It turns out there is only one possible total that gives a viable set of pairs. The pairs are:

      (1, 11) (8, 10) (11, 9) (16, 6) (17, 5) (19, 1)

      Each giving the value of 364 when the function f(a, b) = a^2 + 3b^2 is applied to them.

      So there two 1 year olds (the twins) and also two 11 year olds.

      If we had four children of ages 1, 1, 11, 19, we would have “just enough” to form them into 2 pairs – (1, 11) and (19, 1) – that give the same value under the function, and there are two 1’s and a teenager involved. So this would be the answer if we take a strict interpretation of the wording.

      Similarly, if we allow duplication among the pairs we could have 14 children, or 16, etc.

      Like

      • Jim Randell's avatar

        Jim Randell 10:07 am on 4 March 2019 Permalink | Reply

        A variation would be to look for the largest number of children of different ages (apart from the twins) that can form the pairs.

        In this case we would have to discard the (11, 9) pair to leave:

        (1, 11) (8, 10) (16, 6) (17, 5) (19, 1)

        So there would be 10 children.

        Like

  • Unknown's avatar

    Jim Randell 7:12 am on 3 March 2019 Permalink | Reply
    Tags: ,   

    Teaser 2940: Getting there in the end 

    From The Sunday Times, 27th January 2019 [link]

    A tractor is ploughing a furrow in a straight line. It starts from rest and accelerates at a constant rate, taking a two-digit number of minutes to reach its maximum speed of a two-digit number of metres per minute. It has, so far, covered a three-digit number of metres. It now maintains that maximum speed for a further single-digit number of minutes and covers a further two-digit number of metres. It then decelerates to rest at the same rate as the acceleration. I have thus far mentioned ten digits and all of them are different.

    What is the total distance covered?

    As stated this puzzle does not have a unique solution.

    This puzzle was not included in the book The Sunday Times Teasers Book 1 (2021).

    [teaser2940]

     
    • Jim Randell's avatar

      Jim Randell 7:12 am on 3 March 2019 Permalink | Reply

      The tractor starts at rest:

      u = 0

      It then accelerates, at constant rate a, in time t1, to velocity v:

      v = a.t1
      a = v/t1

      During this period it has covered a distance d1:

      d1 = (1/2)a(t1^2) = v.t1/2

      It continues at a constant velocity v, for time t2, and covers distance d2:

      d2 = v.t2

      It then decelerates to rest, at a rate of −a, covering distance d1 again.

      The required answer being:

      d1 + d2 + d1 = v(t1 + t2)

      We can consider the alphametic expressions where:

      t1 = AB; v = CD; d1 = EFG; t2 = H; d2 = IJ

      This can be easily solved by the [[ SubstitutedExpression() ]] solver from the enigma.py library.

      This run-file executes in 126ms.

      Run: [ @repl.it ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      --answer="2 * EFG + IJ"
      
      "div(AB * CD, 2) = EFG"
      "CD * H = IJ"
      

      Solution: There are three possible total distances: 646m, 864m, 1316m.

      None of the solutions are particularly realistic. Each of them involve the tractor accelerating incredibly slowly for a very long time to reach an extremely modest top speed, and later take just as long to decelerate. Perhaps with a change of units the problem could made to apply to something that does take a long time to decelerate, like a train, oil tanker or spaceship.

      It would also have been easy to require just one of the possible answers, maybe by specifying the answer has 4 digits (1316m), or that all the digits are different (864m).


      The published solution is:

      Teaser 2940
      There were three possible correct answers.
      646, 864 or 1316m. We apologise for any confusion.

      Like

  • Unknown's avatar

    Jim Randell 8:54 am on 2 March 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 458: [Football tournament] 

    From The Sunday Times, 1st March 1970 [link]

    The table gives the results of an all-play-all soccer tournament is South America.

    If I tell you the number of scores of one goal by either side in the 3 games played by Brazil you can deduce the scores of the games between Argentine and Peru and Argentine and Ecuador.

    What are they?

    This puzzle was originally published with no title.

    [teaser458]

     
    • Jim Randell's avatar

      Jim Randell 8:55 am on 2 March 2019 Permalink | Reply

      The enigma.py library includes the [[ Football() ]] class to help in solving puzzles involving football tables, and the [[ filter_unique() ]] function to help in solving puzzles of the form “… if I told you this, then you could work out that…”. We can use both of these to solve this puzzle.

      This Python program runs in 98ms.

      Run: [ @repl.it ]

      from enigma import Football, filter_unique, unpack
      
      # record possible outcomes
      rs = list()
      
      # scoring system
      football = Football(games='wdl')
      
      # the order of the teams in the table
      (B, A, P, E) = (0, 1, 2, 3)
      
      # digits in the table stand for themselves
      d = dict((x, int(x)) for x in "01234789")
      
      # the columns of the table
      (table, gf, ga) = (dict(w="3100", d="0121", l="0112"), "9724", "3847")
      
      # find possible match outcomes
      for (ms, _) in football.substituted_table(table, d=d):
      
        # find possible scorelines using the goals for/against columns
        for ss in football.substituted_table_goals(gf, ga, ms, d=d):
      
          # record outcomes
          rs.append((ms, ss))
      
      # if I told you...
      # the number of scores of 1 goal by either side in the games played by B...
      f = unpack(lambda ms, ss: sum(v.count(1) for (k, v) in ss.items() if B in k))
      
      # you can deduce the scores in the AvP and AvE match
      g = unpack(lambda ms, ss: (ss[(A, P)], ss[(A, E)]))
      
      # find the unique solutions
      (rs, _) = filter_unique(rs, f, g)
      
      # output solutions
      for (ms, ss) in rs:
        football.output_matches(ms, ss, "BAPE")
      

      Solution: A vs P = 1-1. A vs E = 5-3.

      The scores in all matches are uniquely determined. They are:

      B vs A = 4-1
      B vs P = 3-1
      B vs E = 2-1
      A vs P = 1-1
      A vs E = 5-3
      P vs E = 0-0

      Like

  • Unknown's avatar

    Jim Randell 12:31 pm on 1 March 2019 Permalink | Reply
    Tags:   

    Teaser 2941: Big deal 

    From The Sunday Times, 3rd February 2019 [link] [link]

    My wife and I play bridge with Richard and Linda. The 52 cards are shared equally among the four of us – the order of cards within each player’s hand is irrelevant but it does matter which player gets which cards. Recently, seated in our fixed order around the table, we were discussing the number of different combinations of cards possible and we calculated that it is more than the number of seconds since the “big bang”!

    We also play another similar game with them, using a special pack with fewer cards than in the standard pack – again with each player getting a quarter of the cards. Linda calculated the number of possible combinations of the cards for this game and she noticed that it was equal to the number of seconds in a whole number of days.

    How many cards are there in our special pack?

    [teaser2941]

     
    • Jim Randell's avatar

      Jim Randell 12:32 pm on 1 March 2019 Permalink | Reply

      If there are k players, and each player receives n cards in the deal, then there are n.k cards in total.

      The number of ways of dealing n cards to the first player from the total set of n.k cards are:

      C(n.k, n) = (n.k)! / [ n! (n(k − 1))! ]

      For the second player there are only n(k − 1) cards remaining, and dealing n cards from that we get:

      C(n(k − 1), n) = (n(k − 1))! / [ n! (n(k − 2))! ]

      For the third player:

      C(n(k − 2), n) = (n(k − 2))! / [ n! (n(k − 3))! ]

      and so on up to the final player

      C(n, n) = n! / [ n! 0! ] = 1

      Multiplying all these together we find that one of the terms in the denominator cancels with the numerator for the next player, giving a total number of possible deals of:

      deals(k, n) = (n.k)! / (n!)^k

      We can use this rather neat formula to find the required number of cards in the puzzle.

      This Python program runs in 74ms.

      from enigma import (irange, inf, factorial, arg, printf)
      
      # number of players
      k = arg(4, 0, int, prompt="number of players")
      
      # multiple = number of seconds in a day (assumed constant)
      m = arg(60 * 60 * 24, 1, int, prompt="multiple")
      
      printf("[{k} players, m = {m}]")
      
      # number of cards per player
      for n in irange(1, inf):
        p = factorial(n * k) // pow(factorial(n), k)
        (d, r) = divmod(p, m)
        printf("{t} cards, {n} each, {p} deals, {d} days (+ {r}s)", t=n * k)
        if r == 0: break
      

      Solution: There are 28 cards in the special pack.

      Like

  • Unknown's avatar

    Jim Randell 2:05 pm on 28 February 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 457: [March-past] 

    From The Sunday Times, 15th February 1970 [link]

    The Duke of Teresa and Baron von Barin agreed to have a march-past of their respective men-at-arms to celebrate the wedding of the Duke’s son with Baron’s daughter. Each troop would march past in column of three (i.e. 3 men per file). The Duke has a few thousand men and the Baron about half as many.

    On the appointed day however, one of the Duke’s men could not go on parade and so the men were ordered into column of four, but 3 men were left over, whereupon they formed column of five and 4 men were left over, and this pattern of behaviour persisted as the Duke consecutively increased the number per file until all the men made an exact number of files.

    Meanwhile, the Baron has the same problem. One man reported sick and he consecutively increased the number per file and in column of four had 3 left over, column of five had 4 left over, etc., and eventually he reached a number per file that left no man spare.

    The Baron’s men proceeded to march past but the Duke was in a dilemma as each body of troops had a different number of men per file. He immediately solved this by ordering his men to form files with the same number of men as the Baron’s. This they did without any men being left over.

    How many men respectively had the Duke and the Baron on parade?

    This puzzle was originally published with no title.

    [teaser457]

     
    • Jim Randell's avatar

      Jim Randell 2:09 pm on 28 February 2019 Permalink | Reply

      The total number of men (including the indisposed man) must be able to form 3, 4, 5, … lines, if they are unable to form lines when one of them is missing, being short by one man.

      So, if we can form 3, 4, 5, … lines, the total number of men must be a multiple of 3, 4, 5, …, i.e. a multiple of lcm(3, 4, 5, …).

      This Python program looks for possible total numbers of men for the Duke D and the Baron B, and then finds the solution where the ratio D/B is closest to 2. I assumed the Duke had somewhere between 2,000 and 10,000 men. The program runs in 84ms.

      Run: [ @repl.it ]

      from itertools import count, combinations
      from collections import defaultdict
      from enigma import irange, mlcm, fdiv, Accumulator, printf
      
      # suppose the number of men (n - 1) end dividing into k equal sized lines (k > 6)
      # for all lowers numbers they are one short, so n must be a multiple of all lower numbers
      
      # minimum/maximum numbers to consider for D
      (m, M) = (2000, 10000)
      
      # record lcms up to M by k
      d = defaultdict(list)
      for k in count(7):
        n = mlcm(*irange(2, k - 1))
        if n > M: break
        d[k] = n
      
      # choose the result with D/B nearest to 2.0
      r = Accumulator(fn=(lambda x, y: (x if abs(x - 2.0) < abs(y - 2.0) else y)))
      
      # choose k's for D and B (kD < kB)
      for (kD, kB) in combinations(sorted(d.keys()), 2):
        (mD, mB) = (d[kD], d[kB])
        # the Duke has "a few thousand men"
        for D in irange(mD, M, step=mD):
          if D < m: continue
          # (D - 1) is divisible by kD and kB
          if not ((D - 1) % kD == 0 and (D - 1) % kB == 0): continue
          # the Baron "about half as many"
          for B in irange(mB, M, step=mB):
            # (B - 1) is divisible by kB
            if (B - 1) % kB != 0: continue
      
            # output the solution (the numbers on parade are B-1, D-1)
            r.accumulate_data(fdiv(D, B), (D - 1, B - 1))
            printf("kD={kD} kB={kB}, mD={mD} mB={mB}, D={D} B={B} [D/B ~ {f:.3f}]", f=fdiv(D, B))
      
      # output the solution
      (D, B) = r.data
      printf("parade: B={B}, D={D}")
      

      Solution: The Duke had 5159 men on parade. The Baron had 2519 men on parade.

      The ratio D/B is approximately 2.05.

      The Duke’s men are one man short of forming 3, 4, 5, 6 lines, but can form 7 lines (5159 = 737 × 7).

      The Baron’s men are one man short of forming 3, 4, 5, 6, 7, 8, 9, 10 lines, but can form 11 lines (2519 = 229 × 11).

      The Duke’s men can also form 11 lines (5159 = 469 × 11).

      There is a further solution where the Duke has 9779 men on parade (and the Baron still has 2519), but in this case the D/B ratio is 3.88.

      If we allow the Duke and the Baron more men then we can get the ratio closer to 2. There is a solution with D=60599 and B=30239, giving a ratio of 2.004, but it is hard to describe 60,600 men as “a few thousand”.

      Like

  • Unknown's avatar

    Jim Randell 1:55 pm on 27 February 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 456: [Chess competition] 

    From The Sunday Times, 8th February 1970 [link]

    The organiser of our lightning chess competition works on a strict timetable; he allows ten minutes a match, and makes no concession, in his planning, for draws or protracted games.

    Last year having five chess boards available for use, he arranged an American tournament (in which every competitor played one match against every other player). This year there would be exactly twice as many competitors as last year if one man hadn’t recently dropped out; and only one chessboard is available.

    He is therefore organising a knock-out competition: and he reports that his total time allocation will be precisely the same this year as it was last year.

    How many competitors are there this year?

    This puzzle was originally published with no title.

    [teaser456]

     
    • Jim Randell's avatar

      Jim Randell 1:56 pm on 27 February 2019 Permalink | Reply

      For n players there are T(n − 1) = n(n − 1)/2 matches in a tournament where every player plays every other player.

      So, with 5 simultaneous matches this would mean the number of allocated time slots would be:

      T = n(n − 1)/10

      In a knockout competition with m players there are (m − 1) games. (One player is eliminated in each game, until there is just one player left).

      So with only one match going on at a time, the total number of allocated time slots would be:

      T = m − 1

      And we are told that the number in the knockout tournament is m = 2n − 1.

      So, equating the times:

      m − 1 = n(n − 1)/10
      10(2n − 2) = n(n − 1)
      20(n − 1) = n(n − 1)
      n = 20 (as n ≠ 1)

      So last year there were 20 competitors. This year there are 39.

      Solution: This year there are 39 competitors.

      Liked by 1 person

  • Unknown's avatar

    Jim Randell 10:07 am on 26 February 2019 Permalink | Reply
    Tags: ,   

    Brain-Teaser 455: [Darts teams] 

    From The Sunday Times, 1st February 1970 [link]

    Every week we field a village darts team of 3 men, one from each of our pubs (Plough, Queen’s Head, and Roebuck). Altogether we can call on 14 players (whose names, luckily, start respectively with the first 14 letters of the alphabet): five of them frequent the Plough, six the Queen’s Head and seven the Roebuck, the apparent discrepancy is explained by the thirsts of Ernie, Fred, Len and Mark, all of whom are “two-pub men” and are thus eligible to represent either of their haunts.

    For over three years we have picked a different team each week and have just exhausted all 162 possible combinations. The last two teams were:

    Joe, Nigel, Charlie
    Charlie, Fred, Harry

    For the next seven weeks we are waiving the one-man-per-pub rule and have picked teams which have not so far played together. The are:

    Ernie, Len, Mark
    Ian, Fred, Alan
    Joe, Fred, George
    Len, Mark, Keith
    Fred, Keith, Nigel
    Ernie, Len, Nigel
    Ian, Joe, and one other to be picked from a hat on the night.

    Which darts players frequent the Roebuck?

    This puzzle was originally published with no title.

    [teaser455]

     
    • Jim Randell's avatar

      Jim Randell 10:07 am on 26 February 2019 Permalink | Reply

      I found two solutions for this puzzle, although with a slight change in the wording we could arrive at a unique solution.

      This Python program runs in 226ms.

      Run: [ @repl.it ]

      from itertools import product, permutations, combinations
      from enigma import icount, unpack, printf
      
      # all the players
      players = "ABCDEFGHIJKLMN"
      
      # players with dual allegiance
      duals = "EFLM"
      
      # the pubs
      pubs = set("PQR")
      
      # do the three sets form a team
      def team(a, b, c):
        for (x, y, z) in permutations(pubs):
          if x in a and y in b and z in c: return True
        return False
      
      # choose the "missing" pub for the duals
      for s1 in product(pubs, repeat=4):
        (E, F, L, M) = (pubs.difference([x]) for x in s1)
      
        # ELM do not form a team
        if team(E, L, M): continue
      
        # choose (single) pubs for K, N
        for s2 in product(pubs, repeat=2):
          (K, N) = (set([x]) for x in s2)
      
          # KLM, FKN, ELN do not form teams
          if team(K, L, M) or team(F, K, N) or team(E, L, N): continue
      
          # CJN do form a team
          for s3 in permutations(pubs.difference(N)):
            (C, J) = (set([x]) for x in s3)
      
            # remaining assignments for given combinations, AGHI
            for s4 in product(pubs, repeat=4):
              (A, G, H, I) = (set([x]) for x in s4)
      
              # check the remaining combinations
              if not (team(C, F, H)) or team(A, F, I) or team(F, G, J): continue
      
              # which leaves B and D
              for s5 in product(pubs, repeat=2):
                (B, D) = (set([x]) for x in s5)
      
                table = (A, B, C, D, E, F, G, H, I, J, K, L, M, N)
      
                # P, Q, R should have teams of 5, 6, 7
                (P, Q, R) = (icount(table, (lambda x: p in x)) for p in 'PQR')
                if (P, Q, R) != (5, 6, 7): continue
      
                # count the total possible teams
                t = icount(combinations(table, 3), unpack(team))
                # there should be 162
                if t != 162: continue
      
                # find how many unused IJ? combinations there are
                ijs = list(p for (p, x) in zip(players, table) if p not in 'IJ' and not team(I, J, x))
                # there should be at least 2
                if len(ijs) < 2: continue
      
                # who plays for R
                Rs = list(p for (p, x) in zip(players, table) if 'R' in x)
      
                printf("Rs = {Rs}")
                printf("  A={A} B={B} C={C} D={D} E={E} F={F} G={G} H={H} I={I} J={J} K={K} L={L} M={M} N={N}")
                printf("  ijs={ijs}")
                printf()
      

      Solution: A, B, D, F, G, I, J are on the Roebuck team.

      This solution assumes that the final team member of the I+J+? team that is picked out of the hat can be any of the other players (i.e. I and J have never played together on a team before).

      The team allegiances in this case are:

      P = C, E, F, L, M [5]
      Q = E, H, K, L, M, N [6]
      R = A, B, D, F, G, I, J [7]

      However, I took the construction of final I+J+? team by picking a name out of a hat to require only that there should be more than one candidate to placed in the hat. If we have the following team allegiances:

      P = E, F, J, L, M [5]
      Q = E, H, K, L, M, N [6]
      R = A, B, C, D, F, G, I [7]

      Then this is also a solution to the puzzle. In this case the remaining possible partners for I+J+? are: A, B, C, D, F, G.

      Like

  • Unknown's avatar

    Jim Randell 8:14 am on 25 February 2019 Permalink | Reply
    Tags:   

    Teaser 2945: Infernal indices 

    From The Sunday Times, 3rd March 2019 [link] [link]

     

    The above is the size of the evil multitude in the last “Infernal indices” novel: “A deficit of daemons”.

    Spoiler Alert: At the end, the forces of good engage in the fewest simultaneous battles that prevent this evil horde splitting, wholly, into equal-sized armies for that number of battles. The entire evil horde is split into one army per battle, all equally populated, bar one which has a deficit of daemons, leading to discord and a telling advantage for the forces of good.

    How many battles were there?

    [teaser2945]

     
    • Jim Randell's avatar

      Jim Randell 8:15 am on 25 February 2019 Permalink | Reply

      Although the given number (let’s call it N) is large (it is 36,306 decimal digits), it is not too large for Python to cope with.

      We need to find the smallest whole number n that does not divide N. This is a much smaller number.

      The following Python program runs in 107ms.

      Run: [ @replit ]

      from enigma import (irange, inf, printf)
      
      # construct the large number N
      x = 6**6
      N = (6**x) - (x**6)
      
      # find the smallest number that does not divide it
      for n in irange(2, inf):
        if N % n != 0:
          printf("n={n}")
          break
      

      Solution: There were 17 battles.

      (N mod 17) = 14, so the best the evil horde could manage would be 16 armies the same size and 1 army that had 3 fewer demons.

      Like

      • Jim Randell's avatar

        Jim Randell 4:46 pm on 2 March 2019 Permalink | Reply

        We can use the technique given in Enigma 1494 to compute the residues of large powers without the need to construct the huge numbers.

        The internal runtime for the following program is significantly less than the simple program given above (169µs vs. 961µs for the program given above). Although in practise both programs run instantaneously.

        from enigma import (irange, inf, printf)
        
        # compute a^b mod n
        def mpow(a, b, n):
          s = 1
          while b > 0:
            (b, r) = divmod(b, 2)
            if r > 0: s = (s * a) % n
            a = (a * a) % n
          return s
        
        # N = 6^x - x^6
        x = 6**6
        
        # find the smallest number that does not divide it
        for n in irange(2, inf):
          # find the residue N mod n
          if mpow(6, x, n) != mpow(x, 6, n):
            printf("n={n}")
            break
        

        Using the 3-argument version of the Python builtin [[ pow() ]] instead of [[ mpow() ]] gets the internal run time down to 40µs.


        For a manual solution we can use “the difference of two squares” method to express the number as:

        N = (6^36)(6^23310 − 1)(6^23310 + 1)

        From which it is easy to see that N will have a large number of factors of 2 and 3, and the fact that any power of 6 ends in a 6 means that the difference of two powers of 6 will end in a 0, so it will also be divisible by 5.

        So we can start by considering the primes: 7, 11, 13, 17, 19, 23 when looking for a suitable n.

        When evaluating mpow(6, x, n) the exponent can be reduced modulo (n − 1) (as n is prime) using Euler’s Theorem, and we can always evaluate the mpow(x, 6, n) in 3 iterations.

        In the end we don’t even need to consider all these primes in order to get the answer, so we can arrive at the solution with only a modest amount of calculation.

        Like

        • Jim Randell's avatar

          Jim Randell 12:14 pm on 3 March 2019 Permalink | Reply

          Here’s my complete manual solution:

          Writing:

          N = (6^36)(6^23310 − 1)(6^23310 + 1)

          We can start to examine divisors:

          For n = 2, it clearly divides the (6^36) term. Similarly for n = 3, 4, 6, 8, 9, 12, 16, ….

          For n = 5, it doesn’t divide the (6^36) term, so let’s consider the value of (6^23310 mod 5):

          5 is prime, so we can use Euler’s Theorem to reduce the exponent mod (p − 1):

          6^23310 mod 5 =
          6^(23310 mod (5 − 1)) mod 5 =
          6^2 mod 5 =
          36 mod 5 =
          1

          And if (6^23310 mod 5) = 1 then 5 divides the (6^23310 − 1) term.

          For n = 7, we consider the value of (6^23310 mod 7):

          6^23310 mod 7 =
          6^(23310 mod 6) mod 7 =
          6^0 mod 7 =
          1 mod 7 =
          1

          So 7 divides the (6^23310 − 1) term.

          For n = 10 we already know 2 divides the (6^36) term and 5 divides the (6^23310 − 1) term.

          For n = 11:

          6^23310 mod 11 =
          6^(23310 mod 10) mod 11 =
          6^0 mod 11 =
          1 mod 11 =
          1

          So 11 divides the (6^23310 − 1) term.

          For n = 13:

          6^23310 mod 13 =
          6^(23310 mod 12) mod 13 =
          6^6 mod 13 =
          12

          And 12 is equivalent to −1 mod 13, so 13 divides the (6^23310 + 1) term.

          For n = 14, we already have divisors of 2 and 7.

          For n = 15, we already have divisors of 3 and 5.

          for n = 17:

          6^23310 mod 17 =
          6^(23310 mod 16) mod 17 =
          6^14 mod 17 =
          (6^7 mod 17)^2 mod 17 =
          196 mod 17 =
          9

          9 is not equivalent to +1 or −1 mod 17, so 17 does not divide any of the terms, and gives our solution.

          Like

  • Unknown's avatar

    Jim Randell 7:39 am on 24 February 2019 Permalink | Reply
    Tags:   

    Teaser 2944: Happy families 

    From The Sunday Times, 24th February 2019 [link] [link]

    Teaser 2944

    Oliver lives with his parents, Mike and Nellie, at number 5. In each of numbers 1 to 4 lives a family, like his, with a mother, a father and one child. He tries listing the families in alphabetical order and produces the table above.

    However, apart from his own family, there is just one father, one mother and one child in the correct position. Neither Helen nor Beth lives at number 3 and neither Dave nor Ingrid lives at number 1. George’s house number is one less than Larry’s and Beth’s house number is one less than Carol’s. Apart from Oliver’s family, who are correctly positioned?

    [teaser2944]

     
    • Jim Randell's avatar

      Jim Randell 8:05 am on 24 February 2019 Permalink | Reply

      The wording of the puzzle is a little strange. I’m assuming the columns of the correct table are placed in order of house number (not “alphabetical” order), and the names of the fathers, mothers and children have been placed in the correct rows, just not necessarily in the correct columns. It seems like a reasonable assumption, and leads to a unique solution.

      I think I would have described the filling out of the original table like this:

      Oliver knows the names of the fathers, mothers and children, but is not sure who lives where, so he filled out each row in alphabetical order (from left to right), to give the table above. This correctly places his own family at house number 5. However …

      We can easily consider all the possibilities and eliminate those that do not satisfy the requirements.

      This Python program runs in 71ms.

      Run: [ @repl.it ]

      from itertools import permutations
      from enigma import printf
      
      # generate permutations that are only correct in 1 position
      def generate(vs, k=1):
        for s in permutations(vs):
          if sum(x == v for (x, v) in zip(s, vs)) == k:
            yield s
      
      # permute the Mums
      for mums in generate('BEHK'):
        (m1, m2, m3, m4) = mums
      
        # neither H or B live at number 3
        if m3 == 'H' or m3 == 'B': continue
      
        # permute the kids
        for kids in generate('CFIL'):
          (k1, k2, k3, k4) = kids
      
          # I does not live at number 1
          if k1 == 'I': continue
      
          # B's house number is 1 less than C's
          if not (mums.index('B') + 1 == kids.index('C')): continue
      
          # permute the dads
          for dads in generate('ADGJ'):
            (d1, d2, d3, d4) = dads
      
            # D does not live at 1
            if d1 == 'D': continue
      
            # G's house number is 1 less than L's
            if not (dads.index('G') + 1 == kids.index('L')): continue
      
            printf("1 = {d1}+{m1}+{k1}; 2 = {d2}+{m2}+{k2}; 3 = {d3}+{m3}+{k3}; 4 = {d4}+{m4}+{k4}")
      

      Solution: George, Kate and Larry were also correctly placed.

      Like

  • Unknown's avatar

    Jim Randell 10:31 pm on 21 February 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 454: Nine holes 

    From The Sunday Times, 25th January 1970 [link]

    The card of the course at Triangle Park Golf Club gives the total length of the first 9 holes as 3,360 yards. Par for the individual holes (numbers 1 to 9 respectively) being 5, 4, 5, 4, 3, 4, 4, 3, 5 (total 37).

    Closer inspection of the card would show that the lengths of the holes (each a whole number of yards) are such that holes 1, 2 and 3 could each form a different side of the same right-angled triangle (Triangle A) and that other right-angled triangles could similarly be formed from lengths equal to those of holes 4, 5 and 6 (Triangle B); 7, 8 and 9 (Triangle C); 1, 4 and 7 (Triangle X); 2, 5 and 8 (Triangle Y) and 3, 6 and 9 (Triangle Z).

    Moreover, the total length of the three holes forming Triangle A, the total length of the three holes forming Triangle B, and the total length of the three holes forming Triangle C could similarly form the three sides of another right-angled triangle (Triangle ABC) while yet another right-angled triangle could similarly be constructed from the total lengths of the holes forming triangles X, Y and Z (Triangle XYZ).

    In triangle ABC the sides would be in the ratio 5:3:4.

    The length of each of the par 3 holes is between 150 and 250 yards (one being 168 yards); the par 4 holes are between 250 and 450 yards; and the par 5 holes are between 475 and 600 yards (one being 476 yards).

    What are the lengths of holes 2, 6 and 7?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser454]

     
    • Jim Randell's avatar

      Jim Randell 10:33 pm on 21 February 2019 Permalink | Reply

      This Python program uses the [[ pythagorean_triples() ]] function from the enigma.py library to find appropriate triangles. (Originally written for Teaser 2910).

      Run: [ @replit ]

      from enigma import (defaultdict, pythagorean_triples, sq, printf)
      
      # par for distance x
      def par(x):
        if 149 < x < 251: return 3
        if 249 < x < 451: return 4
        if 474 < x < 601: return 5
      
      # find triangles in the appropriate classes
      ts = defaultdict(list)
      for t in pythagorean_triples(600):
        k = tuple(par(x) for x in t)
        if None not in k:
          ts[k].append(t)
      
      # select tuples from d[k] ordered by indices in ss
      def select(d, k, ss):
        for x in d[k]:
          for s in ss:
            yield tuple(x[i] for i in s)
      
      # does (x, y, z) form a right-angled triangle
      def is_triangle(x, y, z):
        return sq(x) + sq(y) + sq(z) == 2 * sq(max(x, y, z))
      
      
      # choose triangle A (5, 4, 5)
      for (d1, d2, d3) in select(ts, (4, 5, 5), [(1, 0, 2), (2, 0, 1)]):
      
        # choose triangle B (4, 3, 4)
        for (d4, d5, d6) in select(ts, (3, 4, 4), [(1, 0, 2), (2, 0, 1)]):
      
          # choose triangle C (4, 3, 5)
          for (d7, d8, d9) in select(ts, (3, 4, 5), [(1, 0, 2)]):
      
            # check the total distance
            if not (sum((d1, d2, d3, d4, d5, d6, d7, d8, d9)) == 3360): continue      
      
            # check the other triangles
            (X, Y, Z) = ((d1, d4, d7), (d2, d5, d8), (d3, d6, d9))
            ABC = (d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9)
            XYZ = (d1 + d4 + d7, d2 + d5 + d8, d3 + d6 + d9)
            if not all(is_triangle(*t) for t in (X, Y, Z, ABC, XYZ)): continue
      
            # check ABC is a 3, 4, 5 triangle
            if not (5 * min(ABC) == 3 * max(ABC)): continue
      
            # check the given pars
            if not (168 in (d5, d8) and 476 in (d1, d3, d9)): continue
      
            printf("d1={d1} d2={d2} d3={d3} / d4={d4} d5={d5} d6={d6} / d7={d7} d8={d8} d9={d9}")
      

      Solution: Hole 2 is 280 yards. Hole 6 is 357 yards. Hole 7 is 420 yards.

      There is only one solution:

      Hole 1 = 525 yards
      Hole 2 = 280 yards
      Hole 3 = 595 yards
      Hole 4 = 315 yards
      Hole 5 = 168 yards
      Hole 6 = 357 yards
      Hole 7 = 420 yards
      Hole 8 = 224 yards
      Hole 9 = 476 yards

      In fact if the triangle constraints for A, B, C, X, Y, Z, ABC, XYZ are satisfied, there is only a single solution even if the conditions for the total distance, ratios for ABC, and the specific distances for par 3 and 5 are ignored (lines 38, 47, 50).

      Like

      • Jim Randell's avatar

        Jim Randell 9:53 am on 23 February 2019 Permalink | Reply

        This puzzle is a good candidate for solving with a declarative set of constraints.

        Here is a MiniZinc model, that is run via the minizinc.py module. It solves the puzzle in 93ms.

        %#! python3 -m minizinc use_embed=1
        
        % hole distances
        {var("150..250", ["d5", "d8"])};  % par 3
        {var("250..450", ["d2", "d4", "d6", "d7"])};  % par 4
        {var("475..600", ["d1", "d3", "d9"])};  % par 5
        
        % total distance
        constraint d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 = 3360;
        
        % right angled triangle constraints
        predicate is_triangle(var int: a, var int: b, var int: c) =
          pow(a, 2) + pow(b, 2) + pow(c, 2) = pow(max([a, b, c]), 2) * 2;
        
        constraint is_triangle(d1, d2, d3); % triangle A
        constraint is_triangle(d4, d5, d6); % triangle B
        constraint is_triangle(d7, d8, d9); % triangle C
        
        constraint is_triangle(d1, d4, d7); % triangle X
        constraint is_triangle(d2, d5, d8); % triangle Y
        constraint is_triangle(d3, d6, d9); % triangle Z
        
        constraint is_triangle(d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9); % triangle ABC
        constraint is_triangle(d1 + d4 + d7, d2 + d5 + d8, d3 + d6 + d9); % triangle XYZ
        
        % ABC is a 3, 4, 5 triangle
        constraint 5 * min([d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9]) = 3 * max([d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9]);
        
        % some lengths are given
        constraint d5 = 168 \/ d8 = 168;  % par 3
        constraint d1 = 476 \/ d3 = 476 \/ d9 = 476;  % par 5
        
        solve satisfy;
        

        Like

    • GeoffR's avatar

      GeoffR 11:07 am on 23 February 2019 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
      
      % The nine holes are H1..H9 with Par distances as below:
      var 475..600: H1; var 250..450: H2; var 475..600: H3; % Par 5, 4, 5
      
      var 250..450: H4; var 150..250: H5; var 250..450: H6; % Par 4, 3, 4
      
      var 250..450: H7; var 150..250: H8; var 475..600: H9; % Par 4, 3, 5
      
      % Given hole distances
      constraint H5 == 168 \/ H8 == 168;
      constraint H1 == 476 \/ H3 == 476 \/ H9 == 476;
      
      % Total distance for all holes
      constraint H1 + H2 + H3 + H4 + H5 + H6 + H7 + H8 + H9 == 3360;
      
      % Triangle A - H1 and H3 are both Par 5
      constraint (H2 * H2 + H3 * H3 == H1 * H1) \/(H2 * H2 + H1 * H1 == H3 * H3);
      
      % Triangle B - H4 and H6 are both Par 4
      constraint( H5 * H5 + H6 * H6 == H4 * H4) \/ (H5 * H5 + H4 * H4 == H6 * H6);
      
      % Triangle C - H9 is higher Par than H7 or H8
      constraint (H7 * H7 + H8 * H8 == H9 * H9);
      
      % % Triangle X - H1 is higher Par than H4 or H7
      constraint H4 * H4 + H7 * H7 == H1 * H1;
      
      % % Triangle Y - H2 is higher Par than H5 and H8
      constraint (H8 * H8 + H5 * H5 = H2 * H2); 
      
      % % Triangle Z - H3 and H9 are both Par 5
      constraint (H6 * H6 + H9 * H9 == H3 * H3)\/ (H3 * H3 + H6 * H6 == H9 * H9);
      
      % Triangle ABC sides
      var 500..2000: A1;
      var 500..2000: B1;
      var 500..2000: C1;
      
      constraint A1 = H1 + H2 + H3;
      constraint B1 = H4 + H5 + H6;
      constraint C1 = H7 + H8 + H9;
      
      % Sides are in ratio 5:4:3
      constraint A1 mod 5 == 0 \/ B1 mod  5 == 0 \/ C1 mod 5 == 0;
      constraint A1 mod 4 == 0 \/ B1 mod  4 == 0 \/ C1 mod 4 == 0;
      constraint A1 mod 3 == 0 \/ B1 mod  3 == 0 \/ C1 mod 3 == 0;
      
      constraint (A1 * A1 + B1 * B1 == C1 * C1)
      \/ (A1 * A1 + C1 * C1 == B1 * B1)
      \/ (B1 * B1 + C1 * C1 == A1 * A1);
      
      % Triangle XYZ sides
      var 500..4000: X1;
      var 500..4000: Y1;
      var 500..4000: Z1;
      
      constraint X1 = H1 + H4 + H7;
      constraint Y1 = H2 + H5 + H8;
      constraint Z1 = H3 + H6 + H9;
      
      constraint (X1 * X1 + Y1 * Y1 == Z1 * Z1)
      \/ (X1 * X1 + Z1 * Z1 == Y1 * Y1)
      \/ (Y1 * Y1 + Z1 * Z1 == X1 * X1);
      
      solve satisfy;
      
      % H1 = 525; H2 = 280; H3 = 595;  Holes H1..H9 lengths (yd)
      % H4 = 315; H5 = 168; H6 = 357;
      % H7 = 420; H8 = 224; H9 = 476;
      % Solution: H2 = 280, H6 = 357, H7 = 420
       
      % A1 = 1400; B1 = 840; C1 = 1120;  Triangle ABC sides
      % X1 = 1260; Y1 = 672; Z1 = 1428;  Triangle XYZ sides
      % ----------
      % ==========
      % Finished in 237msec
      
      

      Like

  • Unknown's avatar

    Jim Randell 3:06 pm on 21 February 2019 Permalink | Reply
    Tags:   

    Teaser 2910: Living on the coast 

    From The Sunday Times, 1st July 2018 [link] [link]

    George and Martha are living on Pythag Island. Not surprisingly, it is in the shape of a right-angled triangle, and each side is an integral number of miles (under one hundred) long. Martha noticed that the area of the island (expressed in square miles) was equal to an exact multiple of its perimeter (expressed in miles). George was trying to work out that multiple, but gave up: “Please write down the appropriate digit” he said. “Impossible!” said Martha.

    What are the lengths of the coasts?

    [teaser2910]

     
    • Jim Randell's avatar

      Jim Randell 3:07 pm on 21 February 2019 Permalink | Reply

      Suppose the triangle has sides x, y, z where 0 < x < y < z < 100.

      We have:

      x² + y² = z²

      area = A = xy/2
      perimeter = P = x + y + z

      ratio = k = A/P = xy/2(x + y + z)

      Consider:

      (x + y + z)(x + y − z) = (x² + y² − z²) + 2xy = 2xy
      ⇒ xy = (x + y + z)(x + y − z)/2

      So:

      k = (x + y + z)(x + y − z)/4(x + y + z) = (x + y − z)/4

      This Python program uses the [[ pythagorean_triples() ]] function from the enigma.py library to find appropriate triangles. The routine itself uses the technique described at [ @Wikipedia ]. It runs in 71ms.

      Run: [ @repl.it ]

      from enigma import (pythagorean_triples, div, printf)
      
      # consider all pythagorean triples with hypotenuse less than 100
      for (x, y, z) in pythagorean_triples(99):
        # find ratio of area to perimeter, an integer with more than 1 digit
        k = div(x + y - z, 4)
        if k is None or k < 10: continue
        # output solution
        printf("x={x} y={y} z={z}, k={k}")
      

      Solution: The lengths of the coasts (in miles) are 65, 72, 97.

      Like

    • GeoffR's avatar

      GeoffR 1:26 pm on 22 February 2019 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
      
      var 1..99:X; var 1..99:Y; var 1..99:Z;  % 3 sides of triangle
      constraint X < Y /\ Y < Z;
      
      var 1..5000: area;
      var 3..297: perim;
      var 2..50:ratio;
      
      constraint X * X + Y * Y == Z * Z;
      constraint area = (X * Y) div 2;
      constraint perim = X + Y + Z;
      
      constraint ratio = area/perim /\ ratio > 9;  % Single digit ratio is impossible (Martha)
      
      solve satisfy;
      
      % X = 65;  Y = 72; Z = 97;
      % area = 2340; perim = 234; ratio = 10;
      % ----------
      % ==========
      % Finished in 267msec
      

      Like

  • Unknown's avatar

    Jim Randell 8:23 am on 19 February 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 453: [Square field] 

    From The Sunday Times, 18th January 1970 [link]

    Old Hassan has been at it again! He has thought of a new way of parcelling out his square field between his three sons (Rashid and Riad the twins, and Ali).

    Calling the three into his tent on the eve of Ramadhan, he addressed them thus:

    “My sons, as I am now 74 years of age, I desire that you shall come into part of your inheritance. I have therefore divided my field into four triangular plots such that we each have an area proportional to our age.”

    “To avoid any friction regarding upkeep of fences I have also arranged that none of you shall have a common boundary line with either of your brothers. Further, knowing Rashid and Riad’s objection to being too strongly identified with each other, I have arranged for their plots to be of a different shape.”

    The twins are 11 years older than Ali.

    How old is Ali?

    This puzzle was originally published with no title.

    [teaser453]

     
    • Jim Randell's avatar

      Jim Randell 8:40 am on 19 February 2019 Permalink | Reply

      Let’s suppose that the field is a unit square, and that Ali’s age is a (a whole number).

      Then the total of all the ages is d = a + 2(a + 11) + 74 = 3a + 96, so the corresponding areas of the triangular plots are:

      Hassan = 74 / d
      Rashid, Riad = (a + 11) / d
      Ali = a / d

      Splitting two sides of the square at x, y ∈ (0, 1) we have:

      For Rashid and Riad:

      (a + 11) / d = x / 2
      (a + 11) / d = (1 − x)(1 − y) / 2

      and for Ali:

      a / d = y / 2

      So, given a value for a we have:

      d = 3a + 96
      x = 2(a + 11) / d
      y = 2a / d
      (1 − x)(1 − y) = x

      So we can consider whole number values for a that give a solution to these equations:

      from enigma import (Rational, irange, printf)
      
      Q = Rational()
      
      # choose a value for a
      for a in irange(1, 50):
        # total age
        d = 3 * a + 96
        # calculate x and y
        (x, y) = (Q(2 * a + 22, d), Q(2 * a, d))
        # do they satisfy the third equation?
        if x == (1 - x) * (1 - y):
          printf("a={a} [x={x}, y={y}]")
      

      Solution: Ali is 24.

      A viable solution to the equations is:

      a = 24, x = 5/12, y = 2/7

      so the fields look like this:

      Hassan has 37/84 (≈ 44.1%) of the field. The twins have 5/24 (≈ 20.8%) each. And Ali has the remaining 1/7 (≈ 14.3%).

      There is a further solution to the equations at:

      a = −208/5, x = 17/8, y = 26/9

      but this doesn’t give a viable answer.

      Like

    • John Crabtree's avatar

      John Crabtree 4:24 pm on 16 April 2021 Permalink | Reply

      The four equations involving a, d, x and y can be reduced to:
      5a^2 + 88a -4992 = 0. Then a = -8.8 +/- 32.8

      Like

  • Unknown's avatar

    Jim Randell 8:25 am on 17 February 2019 Permalink | Reply
    Tags:   

    Teaser 2943: Keep your balance 

    From The Sunday Times, 17th February 2019 [link] [link]

    George and Martha have a set of a dozen balls, identical in appearance but each has been assigned a letter of the alphabet, A, B, …, K, L and each is made of a material of varying density so that their weights in pounds are 1, 2…. 11, 12 but in no particular order. They have a balance and the following weighings were conducted:

    (1) {A, C, I} vs {G, J, L}

    (2) {A, H, L} vs {G, I, K}

    (3) {B, I, J} vs {C, F, G}

    (4) {B, D, I} vs {E, G, H}

    (5) {D, F, L} vs {E, G, K}

    On all five occasions, there was perfect balance and the total of the threesome in each was a different prime number, that in (1) being the smallest and progressing to that in (5) which was the largest.

    In alphabetical order, what were the weights of each of the twelve balls?

    [teaser2943]

     
    • Jim Randell's avatar

      Jim Randell 8:38 am on 17 February 2019 Permalink | Reply

      We can solve this using the [[ SubstitutedExpression() ]] solver from the enigma.py library. Treating each symbol as standing for a different non-zero base 13 digit.

      This run-file executes in 332ms.

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      --base="13"
      --digits="1-12"
      
      --template=""
      
      # the weighings
      "A + C + I == G + J + L"
      "A + H + L == G + I + K"
      "B + I + J == C + F + G"
      "B + D + I == E + G + H"
      "D + F + L == E + G + K"
      
      # the total weights are prime
      "is_prime(A + C + I)"
      "is_prime(A + H + L)"
      "is_prime(B + I + J)"
      "is_prime(B + D + I)"
      "is_prime(D + F + L)"
      
      # the primes are in increasing order
      "A + C + I < A + H + L"
      "A + H + L < B + I + J"
      "B + I + J < B + D + I"
      "B + D + I < D + F + L"
      

      Solution: The weights of the balls are: A=4, B=8, C=5, D=9, E=12, F=11, G=1, H=6, I=2, J=7, K=10, L=3.

      Like

    • Jim Randell's avatar

      Jim Randell 10:19 am on 17 February 2019 Permalink | Reply

      There are six symbols in the first weighing, and together they must sum to twice the smallest prime, so the smallest possible value for the smallest prime is:

      divc(1 + 2 + 3 + 4 + 5 + 6, 2) = 11

      Similarly the largest possible value for the largest prime is:

      divf(7 + 8 + 9 + 10 + 11 + 12, 2) = 28

      So the list of possible primes is: 11, 13, 17, 19, 23.

      There are only 5 primes on the list, so the weighings give us 10 equations in 12 variables.

      Again using the [[ SubstitutedExpression() ]] solver, this run file executes in 131ms.

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      --base="13"
      --digits="1-12"
      --template=""
      
      # the weighings
      "A + C + I == 11"
      "G + J + L == 11"
      "A + H + L == 13"
      "G + I + K == 13"
      "B + I + J == 17"
      "C + F + G == 17"
      "B + D + I == 19"
      "E + G + H == 19"
      "D + F + L == 23"
      "E + G + K == 23"
      

      Like

      • Jim Randell's avatar

        Jim Randell 7:30 am on 5 March 2019 Permalink | Reply

        Here’s a manual solution:

        Given the 10 equations above and adding the equation:

        A + B + C + D + E + F + G + H + I + J + K + L = 78

        Gives us 11 equations in 12 variables.

        These can be solved to give the other values in terms of B:

        A = 44 − 5B
        C = 4B − 27
        D = 25 − 2B
        E = B + 4
        F = 27 − 2B
        G = 17 − 2B
        H = B − 2
        I = B − 6
        J = 23 − 2B
        K = B + 2
        L = 4B − 29

        And all the variables have to take on different values from 1 to 12.

        From I and E, we have:

        B ≥ 7
        B ≤ 8

        So B is 7 or 8.

        The formula for F gives:

        B = 7 → F = 13
        B = 8 → F = 11

        The first of these is not possible so B = 8, giving:

        A = 4; B = 8; C = 5; D = 9; E = 12; F = 11; G = 1; H = 6; I = 2; J = 7; K = 10; L = 3

        Like

        • Frits's avatar

          Frits 3:43 pm on 30 July 2020 Permalink | Reply

          @Jim

          “These can be solved to give the other values in terms of B:” –> easier said than done.

          Can your Enigma functions generate these 11 equations in terms of B?

          Like

          • Jim Randell's avatar

            Jim Randell 5:03 pm on 30 July 2020 Permalink | Reply

            You could use SymPy to reduce the set of equations down using a single parameter.

            But you can also choose a value for B and then you have 12 equations in 12 variables, which you can solve using the [[ Matrix.linear() ]] solver in enigma.py.

            Run: [ @replit ]

            from enigma import (Matrix, irange, join, printf)
            
            eqs = [
              # A  B  C  D  E  F  G  H  I  J  K  L
              ( 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), # B = ?
              ( 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 ), # (A, C, I) = 11
              ( 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 ), # (G, J, L) = 11
              ( 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 ), # (A, H, L) = 13
              ( 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ), # (G, I, K) = 13
              ( 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ), # (B, I, J) = 17
              ( 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0 ), # (C, F, G) = 17
              ( 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0 ), # (B, D, I) = 19
              ( 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 ), # (E, G, H) = 19
              ( 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 ), # (D, F, L) = 23
              ( 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0 ), # (E, G, K) = 23
              ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ), # (A ... L) = 78
            ]
            
            # the collection of weights
            weights = set(irange(1, 12))
            
            # choose a value for B
            for B in weights:
              # evaluate the equations
              s = Matrix.linear(eqs, [B, 11, 11, 13, 13, 17, 17, 19, 19, 23, 23, 78])
              # the answers should be the values in weights
              if not (set(s) == weights): continue
              # output solution
              printf("{s}", s=join((join((w, '=', v)) for (w, v) in zip("ABCDEFGHIJKL", s)), sep=" "))
            

            Like

            • Frits's avatar

              Frits 8:27 pm on 30 July 2020 Permalink | Reply

              Thanks, I ran the following code at [ https://live.sympy.org/ ]:

              from sympy import linsolve, symbols, linear_eq_to_matrix
              A,B,C,D,E,F,G,H,I,J,K,L = symbols("A,B,C,D,E,F,G,H,I,J,K,L", integer=True)
              variables = [A,C,D,E,F,G,H,I,J,K,L,B]
              
              def my_solver(known_vals):
              
                  eqns = [A + C + I - 11,
              G + J + L - 11,
              A + H + L - 13,
              G + I + K - 13,
              B + I + J - 17,
              C + F + G - 17,
              B + D + I - 19,
              E + G + H - 19,
              D + F + L - 23,
              E + G + K - 23,
              A + B + C + D + E + F + G + H + I + J + K + L - 78]
              
                  # add the known variables to equation list
                  for x in known_vals.keys():
                      eqns.append(x - (known_vals[x]))
              
                  X, b = linear_eq_to_matrix(eqns, variables)
                  solution = linsolve((X, b), variables)
              
                  return solution
              
              
              my_solver({})
              

              Output:

              {(44−5B, 4B−27, 25−2B, B+4, 27−2B, 17−2B, B−2, B−6, 23−2B, B+2, 4B−29, B)}

              Like

    • GeoffR's avatar

      GeoffR 3:38 pm on 19 February 2019 Permalink | Reply

      I assumed you did not want the answer shown?

      % A Solution in MiniZinc
      include "globals.mzn";
      
      % The dozen balls weigh between 1 and 12 pounds
      var 1..12:A; var 1..12:B; var 1..12:C; var 1..12:D; var 1..12:E;
      var 1..12:F; var 1..12:G; var 1..12:H; var 1..12:I; var 1..12:J;
      var 1..12:K; var 1..12:L;
      
      % All the balls A..K are of different weight
      constraint all_different([A, B, C, D, E, F, G, H, I, J, K, L]);
      
      predicate is_prime(var int: x) = 
      x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) ((i < x) -> (x mod i > 0));
      
      % The weighing equations
      constraint (A + C + I == G + J + L) 
      /\ (A + H + L == G + I + K)
      /\ (B + I + J == C + F + G) 
      /\ (B + D + I == E + G + H)
      /\ (D + F + L == E + G + K);
      
      % the total weights in the equations are all prime numbers
      constraint is_prime(A + C + I) /\ is_prime(A + H + L) /\ is_prime(B + I + J) 
      /\ is_prime(B + D + I) /\ is_prime(D + F + L);
      
      % The five primes are in increasing order
      constraint (A + C + I) < (A + H + L) /\  (A + H + L) < (B + I + J)
      /\ (B + I + J) < (B + D + I) /\  (B + D + I) < (D + F + L);
      
      solve satisfy;
      
      output [ " A = "++ show(A) ++ ", B = " ++ show(B) ++ ", C = " ++ show(C) ++ "\n"
      ++ " D = " ++ show(D) ++ ", E = " ++ show(E) ++ ", F = " ++ show(F) ++ "\n"
      ++ " G = " ++ show(G) ++ ", H = " ++ show(H) ++ ", I = " ++ show(I) ++ "\n"
      ++ " J = " ++ show(J) ++ ", K = " ++ show(K) ++ ", L = " ++ show(L) ];
      
      
      

      Like

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
Design a site like this with WordPress.com
Get started