Skip to content
Vamshi Jandhyala

Books · The Riddler

Chapter 33

How Many Ways Can You Raid The Candy Shop?

Riddler Express

Using exactly three nines and the operations add, subtract, multiply, divide, exponentiate, or write side-by-side, the biggest number is 9999^{9^9}. Now: what is the biggest number you can make with exactly four threes?

Solution

Repeated exponentiation dwarfs everything else, so the answer is a power tower, and the only question is how to spend four threes to make the tower’s top as large as possible. Building straight up gives 3333=33273^{3^{3^3}} = 3^{3^{27}}, whose top exponent is 3277.6×10123^{27}\approx 7.6\times 10^{12}. But writing two of the threes side by side as 3333 and lifting it one level gives 33333^{3^{33}}, whose top exponent is 3335.6×10153^{33}\approx 5.6\times 10^{15}, larger by three orders of magnitude. Since the whole number is 33 raised to that top, the bigger top wins: 3333.\boxed{3^{3^{33}}}. Other arrangements (33333^{33^3}, 333333^{3^3}, (33)33(3^3)^{33}) put far smaller numbers in the exponent and do not come close.

The computation

These numbers are too large to write out, so compare them by iterated logarithm: each is 33 raised to some exponent EE, and log10log10(3E)=log10 ⁣(Elog103)\log_{10}\log_{10}(3^{E}) = \log_{10}\!\big(E\log_{10} 3\big) ranks them.

import math
cands = {"3^(3^33)": 3**33, "3^(3^(3^3))": 3**27,
         "3^(33^3)": 33**3, "(3^3)^33": 99, "33^(3^3)": None}
for name, E in cands.items():
    if E:                                  # the number is 3**E
        print(name, round(math.log10(E * math.log10(3)), 4))
# 3^(3^33) has the largest iterated logarithm -> the biggest number

Riddler Classic

Three kinds of candy are for sale. You want to buy at least one candy and at most 100, with no constraint on how many of each. How many distinct ways are there to make your purchase?

Solution

A purchase is a triple (a,b,c)(a,b,c) of nonnegative counts with 1a+b+c1001 \le a+b+c \le 100. Count the triples with a+b+c100a+b+c \le 100 by adding a slack variable s0s \ge 0 so that a+b+c+s=100a+b+c+s = 100; the number of nonnegative solutions is the stars-and-bars count (100+33)=(1033)\binom{100+3}{3} = \binom{103}{3}. Removing the single empty purchase (a=b=c=0a=b=c=0) leaves (1033)1=1768511=176850.\binom{103}{3} - 1 = 176851 - 1 = \boxed{176850}.

The computation

Evaluate the closed form, and cross-check by summing the triangular counts (n+22)\binom{n+2}{2} for each total nn from 11 to 100100.

from math import comb
print(comb(103, 3) - 1)                              # 176850
print(sum(comb(n + 2, 2) for n in range(1, 101)))    # 176850