Riddler Riddler Express
A group of people join , and each person has a random, percent chance of being friends with each of the other 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 — 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 . It is interesting to note that Marcia on average would have only 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 — including itself — is . Coincidentally, inches rounded to the nearest centimeter is … centimeters!
Can you find another whole number like , 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 and are two numbers below 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())