3 min read

How Many Friends Are On The Riddler Social Network?

Table of Contents

Riddler Riddler Express

A group of 101101 people join μεταμετα, and each person has a random, 5050 percent chance of being friends with each of the other 100100 people. Friendship is a symmetric relationship on μεταμετα, so if you’re friends with me, then I am also friends with you.I pick a random person among the 101101 — let’s suppose her name is Marcia. On average, how many friends would you expect each of Marcia’s friends to have?

Computational Solution

From the simulation below, we see that the expected number of friends of each of Marcia’s friends is 50.5\textbf{50.5}. It is interesting to note that Marcia on average would have only 5050 friends.

import networkx as nx
from random import random, randint, choice

def exp_num_friends(n, runs = 10000):
    total_deg = 0
    for _ in range(runs):
        G = nx.Graph()
        for i in range(n):
            G.add_node(i)
        for i in range(n-1):
            for j in range(i+1, n):
                if random() < 0.5:
                    G.add_edge(i,j) 
        marcia = randint(0,n-1)
        marcia_friends =  list(G.adj[marcia].keys())
        if marcia_friends:
            total_deg += G.degree[choice(marcia_friends)]
    return total_deg/runs

print(exp_num_friends(101))

Riddler Classic

The sum of the factors of 3636 — including 3636 itself — is 9191. Coincidentally, 3636 inches rounded to the nearest centimeter is … 9191 centimeters!

Can you find another whole number like 3636, where you can “compute” the sum of its factors by converting from inches to centimeters?

Extra credit: Can you find a third whole number with this property? How many more whole numbers can you find?

Computational Solution

From the code below we see that 378378 and 4960049600 are two numbers below 10000001000000 that satisify the given property.

from functools import reduce

def sum_of_factors(n):    
    return sum(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def inches_to_cm_same_as_sum_of_divisors():
    nums= []
    for i in range(37,1000000):
        if round(i*2.54) == sum_of_factors(i):
            nums.append(i)
    return nums
    
print(inches_to_cm_same_as_sum_of_divisors())