Chapter 57
How Many Friends Are On The Riddler Social Network?
Riddler Express
On a network of people, every pair is independently friends with probability , and friendship is mutual. Pick a random person, Marcia. On average, how many friends does each of Marcia’s friends have?
Solution
Marcia herself has, on average, friends, one possible link to each of the other people. But a friend of Marcia is special: we already know that person is connected to Marcia, so that one edge is guaranteed rather than a coin flip.
Take any friend of Marcia. Among the other people (everyone except Marcia and ), each is independently a friend of with probability , contributing friends on average. Adding the guaranteed edge to Marcia, This is the friendship paradox in miniature: your friends have more friends than you do, because being someone’s friend is evidence of being well connected.
The computation
Build the random graph, pick Marcia, pick one of her friends at random, and record that friend’s degree, averaged over many graphs.
import numpy as np
rng = np.random.default_rng(0)
def avg_friend_degree(n=101, runs=50_000):
total = 0; count = 0
for _ in range(runs):
A = rng.random((n, n)) < 0.5
A = np.triu(A, 1); A = A | A.T # symmetric, no self-loops
m = rng.integers(n)
friends = np.flatnonzero(A[m])
if friends.size:
f = rng.choice(friends)
total += A[f].sum(); count += 1
return total / count
print(avg_friend_degree()) # ~50.5
Riddler Classic
The sum of the factors of , including itself, is ; and inches rounds to centimeters. Find other whole numbers for which the sum of the factors of equals inches converted to the nearest centimeter. How many are there?
Solution
One inch is exactly centimeters, so the puzzle asks for whole numbers with where is the sum of all divisors of . Dividing, this means the abundancy must sit very near : for it is , close enough that rounds to exactly . There is no formula for such ; we simply scan. Up to a million there are only three: A check on the largest: , and has .
The computation
Scan each , compute the divisor sum directly, and keep those where it equals the rounded centimeter value.
def sigma(n):
s, i = 0, 1
while i * i <= n:
if n % i == 0:
s += i + (n // i if i != n // i else 0)
i += 1
return s
hits = [n for n in range(2, 1_000_001) if round(2.54 * n) == sigma(n)]
print(hits) # [36, 378, 49600]