The Mathematics of Friendship