NB. packages in the sleigh http://adventofcode.com/day/24 NB. ncx is based on https://docs.python.org/3/library/itertools.html ncx=: 4 : 0 NB. next combination index; x - n; y - prev indices if. 0=$$y do. i.y return. end. NB. first call - n ncx r for_i. i.-r=.#y do. if. (i+x-r)~:i{y do. y=.(>:i{y)i}y NB. y[i]+=1; for j in range(i+1, r): y[j]=y[j-1]+1 for_j. (>:i)+i.r->:i do. y=.(>:(<:j){y)j}y end. y return. end. end. 0$0 ) NB. this is based on godarderik's python full-check solution: NB. https://www.reddit.com/r/adventofcode/comments/3y1s7f/day_24_solutions/cy9srkh has_sum=: 3 : 0 NB. y - p;weight;n-subparts;n-total-parts m=.#p [ 'p w n t'=.y for_c. >:i.m do. NB. try all lengths 1..#p whilst. 0<#c=.m ncx c do. NB. all combinations if. w~:+/part=. c{p do. continue. end. NB. wrong weight - try again if. n=2 do. 1 return. end. NB. just 2 parts and 1st is ok - all ok! if. n:i.m do. whilst. 0<#c=.m ncx c do. part=.c{p if. w~:+/part do. continue. end. if. n=2 do. E 'R';(p-.part);+/(p-.part) E 'L';part;+/part 1 return. end. if. n