Enigmatic Code

Programming Enigma Puzzles

Tantalizer 334: Tell us another one

From New Scientist #885, 14th February 1974 [link]

Aunt Agatha’s three daughters are an argumentative lot and it is no surprise to find them all working for different political parties. They are too young for front-line stuff so they all sit outside the only polling station in their ward and write down the voters’ polling numbers on special pads. the polling numbers start at one, there are no postal voters and last time, incredible to relate, there was 100 per cent poll.

“Phew!” exclaimed Prissy for the Liberals, “I wrote down 3967 digits in all”.

“I knew you wouldn’t get it right”, retorted Emily, who is Labour. “I wrote down 3961 digits”.

“More fool you”, remarked Tory Tania, “the right tally is 3971”.

It does the girls credit that one of them not only recorded the polling numbers with complete accuracy but also added up the number of digits in them right.

How many electors are there in the ward?

[tantalizer334]

One response to “Tantalizer 334: Tell us another one

  1. Jim Randell 27 October 2021 at 9:53 am

    We can easily write a constructive solution that just counts the digits.

    This Python 3.10 program uses structural pattern matching to identify the solution. It runs in 59ms.

    Run: [ @replit ] (Python <3.10 version)

    from enigma import irange, inf, ndigits, printf
    
    # count the total number of digits
    t = 0
    for n in irange(1, inf):
      t += ndigits(n)
    
      # look for solutions
      match t:
        case 3967 | 3961 | 3971:
          # one of the girls got a correct figure
          printf("n={n} -> t={t}")
        case x if x > 3971:
          # we are done
          break
    

    Solution: There are 1267 voters.


    Manually:

    There are 9 1-digit voters (1-9) = 9 digits

    There are 90 2-digit voters (10-99) = 180 digits [189 digits in total]

    There are 900 3-digit voters (100-999) = 2700 digits [2889 digits in total]

    There are 9000 4-digit voters (1000-9999) = 36000 digits [38889 digits in total]

    (In general there are 9×10^(k – 1) k-digit voters, giving a total of 9k×10^(k – 1) digits).

    So the number of voters is 4-digits. We just need to work out how many 4-digit voters there are:

    3967 – 2889 = 1078 [not a multiple of 4]
    3961 – 2889 = 1072 = 4 × 268
    3971 – 2889 = 1082 [not a multiple of 4]

    So there are 268 4-digit votes, and the correct total is 3961 (Emily).

    The total number of voters is: 9 + 90 + 900 + 268 = 1267.

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 )

Google photo

You are commenting using your Google 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: