Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. NB. wrap our data with a meaningless 0 index row for safety!
  2. dat=: 0,.|:0,.|:a$~2$%:#a
  3.  
  4. NB. score a user row (count of invited users in row)
  5. sc=: 3 : '+/y{dat'
  6.  
  7. NB. children of a user row (users they invited)
  8. ch=: 3 : 'I.y{dat'
  9.  
  10. NB. recursively score a row, row + score of children (however deep)
  11. t1=: 3 : 0
  12. NB. if we have any children
  13. if. 0<scr"0 y
  14. NB. sum children scores plus 1 for the child itself
  15. do. +/1+t1"0 ch"0 y
  16. NB. if we don't have any children
  17. else. 0
  18. end.
  19. )
  20.  
  21. NB. get our top 3 users
  22. t3=:(i.3){\:~,;t1"0 i.#dat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement