NB. happy dinner http://adventofcode.com/day/13 m=: ' '&cut & > cutLF ('.',CR) -.~ fread {:ARGV NB. matrix of input u=: ~. {."1 m NB. noun: unique names = all the ppl s=: _1 1{~'gain'-: >@:(2&{) NB. _1 for 'lose', 1 for 'gain' n=: ". @ > @ (3&{) NB. numeric value g=: 4 : 'v=.0$~2##x for_e. y do. v=. ((s*n)e) (< x i. 0 10{e) }v end. v' NB. calc matrix v=: u g m NB. noun: 'happiness' matrix; all data are parsed now h=: {&v @ < @ , NB. get 'happiness' for x -> y r=: 2 h/\ ] NB. one way relations between ppl in one combination w=: +/@r + +/@r@|. NB. total happiness of one combination p=: ([ , {.)"1@(i.@! A. i.) NB. all permutation with first column appended on the right echo >./ w"1 p #u h=: ({&v @ < @ ,) :: 0: NB. all missing 'happiness' values will be 0 echo >./ w"1 p >:#u NB. repeat calculation for one more (virtual) person exit 0