We’re rewarding the question askers & reputations are being recalculated! Read more.
10

J, 1 byte Courtesy of ngn { Try it online! 'tis called Catalogue…


6

Python 3, 56 bytes def f(M,*l):M and[f(M[1:],*l,x)for x in M[0]]or print(l) Try it online! No itertools. This is one of those weird functions that prints. Thanks to Unrelated String for -2 bytes with def.


6

Haskell, 7 bytes mapM id Try it online! Built-in, 8 bytes sequence Try it online! Less boring, 33 bytes Out-golfed by xnor's answer. Go upvote that instead! f[]=[[]] f(h:t)=[i:j|i<-h,j<-f t] Try it online!


5

Haskell, 23 bytes foldr((<*>).map(:))[[]] Try it online! Without using mapM or sequence or the like.


4

Python 2, 60 59 bytes f=lambda A,*x:[[v]+u for v in A for u in x and f(*x)or[[]]] Try it online! 1 byte thx to ovs. Look Ma! No itertools!


3

Ruby, 20 bytes ->i,*j{i.product *j} Try it online!


3

Perl 6, 8 4 bytes &[X] Try it online! Simple reduce by cross product. It would be nice if I could return the meta-operator by itself, but I've never figured out how to do that. Turns out it works for cross product?


3

K (oK), 31 15 bytes {x@'/:+!(#:)'x} Try it online!


3

Brachylog, 1 byte ẋ Try it online! A slightly less boring generator solution: Brachylog, 2 bytes ∋ᵐ Try it online!


3

Japt, 2 bytes A simple reduction by Cartesian product. rï Try it


3

Jelly, 4 2 bytes Œp Try it online! Output is "pretty printed" in the TIO link


3

Python 2, 58 bytes lambda l:l.index(max(l,key=lambda s:(-s.count(0),sum(s)))) Try it online!


2

Getting the solutions from @Delfad0r's program I extended @Delfad0r's program to output solutions. It also gives intermediate results, so you get output like this: Solving n = 8: a(8) >= 9 a(8) >= 10 a(8) >= 11 a(8) >= 12 a(8) >= 13 o . o . o o . o o . o o . o o o o o o . . o . . o o o . o . . o . o o o a(8) = 13 ...


2

R, 52 bytes function(l)order(lengths(l)-(m=sapply(l,sum)),-m)[1] Try it online! Minimizes the number of toothbrushes, then maximizes the pieces of candy, since this is apparently what OP is asking. If we want to first maximize the amount of candy, then minimize the number of toothbrushes (seems more plausible…) it becomes R, 51 bytes function(l)order(m&...


2

RUBY, 24 bytes 18 bytes n=0;10.times{puts n+=1} thanks to @A_ 10.times{|n|p n+1}


2

Zsh, 30 bytes for l;a=($^a\ ${^${=l}}) <<<$a Try it online! Split = and cartesian product ^ for each element. Our base case adds an extra space, which cleanly separates our output lists.


2

Retina, 54 39 32 bytes This took really long to write (as I tried to golf it too) (unsurprisingly, all the golfing ideas only appeared after I finally posted this). Takes input as a list of strings of alphanumeric characters and underscores (whatever \w matches in your universe), each preceded by a semicolon (I assume characters are as acceptable in Retina ...


1

05AB1E, 3 (or 6?) bytes .»â Outputs [[a,b],[c,d],[d,e]] in the format [[[a,c],d], [[a,c],e], ...]. Try it online. If this format is not allowed (I see some other answers use it, though) and it should be [[a,c,d], [a,c,e], ...], it would be this instead: .»â}€˜ Try it online. Two other formats are also possible: [[a,[c,d]], [a,[c,e]], ...] (3 bytes) or ...


1

R, 54 47 bytes f=function(x)split(j<-expand.grid(x),1:nrow(j)) Try it online! If you consider data.frame rows iterable: R, 27 bytes f=function(x)expand.grid(x) Try it online!


1

APL(NARS), chars 11, bytes 22 {,↑(∘.,)/⍵} test for product of sets: f←{,↑(∘.,)/⍵} ⎕fmt (1 2)(3 4) ┌2────────────┐ │┌2───┐ ┌2───┐│ ││ 1 2│ │ 3 4││ │└~───┘ └~───┘2 └∊────────────┘ ⎕fmt f (1 2)(3 4) ┌4──────────────────────────┐ │┌2───┐ ┌2───┐ ┌2───┐ ┌2───┐│ ││ 1 3│ │ 1 4│ │ 2 3│ │ 2 4││ │└~───┘ └~───┘ └~───┘ └~───┘2 └∊──────────────────────────┘ ⎕...


1

Charcoal, 22 bytes IEΠEθLιEθ§λ÷ιΠ∨E…θμLν¹ Try it online! Link is to verbose version of code. Explanation: θ Input list E Map over elements ι Current element L Length Π Product E Map over implicit range θ ...


1

Japt, 2 bytes rï Try it Reduces input by combination with initial value of 1st element Duplicate of @Shaggy answer, I was solving this while he just posted the same solution. I hope I can leave my answer too because it's awesome


1

JavaScript (Node.js), 52 bytes Returns a list of lists. f=([a,...b],o=[])=>a?a.flatMap(x=>f(b,[...o,x])):[o] Try it online! JavaScript (V8), 52 bytes Prints the results. f=([a,...b],o)=>a?a.map(x=>f(b,o?o+[,x]:x)):print(o) Try it online!


1

Julia 1.0, 34 bytes No imports used, iterators in Base has this. It actually makes a lazy form of this, but to print them all it will collect each one. println.(Iterators.product(l...)) where l is the list of lists.


1

Erlang, 57 bytes c([]) -> [[]]; c([H|T]) -> [[X|Y] || X <- H, Y <- c(T)].


1

Mathematica, 180 172 bytes ToExpression[StringReplace[a,{"["->"{","]"->"}"," "->"=","True"->"-10^-9","False"->"1"}]];(If[Length[#]==1,#[[1]],-1]&@@Flatten[Position[#,Min[#]]]&/@{Total/@Streets})[[1]] We assume the input is already stored as text in the variable a. If the reformatting code is neglected (input is already stored in the ...


1

APL(NARS), 149 chars, 298 bytes r←f w;n;s;i;k (n s)←w⋄r←⍬⋄→0×⍳s<3⋄i←1 →0×⍳n<k←2÷⍨(i×i×s-2)-i×s-4⋄r←r,k⋄i+←1⋄→2 h←{0=≢b←((v←↑⍵)=+/¨a)/a←{0=≢⍵:⊂⍬⋄m,(⊂1⌷⍵),¨m←∇1↓⍵}f⍵:v⍴1⋄k←↑⍋≢¨b⋄k⊃b} if not find solutions "0=≢b" than return for (n s) input, n times 1; else it would return the sum of s numbers that has less addend... test: h 1 3 1 h 2 8 1 1 ...


1

Japt, 12 10 9 bytes É&1-U)>Uq Try it online! Port of Dennis' Jelly answer again. - 1 thanks to @Shaggy.


Only top voted, non community-wiki answers of a minimum length are eligible