Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
f=lambda t,a,*p:t==0<len[p][t*t:len(p)==5and{p}or==5]or{i for v in[*a]for i in f(t-a.pop(0),[*a],*sorted([*p,v]))}
Try it online!Try it online!
Input target value and the array of nums, output a set of tuples.
f=lambda t,a,*p:t==0<len(p)==5and{p}or{i for v in[*a]for i in f(t-a.pop(0),[*a],*sorted([*p,v]))}
Try it online!
f=lambda t,a,*p:[p][t*t:len(p)==5]or{i for v in[*a]for i in f(t-a.pop(0),[*a],*sorted([*p,v]))}
f=lambda t,a,*p:t==0<len(p)==5and{p}or{*sum([[*fi for v in[*a]for i in f(t-a.pop(0),[*a],*sorted([*p,v]))]for v in[*a]],[])}
f=lambda t,a,*p:t==0<len(p)==5and{p}or{*sum([[*f(t-a.pop(0),[*a],*sorted([*p,v]))]for v in[*a]],[])}