Enigmatic Code

Programming Enigma Puzzles

Enigma 531: Petits fours

From New Scientist #1683, 23rd September 1989 [link]

“Four-armed is four-warmed,” declared Professor Törqui as he placed the petits fours in the oven in his lab at the Department of Immaterial Science and Unclear Physics. “There are 4444 of them: a string of 4s. By which I mean, naturally enough, a number in base 10 all of whose digits are 4. Do you like my plus fours? [*] Speaking of 10s and plus fours, you can hardly be unaware of the fact that all positive integral powers of 10 (except 10¹, poor thing) are expressible as sums of strings of 4s.”

“The most economical way of expressing 10² as a sum of strings of 4s (that is, the one using fewest strings and hence fewest 4s) uses seven 4s:”

10² = 44 + 44 + 4 + 4 + 4.

“The most economical means of expressing 10³ as a sum of strings of 4s requires sixteen 4s:”

10³ = 444 + 444 + 44 + 44 + 4 + 4 + 4 + 4 + 4 + 4.

“Now, it’s four o’clock, and just time for this puzzle: Give me somewhere to put my cakestand and I will make a number of petits fours which is an integral positive power of 10 such that the number of 4s required to write it as a sum of strings of 4s in the most economical way is itself a string of 4s.”

What is the smallest number of petits fours Törqui’s boast would commit him to baking? (Express your answer as a power of 10.)

[*] £44.44 from Whatsit Forum.

[enigma531]

2 responses to “Enigma 531: Petits fours

  1. Jim Randell 23 December 2019 at 7:23 am

    We can denote a repdigit consisting of n repeats of the digit 4 as: 4[n].

    Now, if we consider a power of 10, say 10^k (for sufficiently large k).

    Then we can subtract the repdigit 4[k] from it twice, leaving: 11…12 (with (k – 1) 1’s).

    From this we can subtract the repdigit 4[k – 1] twice, leaving: 22…224 (with (k – 2) 2’s).

    From this we can subtract the repdigit 4[k – 2] five times, leaving 4.

    So we get:

    10^k = 2×4[k] + 2×4[k – 1] + 5×4[k – 2] + 4

    The number of times the digit 4 is used is thus:

    2k + 2(k – 1) + 5(k – 2) + 1 = 9k – 11

    And we see that 10² requires 9×2 – 11 = 7 digits and 10³ requires 9×3 – 11 = 16 digits, as given in the puzzle text.

    So we need to find when (9k – 11) is a repdigit composed entirely of 4’s.

    4[2] + 11 = 55, is not divisible by 9
    4[3] + 11 = 455, is not divisible by 9
    4[4] + 11 = 4455 = 9×495

    Hence 10^495 can be expressed using 4444 copies of the digit 4.

    Run: [ @repl.it ]

    from enigma import irange, inf, repdigit, div, printf
    
    # consider increasing repdigits
    for k in irange(2, inf):
      r = repdigit(k, 4)
      n = div(r + 11, 9)
      if n is not None:
        printf("10^{n} = {r} digits")
        break
    

    Solution: The smallest possible number is 10^495.

    This is an infeasibly large number of cakes to bake.


    We can see that the repdigits of 4, plus eleven are:

    4[k] + 11 = 44…4455 (with (k – 2) 4’s)

    The number will be divisible by 9 if the sum of its digits is:

    4(k – 2) + 10

    Which is divisible by 9 if:

    4(k – 2) = 8 (mod 9)

    So:

    k – 2 = 2 (mod 9)
    k = 4, 13, 22, …

    From which we can calculate the increasing powers of 10 that solve the puzzle:

    (4[4] + 11) / 9 = 495
    (4[13] + 11) / 9 = 493827160495
    (4[22] + 11) / 9 = 493827160493827160495

    In general the solutions can be characterised as:

    (4[9k + 4] + 11) / 9 = 49 382716049[k] 5

    So the possible powers of 10 get even more ludicrously huge very quickly.

  2. Paul Cleary 28 December 2019 at 12:39 am

    This problem would also work for the repdigits 1, 2, 5 and 8 giving a total of 5 possible ways, {1, 2, 4, 5, 8}.

    I reduced the problem to 5 functions that would generate the powers for each digit varient, namely:-

    Repdigit 1 is (1/81*10^(9 n) – 8) – 10/81
    Repdigit 2 is (1700 + 10^(9 n))/4050
    Repdigit 4 is 4/81*(10^((9 n) – 5) – 1) + 11/9
    Repdigit 5 is 5/81*(10^((9 n) – 5) – 1) + 7/9
    Repdigit 8 is 8/81*(10^((9 n) – 8) – 1) + 19/9

    For all n. Which generates the following numbers for n = 1 to 4

    Repdigit 1 , {0,123456790,123456790123456790,123456790123456790123456790}

    Repdigit 2 , {246914,246913580246914,246913580246913580246914,246913580246913580246913580246914}

    Repdigit 4 , {495,493827160495,493827160493827160495,493827160493827160493827160495}

    Repdigit 5 , {618,617283950618,617283950617283950618,617283950617283950617283950618}

    Repdigit 8 , {3,987654323,987654320987654323,987654320987654320987654323}

    For the Repdigit 1 we have 9k + 1, simplifies to 9k + 1
    For the Repdigit 2 we have 4k + 5(k-1) + 1, simplifies to 9k – 4
    For the Repdigit 4 we have 2k + 2(k-1) + 2(k-2) + 1 simplifies to 9k – 11
    For the Repdigit 5 we have k + 8(k-1) + 1 simplifies to 9k – 7
    For the Repdigit 8 we have k + (k-1) + 2(k-2) + 5(k-3) + 1 simplifies to 9k – 19

    A test for the digit 2, first solution 246914, we have the number of 2’s as (4*246914) + (5*246913) + 1 = 2222222

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: