algorithm of friendship formation

in a document format