List *all* the tuples! Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The PPCG Site design is on its way - help us make it awesome! Sandbox for Proposed ChallengesTips for golfing in HaskellOutput a list of all rational numbersMoore IterationNaturally linear Diophantine equationsCo-primality and the number piRotate every row and column in a matrixConvert header levels to numbersASCII DandelionsPrint all decimalsParse a list of lists into a Sad-List2D Array Middle Point

How do I mention the quality of my school without bragging

Is 1 ppb equal to 1 μg/kg?

Bonus calculation: Am I making a mountain out of a molehill?

Why is "Captain Marvel" translated as male in Portugal?

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

What do you call a plan that's an alternative plan in case your initial plan fails?

Disable hyphenation for an entire paragraph

Should I call the interviewer directly, if HR aren't responding?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Why does Python start at index -1 when indexing a list from the end?

Why is black pepper both grey and black?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Are my PIs rude or am I just being too sensitive?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

When -s is used with third person singular. What's its use in this context?

Did Xerox really develop the first LAN?

Can inflation occur in a positive-sum game currency system such as the Stack Exchange reputation system?

How can I make names more distinctive without making them longer?

G-Code for resetting to 100% speed

How to draw this diagram using TikZ package?

What are the motives behind Cersei's orders given to Bronn?

How can I fade player when goes inside or outside of the area?

List *all* the tuples!

How to recreate this effect in Photoshop?



List *all* the tuples!



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The PPCG Site design is on its way - help us make it awesome!
Sandbox for Proposed ChallengesTips for golfing in HaskellOutput a list of all rational numbersMoore IterationNaturally linear Diophantine equationsCo-primality and the number piRotate every row and column in a matrixConvert header levels to numbersASCII DandelionsPrint all decimalsParse a list of lists into a Sad-List2D Array Middle Point










21












$begingroup$


Write a program, given an input n, will generate all possible n-tuples using natural numbers.



n=1
(1),(2),(3),(4),(5),(6)...

n=2
(1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)...

n=6
(1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)...


  • The output may be in any order that does not break any other rules.

  • The program must be written to run forever and list all applicable tuples exactly once, in theory.

    • In reality, your program will reach your integer type's limit and crash. This is acceptable as long the program would run infinitely long if only your integer type was unlimited.

    • Each valid tuple must be listed within finite time, if only the program were allowed to run that long.


  • The output may, at your option, include zeroes in addition to the natural numbers.

  • You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)

  • Code-golf rules apply, shortest program wins.

Thanks to "Artemis Fowl" for feedback during the sandbox phase.










share|improve this question











$endgroup$











  • $begingroup$
    For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
    $endgroup$
    – Phil H
    13 hours ago










  • $begingroup$
    For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
    $endgroup$
    – billpg
    13 hours ago






  • 1




    $begingroup$
    Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
    $endgroup$
    – Expired Data
    13 hours ago






  • 1




    $begingroup$
    Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
    $endgroup$
    – Jonathan Allan
    9 hours ago






  • 4




    $begingroup$
    "You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
    $endgroup$
    – Jonathan Allan
    8 hours ago















21












$begingroup$


Write a program, given an input n, will generate all possible n-tuples using natural numbers.



n=1
(1),(2),(3),(4),(5),(6)...

n=2
(1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)...

n=6
(1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)...


  • The output may be in any order that does not break any other rules.

  • The program must be written to run forever and list all applicable tuples exactly once, in theory.

    • In reality, your program will reach your integer type's limit and crash. This is acceptable as long the program would run infinitely long if only your integer type was unlimited.

    • Each valid tuple must be listed within finite time, if only the program were allowed to run that long.


  • The output may, at your option, include zeroes in addition to the natural numbers.

  • You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)

  • Code-golf rules apply, shortest program wins.

Thanks to "Artemis Fowl" for feedback during the sandbox phase.










share|improve this question











$endgroup$











  • $begingroup$
    For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
    $endgroup$
    – Phil H
    13 hours ago










  • $begingroup$
    For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
    $endgroup$
    – billpg
    13 hours ago






  • 1




    $begingroup$
    Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
    $endgroup$
    – Expired Data
    13 hours ago






  • 1




    $begingroup$
    Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
    $endgroup$
    – Jonathan Allan
    9 hours ago






  • 4




    $begingroup$
    "You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
    $endgroup$
    – Jonathan Allan
    8 hours ago













21












21








21


3



$begingroup$


Write a program, given an input n, will generate all possible n-tuples using natural numbers.



n=1
(1),(2),(3),(4),(5),(6)...

n=2
(1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)...

n=6
(1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)...


  • The output may be in any order that does not break any other rules.

  • The program must be written to run forever and list all applicable tuples exactly once, in theory.

    • In reality, your program will reach your integer type's limit and crash. This is acceptable as long the program would run infinitely long if only your integer type was unlimited.

    • Each valid tuple must be listed within finite time, if only the program were allowed to run that long.


  • The output may, at your option, include zeroes in addition to the natural numbers.

  • You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)

  • Code-golf rules apply, shortest program wins.

Thanks to "Artemis Fowl" for feedback during the sandbox phase.










share|improve this question











$endgroup$




Write a program, given an input n, will generate all possible n-tuples using natural numbers.



n=1
(1),(2),(3),(4),(5),(6)...

n=2
(1,1),(1,2),(2,1),(2,2),(1,3),(3,1),(2,3),(3,2),(3,3)...

n=6
(1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1)...


  • The output may be in any order that does not break any other rules.

  • The program must be written to run forever and list all applicable tuples exactly once, in theory.

    • In reality, your program will reach your integer type's limit and crash. This is acceptable as long the program would run infinitely long if only your integer type was unlimited.

    • Each valid tuple must be listed within finite time, if only the program were allowed to run that long.


  • The output may, at your option, include zeroes in addition to the natural numbers.

  • You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)

  • Code-golf rules apply, shortest program wins.

Thanks to "Artemis Fowl" for feedback during the sandbox phase.







code-golf sequence






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 hours ago







billpg

















asked 13 hours ago









billpgbillpg

9751929




9751929











  • $begingroup$
    For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
    $endgroup$
    – Phil H
    13 hours ago










  • $begingroup$
    For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
    $endgroup$
    – billpg
    13 hours ago






  • 1




    $begingroup$
    Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
    $endgroup$
    – Expired Data
    13 hours ago






  • 1




    $begingroup$
    Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
    $endgroup$
    – Jonathan Allan
    9 hours ago






  • 4




    $begingroup$
    "You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
    $endgroup$
    – Jonathan Allan
    8 hours ago
















  • $begingroup$
    For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
    $endgroup$
    – Phil H
    13 hours ago










  • $begingroup$
    For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
    $endgroup$
    – billpg
    13 hours ago






  • 1




    $begingroup$
    Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
    $endgroup$
    – Expired Data
    13 hours ago






  • 1




    $begingroup$
    Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
    $endgroup$
    – Jonathan Allan
    9 hours ago






  • 4




    $begingroup$
    "You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
    $endgroup$
    – Jonathan Allan
    8 hours ago















$begingroup$
For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
$endgroup$
– Phil H
13 hours ago




$begingroup$
For n=6, is it acceptable to produce 0,0 .. 5,5 or does it have to include 6,6?
$endgroup$
– Phil H
13 hours ago












$begingroup$
For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
$endgroup$
– billpg
13 hours ago




$begingroup$
For n=6, the 6-tuples are (1,1,1,1,1,1) (1,1,1,1,2,1) (1,1,1,2,1,1) etc. I'll add this to the the examples.
$endgroup$
– billpg
13 hours ago




1




1




$begingroup$
Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
$endgroup$
– Expired Data
13 hours ago




$begingroup$
Each valid tuple must be listed within finite time, if only the program were allowed to run that long. .. Does this contradict the output being in any order? i.e what if my order is (1,1),(2,1),(3,1)...(n,1) and only once I've gone through every natural number will i print (1,2)
$endgroup$
– Expired Data
13 hours ago




1




1




$begingroup$
Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
$endgroup$
– Jonathan Allan
9 hours ago




$begingroup$
Must we output as we go or would a function which yields an infinite list at the end of time sufficient?
$endgroup$
– Jonathan Allan
9 hours ago




4




4




$begingroup$
"You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
$endgroup$
– Jonathan Allan
8 hours ago




$begingroup$
"You may choose your program's output format for your convenience, as long as the separation between tuples and numbers inside each tuple is clear and consistent" - may we output differing (albeit consistently differing) separation (e.g. like this)?
$endgroup$
– Jonathan Allan
8 hours ago










15 Answers
15






active

oldest

votes


















9












$begingroup$


Haskell, 62 bytes





([1..]>>=).(!)
0!s=[[]|s<1]
n!s=[a:p|a<-[1..s],p<-(n-1)!(s-a)]


Try it online!



n!s generates all the n-tuples that sum to s.



Then the answer is ([1..]>>=).(!), i.e. n -> [t | s<-[1..], t<-n!s].



This is a function mapping an integer n to an infinite lazy list of tuples (lists of integers).






share|improve this answer









$endgroup$




















    6












    $begingroup$


    Husk, 2 bytes



    πN


    Try it online!



    Explanation



    N is the infinite list of natural numbers [1,2,3,4,...
    π is Cartesian power.
    Result is an infinite list of lists.
    Each list of the desired length occurs exactly once because π is cool like that.
    Input and output are implicit.






    share|improve this answer









    $endgroup$








    • 1




      $begingroup$
      Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
      $endgroup$
      – billpg
      6 hours ago


















    4












    $begingroup$


    Perl 6, 37 bytes





    $++.polymod(1+$++ xx $_-1).say xx *


    Try it online!



    Essentially runs polymod with as many entries as needed, where the modulo is always greater than the input, i.e. 0.polymod( 1,1,1 ), 1.polymod( 2,2,2 ) etc. That way the digit is always within the range. Perl6 won't let me modulo infinity...






    share|improve this answer









    $endgroup$








    • 3




      $begingroup$
      This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
      $endgroup$
      – bb94
      6 hours ago


















    3












    $begingroup$

    Pyth - 10 bytes



    Loops through all x, and takes [1..x]^n. This makes duplicates, so only keeps ones that are new to that x, aka contain x in them. The formatting is a little weird, but it can be made standard with one more byte, .V1jf}bT^Sb



    .V1f}bT^Sb


    Try it online.






    share|improve this answer











    $endgroup$




















      2












      $begingroup$


      Brachylog (v2), 9 bytes



      ~l.ℕᵐ+≜∧≜


      Try it online!



      This is an infinite generator that generates all possible tuples. The TIO link has a header that uses the generator to generate 1000 elements and prints them (but the generator could continue indefinitely if I asked for that instead; Brachylog's integers are unbounded).



      It feels like there should be a terser way, but there are a lot of constraints and this is the tersest I can fit them into a single program.



      Explanation



      ~l.ℕᵐ+≜∧≜
      . Generate
      ≜ all explicit
      ~l lists whose length is the input
      ᵐ for which every element
      ℕ is non-negative
      + and whose sum
      ≜ is used to order the lists (closest to zero first)
      ∧ [remove unwanted implicit constraint]


      Incidentally, it strikes me as interesting just how different my explanations of the two are, despite them doing the exact same thing from Brachylog's point of view. The first is the first nondeterministic predicate in the program, so it sets the order of results; in this case, it calculates all possible explicit values for the sum of the list in the order 0, 1, 2, 3…, and is being used to ensure that the lists are output in order of their sum (this ensures that each possible list appears after a finite amount of output). The second is used to calculate all the explicit possibilities for the list (rather than outputting a formula specifying how the elements of the list relate to each other).






      share|improve this answer











      $endgroup$












      • $begingroup$
        ↰₁ẉ⊥ is also a good header, for printing infinitely.
        $endgroup$
        – Unrelated String
        6 hours ago










      • $begingroup$
        Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
        $endgroup$
        – Unrelated String
        6 hours ago






      • 1




        $begingroup$
        @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
        $endgroup$
        – ais523
        3 hours ago










      • $begingroup$
        Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
        $endgroup$
        – Unrelated String
        1 hour ago



















      1












      $begingroup$


      Jelly, 10 (9?) bytes



      9 if we may output using non-consistent separation (which I have enquired about) -- removal of the .



      ‘ɼṗ³ċƇ®Ṅ€ß


      Try it online!



      How?



      ‘ɼṗ³ċƇ®Ṅ€ß - Main Link: some argument, x (initially equal to n, but unused)
      ɼ - recall v from the register (initially 0), then set register to, and yield, f(v)
      ‘ - f = increment
      - (i.e. v=v+1)
      ³ - program's third command line argument (1st program argument) = n
      ṗ - (implicit range of [1..v]) Cartesian power (n)
      - (i.e. all tuples of length n with items in [1..v])
      Ƈ - filter keep those for which:
      ċ - count
      ® - recall from register
      - (i.e. keep only those containing v)
      Ṅ€ - print €ach
      ß - call this Link with the same arity
      - (i.e. call Main(theFilteredList), again the argument is not actually used)





      share|improve this answer











      $endgroup$








      • 1




        $begingroup$
        Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
        $endgroup$
        – Kevin Cruijssen
        8 hours ago


















      1












      $begingroup$


      05AB1E, 15 11 bytes



      [¼¾LIãvy¾å—


      -4 bytes by creating a port of @Maltysen's Pyth answer.



      Try it online.



      Explanation:





      [ # Start an infinite loop:
      ¼ # Increase the counter_variable by 1 (0 by default)
      ¾L # Create a list in the range [1, counter_variable]
      Iã # Take the cartesian power of this list with the input
      v # Loop over each list `y` in this list of lists:
      y¾å # If list `y` contains the counter_variable:
      — # Print list `y` with trailing newline





      share|improve this answer











      $endgroup$








      • 2




        $begingroup$
        When will the program get to [1,2,1]? Remember it has to be within finite time.
        $endgroup$
        – billpg
        13 hours ago










      • $begingroup$
        @billpg Should be fixed now.
        $endgroup$
        – Kevin Cruijssen
        11 hours ago


















      1












      $begingroup$


      Haskell, 50 bytes





      f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]


      Try it online!



      Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The <$f trick is explained here.




      Haskell, 51 bytes





      f 1=pure<$>[0..]
      f n=[a-k:k:t|a:t<-f$n-1,k<-[0..a]]


      Try it online!



      Recursively stretches all n-1-tuples into all n-tuples by splitting the first number a of each n-1-tuple into two numbers a-k,k that sum to it, in every possible way.






      share|improve this answer









      $endgroup$




















        0












        $begingroup$


        VDM-SL, 51 bytes



        g(i)==if i=0thenelsex:nat,y in set g(i-1)


        Recursive set comprehension with sequence concatenation..



        Not on TIO, you could run in a program (if you turn on limits for nat type or it wont terminate):



        functions 
        g:nat->set of ?
        g(i)==if i=0thenelsex:nat,y in set g(i-1)


        Includes the optional 0s in answer otherwise it would be 52 bytes binding on nat1






        share|improve this answer









        $endgroup$




















          0












          $begingroup$


          MATL, 16 bytes



          `@:GZ^t!Xs@=Y)DT


          Tuples are ordered by increasing sum, and within a given sum they are ordered lexicographically.



          Try it online!






          share|improve this answer











          $endgroup$












          • $begingroup$
            You are supposed to take input
            $endgroup$
            – H.PWiz
            10 hours ago










          • $begingroup$
            @H.PWiz Thanks. I got it wrong
            $endgroup$
            – Luis Mendo
            9 hours ago










          • $begingroup$
            @H.PWiz Solved now
            $endgroup$
            – Luis Mendo
            6 hours ago


















          0












          $begingroup$


          Wolfram Language (Mathematica), 131 bytes



          While[0<1,If[a~FreeQ~#,Print@#]&/@(b=Table[Select[Range@t~Tuples~s,Tr@#==k&],k,t,t(s=#)]~Flatten~1);a=a~Join~b;t++]&
          t=1
          a=


          Try it online!






          share|improve this answer











          $endgroup$




















            0












            $begingroup$

            perl -M5.010 122 bytes



            $n=shift;
            $s.="for$x$_(1..$m)"for 1..$n;
            $t.="$x$_ "for 1..$n;
            $u.=''x$n;
            eval"$m++;$s$_=qq' $t';/ $
            m /&&say$u;redo"


            Added some newlines for readabilities sake (not counted in the byte count)






            share|improve this answer











            $endgroup$




















              0












              $begingroup$


              Wolfram Language (Mathematica), 62 bytes



              Do[Print/@Permutations@#&/@n~IntegerPartitions~#,n,#,∞]&


              Try it online!




              -3 bytes with inconsistent separation (delete @#&)



              Try it online!






              share|improve this answer









              $endgroup$




















                0












                $begingroup$


                Python 2, 126 112 106 101 bytes





                n=input()
                i=0;p=1
                while 1:
                b=map(len,bin(i+p)[3:].split('0'));i=-~i%p;p<<=i<1
                if len(b)==n:print b


                Try it online!



                5 bytes thx to mypetlion



                Construct the ordered partitions of m into n bins, for m = 0,1,2,3,... by selecting for binary numbers with n-1 0s and m 1s.






                share|improve this answer











                $endgroup$












                • $begingroup$
                  if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                  $endgroup$
                  – mypetlion
                  4 hours ago


















                -2












                $begingroup$

                Python3 (56 characters)



                This runs, but never outputs/returns any values, because the permutations function keeps pulling numbers from count. But in theory, this would return the requested permutations.



                from itertools import*
                lambda n:permutations(count(1),n)


                Proof that this works for limited integer range:



                from itertools import*
                l = lambda n: permutations(range(1, 10), n)
                print(list(l(3))) # returns all permutations of (1, 2, 3, ..., 10) of length 3





                share|improve this answer









                $endgroup$








                • 1




                  $begingroup$
                  This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                  $endgroup$
                  – alexis
                  6 hours ago











                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "200"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183225%2flist-all-the-tuples%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                15 Answers
                15






                active

                oldest

                votes








                15 Answers
                15






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                9












                $begingroup$


                Haskell, 62 bytes





                ([1..]>>=).(!)
                0!s=[[]|s<1]
                n!s=[a:p|a<-[1..s],p<-(n-1)!(s-a)]


                Try it online!



                n!s generates all the n-tuples that sum to s.



                Then the answer is ([1..]>>=).(!), i.e. n -> [t | s<-[1..], t<-n!s].



                This is a function mapping an integer n to an infinite lazy list of tuples (lists of integers).






                share|improve this answer









                $endgroup$

















                  9












                  $begingroup$


                  Haskell, 62 bytes





                  ([1..]>>=).(!)
                  0!s=[[]|s<1]
                  n!s=[a:p|a<-[1..s],p<-(n-1)!(s-a)]


                  Try it online!



                  n!s generates all the n-tuples that sum to s.



                  Then the answer is ([1..]>>=).(!), i.e. n -> [t | s<-[1..], t<-n!s].



                  This is a function mapping an integer n to an infinite lazy list of tuples (lists of integers).






                  share|improve this answer









                  $endgroup$















                    9












                    9








                    9





                    $begingroup$


                    Haskell, 62 bytes





                    ([1..]>>=).(!)
                    0!s=[[]|s<1]
                    n!s=[a:p|a<-[1..s],p<-(n-1)!(s-a)]


                    Try it online!



                    n!s generates all the n-tuples that sum to s.



                    Then the answer is ([1..]>>=).(!), i.e. n -> [t | s<-[1..], t<-n!s].



                    This is a function mapping an integer n to an infinite lazy list of tuples (lists of integers).






                    share|improve this answer









                    $endgroup$




                    Haskell, 62 bytes





                    ([1..]>>=).(!)
                    0!s=[[]|s<1]
                    n!s=[a:p|a<-[1..s],p<-(n-1)!(s-a)]


                    Try it online!



                    n!s generates all the n-tuples that sum to s.



                    Then the answer is ([1..]>>=).(!), i.e. n -> [t | s<-[1..], t<-n!s].



                    This is a function mapping an integer n to an infinite lazy list of tuples (lists of integers).







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 12 hours ago









                    LynnLynn

                    50.9k899233




                    50.9k899233





















                        6












                        $begingroup$


                        Husk, 2 bytes



                        πN


                        Try it online!



                        Explanation



                        N is the infinite list of natural numbers [1,2,3,4,...
                        π is Cartesian power.
                        Result is an infinite list of lists.
                        Each list of the desired length occurs exactly once because π is cool like that.
                        Input and output are implicit.






                        share|improve this answer









                        $endgroup$








                        • 1




                          $begingroup$
                          Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                          $endgroup$
                          – billpg
                          6 hours ago















                        6












                        $begingroup$


                        Husk, 2 bytes



                        πN


                        Try it online!



                        Explanation



                        N is the infinite list of natural numbers [1,2,3,4,...
                        π is Cartesian power.
                        Result is an infinite list of lists.
                        Each list of the desired length occurs exactly once because π is cool like that.
                        Input and output are implicit.






                        share|improve this answer









                        $endgroup$








                        • 1




                          $begingroup$
                          Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                          $endgroup$
                          – billpg
                          6 hours ago













                        6












                        6








                        6





                        $begingroup$


                        Husk, 2 bytes



                        πN


                        Try it online!



                        Explanation



                        N is the infinite list of natural numbers [1,2,3,4,...
                        π is Cartesian power.
                        Result is an infinite list of lists.
                        Each list of the desired length occurs exactly once because π is cool like that.
                        Input and output are implicit.






                        share|improve this answer









                        $endgroup$




                        Husk, 2 bytes



                        πN


                        Try it online!



                        Explanation



                        N is the infinite list of natural numbers [1,2,3,4,...
                        π is Cartesian power.
                        Result is an infinite list of lists.
                        Each list of the desired length occurs exactly once because π is cool like that.
                        Input and output are implicit.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 7 hours ago









                        ZgarbZgarb

                        26.7k462230




                        26.7k462230







                        • 1




                          $begingroup$
                          Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                          $endgroup$
                          – billpg
                          6 hours ago












                        • 1




                          $begingroup$
                          Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                          $endgroup$
                          – billpg
                          6 hours ago







                        1




                        1




                        $begingroup$
                        Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                        $endgroup$
                        – billpg
                        6 hours ago




                        $begingroup$
                        Wow, and this doesn't do [1,1,n] either. Is there a pattern to the order it outputs?
                        $endgroup$
                        – billpg
                        6 hours ago











                        4












                        $begingroup$


                        Perl 6, 37 bytes





                        $++.polymod(1+$++ xx $_-1).say xx *


                        Try it online!



                        Essentially runs polymod with as many entries as needed, where the modulo is always greater than the input, i.e. 0.polymod( 1,1,1 ), 1.polymod( 2,2,2 ) etc. That way the digit is always within the range. Perl6 won't let me modulo infinity...






                        share|improve this answer









                        $endgroup$








                        • 3




                          $begingroup$
                          This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                          $endgroup$
                          – bb94
                          6 hours ago















                        4












                        $begingroup$


                        Perl 6, 37 bytes





                        $++.polymod(1+$++ xx $_-1).say xx *


                        Try it online!



                        Essentially runs polymod with as many entries as needed, where the modulo is always greater than the input, i.e. 0.polymod( 1,1,1 ), 1.polymod( 2,2,2 ) etc. That way the digit is always within the range. Perl6 won't let me modulo infinity...






                        share|improve this answer









                        $endgroup$








                        • 3




                          $begingroup$
                          This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                          $endgroup$
                          – bb94
                          6 hours ago













                        4












                        4








                        4





                        $begingroup$


                        Perl 6, 37 bytes





                        $++.polymod(1+$++ xx $_-1).say xx *


                        Try it online!



                        Essentially runs polymod with as many entries as needed, where the modulo is always greater than the input, i.e. 0.polymod( 1,1,1 ), 1.polymod( 2,2,2 ) etc. That way the digit is always within the range. Perl6 won't let me modulo infinity...






                        share|improve this answer









                        $endgroup$




                        Perl 6, 37 bytes





                        $++.polymod(1+$++ xx $_-1).say xx *


                        Try it online!



                        Essentially runs polymod with as many entries as needed, where the modulo is always greater than the input, i.e. 0.polymod( 1,1,1 ), 1.polymod( 2,2,2 ) etc. That way the digit is always within the range. Perl6 won't let me modulo infinity...







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 12 hours ago









                        Phil HPhil H

                        1,170817




                        1,170817







                        • 3




                          $begingroup$
                          This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                          $endgroup$
                          – bb94
                          6 hours ago












                        • 3




                          $begingroup$
                          This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                          $endgroup$
                          – bb94
                          6 hours ago







                        3




                        3




                        $begingroup$
                        This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                        $endgroup$
                        – bb94
                        6 hours ago




                        $begingroup$
                        This doesn't list every tuple exactly once (for instance, (0, 1, 0, 0) is not listed).
                        $endgroup$
                        – bb94
                        6 hours ago











                        3












                        $begingroup$

                        Pyth - 10 bytes



                        Loops through all x, and takes [1..x]^n. This makes duplicates, so only keeps ones that are new to that x, aka contain x in them. The formatting is a little weird, but it can be made standard with one more byte, .V1jf}bT^Sb



                        .V1f}bT^Sb


                        Try it online.






                        share|improve this answer











                        $endgroup$

















                          3












                          $begingroup$

                          Pyth - 10 bytes



                          Loops through all x, and takes [1..x]^n. This makes duplicates, so only keeps ones that are new to that x, aka contain x in them. The formatting is a little weird, but it can be made standard with one more byte, .V1jf}bT^Sb



                          .V1f}bT^Sb


                          Try it online.






                          share|improve this answer











                          $endgroup$















                            3












                            3








                            3





                            $begingroup$

                            Pyth - 10 bytes



                            Loops through all x, and takes [1..x]^n. This makes duplicates, so only keeps ones that are new to that x, aka contain x in them. The formatting is a little weird, but it can be made standard with one more byte, .V1jf}bT^Sb



                            .V1f}bT^Sb


                            Try it online.






                            share|improve this answer











                            $endgroup$



                            Pyth - 10 bytes



                            Loops through all x, and takes [1..x]^n. This makes duplicates, so only keeps ones that are new to that x, aka contain x in them. The formatting is a little weird, but it can be made standard with one more byte, .V1jf}bT^Sb



                            .V1f}bT^Sb


                            Try it online.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 9 hours ago

























                            answered 9 hours ago









                            MaltysenMaltysen

                            21.4k445116




                            21.4k445116





















                                2












                                $begingroup$


                                Brachylog (v2), 9 bytes



                                ~l.ℕᵐ+≜∧≜


                                Try it online!



                                This is an infinite generator that generates all possible tuples. The TIO link has a header that uses the generator to generate 1000 elements and prints them (but the generator could continue indefinitely if I asked for that instead; Brachylog's integers are unbounded).



                                It feels like there should be a terser way, but there are a lot of constraints and this is the tersest I can fit them into a single program.



                                Explanation



                                ~l.ℕᵐ+≜∧≜
                                . Generate
                                ≜ all explicit
                                ~l lists whose length is the input
                                ᵐ for which every element
                                ℕ is non-negative
                                + and whose sum
                                ≜ is used to order the lists (closest to zero first)
                                ∧ [remove unwanted implicit constraint]


                                Incidentally, it strikes me as interesting just how different my explanations of the two are, despite them doing the exact same thing from Brachylog's point of view. The first is the first nondeterministic predicate in the program, so it sets the order of results; in this case, it calculates all possible explicit values for the sum of the list in the order 0, 1, 2, 3…, and is being used to ensure that the lists are output in order of their sum (this ensures that each possible list appears after a finite amount of output). The second is used to calculate all the explicit possibilities for the list (rather than outputting a formula specifying how the elements of the list relate to each other).






                                share|improve this answer











                                $endgroup$












                                • $begingroup$
                                  ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago










                                • $begingroup$
                                  Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago






                                • 1




                                  $begingroup$
                                  @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                  $endgroup$
                                  – ais523
                                  3 hours ago










                                • $begingroup$
                                  Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                  $endgroup$
                                  – Unrelated String
                                  1 hour ago
















                                2












                                $begingroup$


                                Brachylog (v2), 9 bytes



                                ~l.ℕᵐ+≜∧≜


                                Try it online!



                                This is an infinite generator that generates all possible tuples. The TIO link has a header that uses the generator to generate 1000 elements and prints them (but the generator could continue indefinitely if I asked for that instead; Brachylog's integers are unbounded).



                                It feels like there should be a terser way, but there are a lot of constraints and this is the tersest I can fit them into a single program.



                                Explanation



                                ~l.ℕᵐ+≜∧≜
                                . Generate
                                ≜ all explicit
                                ~l lists whose length is the input
                                ᵐ for which every element
                                ℕ is non-negative
                                + and whose sum
                                ≜ is used to order the lists (closest to zero first)
                                ∧ [remove unwanted implicit constraint]


                                Incidentally, it strikes me as interesting just how different my explanations of the two are, despite them doing the exact same thing from Brachylog's point of view. The first is the first nondeterministic predicate in the program, so it sets the order of results; in this case, it calculates all possible explicit values for the sum of the list in the order 0, 1, 2, 3…, and is being used to ensure that the lists are output in order of their sum (this ensures that each possible list appears after a finite amount of output). The second is used to calculate all the explicit possibilities for the list (rather than outputting a formula specifying how the elements of the list relate to each other).






                                share|improve this answer











                                $endgroup$












                                • $begingroup$
                                  ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago










                                • $begingroup$
                                  Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago






                                • 1




                                  $begingroup$
                                  @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                  $endgroup$
                                  – ais523
                                  3 hours ago










                                • $begingroup$
                                  Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                  $endgroup$
                                  – Unrelated String
                                  1 hour ago














                                2












                                2








                                2





                                $begingroup$


                                Brachylog (v2), 9 bytes



                                ~l.ℕᵐ+≜∧≜


                                Try it online!



                                This is an infinite generator that generates all possible tuples. The TIO link has a header that uses the generator to generate 1000 elements and prints them (but the generator could continue indefinitely if I asked for that instead; Brachylog's integers are unbounded).



                                It feels like there should be a terser way, but there are a lot of constraints and this is the tersest I can fit them into a single program.



                                Explanation



                                ~l.ℕᵐ+≜∧≜
                                . Generate
                                ≜ all explicit
                                ~l lists whose length is the input
                                ᵐ for which every element
                                ℕ is non-negative
                                + and whose sum
                                ≜ is used to order the lists (closest to zero first)
                                ∧ [remove unwanted implicit constraint]


                                Incidentally, it strikes me as interesting just how different my explanations of the two are, despite them doing the exact same thing from Brachylog's point of view. The first is the first nondeterministic predicate in the program, so it sets the order of results; in this case, it calculates all possible explicit values for the sum of the list in the order 0, 1, 2, 3…, and is being used to ensure that the lists are output in order of their sum (this ensures that each possible list appears after a finite amount of output). The second is used to calculate all the explicit possibilities for the list (rather than outputting a formula specifying how the elements of the list relate to each other).






                                share|improve this answer











                                $endgroup$




                                Brachylog (v2), 9 bytes



                                ~l.ℕᵐ+≜∧≜


                                Try it online!



                                This is an infinite generator that generates all possible tuples. The TIO link has a header that uses the generator to generate 1000 elements and prints them (but the generator could continue indefinitely if I asked for that instead; Brachylog's integers are unbounded).



                                It feels like there should be a terser way, but there are a lot of constraints and this is the tersest I can fit them into a single program.



                                Explanation



                                ~l.ℕᵐ+≜∧≜
                                . Generate
                                ≜ all explicit
                                ~l lists whose length is the input
                                ᵐ for which every element
                                ℕ is non-negative
                                + and whose sum
                                ≜ is used to order the lists (closest to zero first)
                                ∧ [remove unwanted implicit constraint]


                                Incidentally, it strikes me as interesting just how different my explanations of the two are, despite them doing the exact same thing from Brachylog's point of view. The first is the first nondeterministic predicate in the program, so it sets the order of results; in this case, it calculates all possible explicit values for the sum of the list in the order 0, 1, 2, 3…, and is being used to ensure that the lists are output in order of their sum (this ensures that each possible list appears after a finite amount of output). The second is used to calculate all the explicit possibilities for the list (rather than outputting a formula specifying how the elements of the list relate to each other).







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                answered 8 hours ago


























                                community wiki





                                ais523












                                • $begingroup$
                                  ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago










                                • $begingroup$
                                  Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago






                                • 1




                                  $begingroup$
                                  @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                  $endgroup$
                                  – ais523
                                  3 hours ago










                                • $begingroup$
                                  Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                  $endgroup$
                                  – Unrelated String
                                  1 hour ago

















                                • $begingroup$
                                  ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago










                                • $begingroup$
                                  Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                  $endgroup$
                                  – Unrelated String
                                  6 hours ago






                                • 1




                                  $begingroup$
                                  @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                  $endgroup$
                                  – ais523
                                  3 hours ago










                                • $begingroup$
                                  Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                  $endgroup$
                                  – Unrelated String
                                  1 hour ago
















                                $begingroup$
                                ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                $endgroup$
                                – Unrelated String
                                6 hours ago




                                $begingroup$
                                ↰₁ẉ⊥ is also a good header, for printing infinitely.
                                $endgroup$
                                – Unrelated String
                                6 hours ago












                                $begingroup$
                                Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                $endgroup$
                                – Unrelated String
                                6 hours ago




                                $begingroup$
                                Although I do feel like this may not actually be a full answer, since any single independent invocation of this predicate will just generate zeroes, with the "generate all" part being done by the or the in the header.
                                $endgroup$
                                – Unrelated String
                                6 hours ago




                                1




                                1




                                $begingroup$
                                @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                $endgroup$
                                – ais523
                                3 hours ago




                                $begingroup$
                                @UnrelatedString Your code doesn't use the predicate as a generator, though. We have explicit rules allowing list output using a generator. What you're doing in your TIO link is calling the predicate in a loop to get 1000 different generators, then taking the first output from each of them; that's a really unnatural operation to do on generators, and it won't let you see the other elements that they can generate.
                                $endgroup$
                                – ais523
                                3 hours ago












                                $begingroup$
                                Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                $endgroup$
                                – Unrelated String
                                1 hour ago





                                $begingroup$
                                Ah, so I've just been misinterpreting the semantics of what a Brachylog predicate is this whole time--my idea of "generator" is stuck on Python. Now that that's straight in my head I guess I'll go shave three bytes off of some of my old answers.
                                $endgroup$
                                – Unrelated String
                                1 hour ago












                                1












                                $begingroup$


                                Jelly, 10 (9?) bytes



                                9 if we may output using non-consistent separation (which I have enquired about) -- removal of the .



                                ‘ɼṗ³ċƇ®Ṅ€ß


                                Try it online!



                                How?



                                ‘ɼṗ³ċƇ®Ṅ€ß - Main Link: some argument, x (initially equal to n, but unused)
                                ɼ - recall v from the register (initially 0), then set register to, and yield, f(v)
                                ‘ - f = increment
                                - (i.e. v=v+1)
                                ³ - program's third command line argument (1st program argument) = n
                                ṗ - (implicit range of [1..v]) Cartesian power (n)
                                - (i.e. all tuples of length n with items in [1..v])
                                Ƈ - filter keep those for which:
                                ċ - count
                                ® - recall from register
                                - (i.e. keep only those containing v)
                                Ṅ€ - print €ach
                                ß - call this Link with the same arity
                                - (i.e. call Main(theFilteredList), again the argument is not actually used)





                                share|improve this answer











                                $endgroup$








                                • 1




                                  $begingroup$
                                  Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  8 hours ago















                                1












                                $begingroup$


                                Jelly, 10 (9?) bytes



                                9 if we may output using non-consistent separation (which I have enquired about) -- removal of the .



                                ‘ɼṗ³ċƇ®Ṅ€ß


                                Try it online!



                                How?



                                ‘ɼṗ³ċƇ®Ṅ€ß - Main Link: some argument, x (initially equal to n, but unused)
                                ɼ - recall v from the register (initially 0), then set register to, and yield, f(v)
                                ‘ - f = increment
                                - (i.e. v=v+1)
                                ³ - program's third command line argument (1st program argument) = n
                                ṗ - (implicit range of [1..v]) Cartesian power (n)
                                - (i.e. all tuples of length n with items in [1..v])
                                Ƈ - filter keep those for which:
                                ċ - count
                                ® - recall from register
                                - (i.e. keep only those containing v)
                                Ṅ€ - print €ach
                                ß - call this Link with the same arity
                                - (i.e. call Main(theFilteredList), again the argument is not actually used)





                                share|improve this answer











                                $endgroup$








                                • 1




                                  $begingroup$
                                  Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  8 hours ago













                                1












                                1








                                1





                                $begingroup$


                                Jelly, 10 (9?) bytes



                                9 if we may output using non-consistent separation (which I have enquired about) -- removal of the .



                                ‘ɼṗ³ċƇ®Ṅ€ß


                                Try it online!



                                How?



                                ‘ɼṗ³ċƇ®Ṅ€ß - Main Link: some argument, x (initially equal to n, but unused)
                                ɼ - recall v from the register (initially 0), then set register to, and yield, f(v)
                                ‘ - f = increment
                                - (i.e. v=v+1)
                                ³ - program's third command line argument (1st program argument) = n
                                ṗ - (implicit range of [1..v]) Cartesian power (n)
                                - (i.e. all tuples of length n with items in [1..v])
                                Ƈ - filter keep those for which:
                                ċ - count
                                ® - recall from register
                                - (i.e. keep only those containing v)
                                Ṅ€ - print €ach
                                ß - call this Link with the same arity
                                - (i.e. call Main(theFilteredList), again the argument is not actually used)





                                share|improve this answer











                                $endgroup$




                                Jelly, 10 (9?) bytes



                                9 if we may output using non-consistent separation (which I have enquired about) -- removal of the .



                                ‘ɼṗ³ċƇ®Ṅ€ß


                                Try it online!



                                How?



                                ‘ɼṗ³ċƇ®Ṅ€ß - Main Link: some argument, x (initially equal to n, but unused)
                                ɼ - recall v from the register (initially 0), then set register to, and yield, f(v)
                                ‘ - f = increment
                                - (i.e. v=v+1)
                                ³ - program's third command line argument (1st program argument) = n
                                ṗ - (implicit range of [1..v]) Cartesian power (n)
                                - (i.e. all tuples of length n with items in [1..v])
                                Ƈ - filter keep those for which:
                                ċ - count
                                ® - recall from register
                                - (i.e. keep only those containing v)
                                Ṅ€ - print €ach
                                ß - call this Link with the same arity
                                - (i.e. call Main(theFilteredList), again the argument is not actually used)






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 8 hours ago

























                                answered 8 hours ago









                                Jonathan AllanJonathan Allan

                                54.4k537174




                                54.4k537174







                                • 1




                                  $begingroup$
                                  Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  8 hours ago












                                • 1




                                  $begingroup$
                                  Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  8 hours ago







                                1




                                1




                                $begingroup$
                                Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                $endgroup$
                                – Kevin Cruijssen
                                8 hours ago




                                $begingroup$
                                Based on "as long as the separation between tuples and numbers inside each tuple is clear and consistent. (For example, one tuple per line.)" I assumed it wasn't allowed and the is required, but let's wait what OP has to say.
                                $endgroup$
                                – Kevin Cruijssen
                                8 hours ago











                                1












                                $begingroup$


                                05AB1E, 15 11 bytes



                                [¼¾LIãvy¾å—


                                -4 bytes by creating a port of @Maltysen's Pyth answer.



                                Try it online.



                                Explanation:





                                [ # Start an infinite loop:
                                ¼ # Increase the counter_variable by 1 (0 by default)
                                ¾L # Create a list in the range [1, counter_variable]
                                Iã # Take the cartesian power of this list with the input
                                v # Loop over each list `y` in this list of lists:
                                y¾å # If list `y` contains the counter_variable:
                                — # Print list `y` with trailing newline





                                share|improve this answer











                                $endgroup$








                                • 2




                                  $begingroup$
                                  When will the program get to [1,2,1]? Remember it has to be within finite time.
                                  $endgroup$
                                  – billpg
                                  13 hours ago










                                • $begingroup$
                                  @billpg Should be fixed now.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  11 hours ago















                                1












                                $begingroup$


                                05AB1E, 15 11 bytes



                                [¼¾LIãvy¾å—


                                -4 bytes by creating a port of @Maltysen's Pyth answer.



                                Try it online.



                                Explanation:





                                [ # Start an infinite loop:
                                ¼ # Increase the counter_variable by 1 (0 by default)
                                ¾L # Create a list in the range [1, counter_variable]
                                Iã # Take the cartesian power of this list with the input
                                v # Loop over each list `y` in this list of lists:
                                y¾å # If list `y` contains the counter_variable:
                                — # Print list `y` with trailing newline





                                share|improve this answer











                                $endgroup$








                                • 2




                                  $begingroup$
                                  When will the program get to [1,2,1]? Remember it has to be within finite time.
                                  $endgroup$
                                  – billpg
                                  13 hours ago










                                • $begingroup$
                                  @billpg Should be fixed now.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  11 hours ago













                                1












                                1








                                1





                                $begingroup$


                                05AB1E, 15 11 bytes



                                [¼¾LIãvy¾å—


                                -4 bytes by creating a port of @Maltysen's Pyth answer.



                                Try it online.



                                Explanation:





                                [ # Start an infinite loop:
                                ¼ # Increase the counter_variable by 1 (0 by default)
                                ¾L # Create a list in the range [1, counter_variable]
                                Iã # Take the cartesian power of this list with the input
                                v # Loop over each list `y` in this list of lists:
                                y¾å # If list `y` contains the counter_variable:
                                — # Print list `y` with trailing newline





                                share|improve this answer











                                $endgroup$




                                05AB1E, 15 11 bytes



                                [¼¾LIãvy¾å—


                                -4 bytes by creating a port of @Maltysen's Pyth answer.



                                Try it online.



                                Explanation:





                                [ # Start an infinite loop:
                                ¼ # Increase the counter_variable by 1 (0 by default)
                                ¾L # Create a list in the range [1, counter_variable]
                                Iã # Take the cartesian power of this list with the input
                                v # Loop over each list `y` in this list of lists:
                                y¾å # If list `y` contains the counter_variable:
                                — # Print list `y` with trailing newline






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 7 hours ago

























                                answered 13 hours ago









                                Kevin CruijssenKevin Cruijssen

                                42.9k571217




                                42.9k571217







                                • 2




                                  $begingroup$
                                  When will the program get to [1,2,1]? Remember it has to be within finite time.
                                  $endgroup$
                                  – billpg
                                  13 hours ago










                                • $begingroup$
                                  @billpg Should be fixed now.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  11 hours ago












                                • 2




                                  $begingroup$
                                  When will the program get to [1,2,1]? Remember it has to be within finite time.
                                  $endgroup$
                                  – billpg
                                  13 hours ago










                                • $begingroup$
                                  @billpg Should be fixed now.
                                  $endgroup$
                                  – Kevin Cruijssen
                                  11 hours ago







                                2




                                2




                                $begingroup$
                                When will the program get to [1,2,1]? Remember it has to be within finite time.
                                $endgroup$
                                – billpg
                                13 hours ago




                                $begingroup$
                                When will the program get to [1,2,1]? Remember it has to be within finite time.
                                $endgroup$
                                – billpg
                                13 hours ago












                                $begingroup$
                                @billpg Should be fixed now.
                                $endgroup$
                                – Kevin Cruijssen
                                11 hours ago




                                $begingroup$
                                @billpg Should be fixed now.
                                $endgroup$
                                – Kevin Cruijssen
                                11 hours ago











                                1












                                $begingroup$


                                Haskell, 50 bytes





                                f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]


                                Try it online!



                                Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The <$f trick is explained here.




                                Haskell, 51 bytes





                                f 1=pure<$>[0..]
                                f n=[a-k:k:t|a:t<-f$n-1,k<-[0..a]]


                                Try it online!



                                Recursively stretches all n-1-tuples into all n-tuples by splitting the first number a of each n-1-tuple into two numbers a-k,k that sum to it, in every possible way.






                                share|improve this answer









                                $endgroup$

















                                  1












                                  $begingroup$


                                  Haskell, 50 bytes





                                  f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]


                                  Try it online!



                                  Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The <$f trick is explained here.




                                  Haskell, 51 bytes





                                  f 1=pure<$>[0..]
                                  f n=[a-k:k:t|a:t<-f$n-1,k<-[0..a]]


                                  Try it online!



                                  Recursively stretches all n-1-tuples into all n-tuples by splitting the first number a of each n-1-tuple into two numbers a-k,k that sum to it, in every possible way.






                                  share|improve this answer









                                  $endgroup$















                                    1












                                    1








                                    1





                                    $begingroup$


                                    Haskell, 50 bytes





                                    f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]


                                    Try it online!



                                    Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The <$f trick is explained here.




                                    Haskell, 51 bytes





                                    f 1=pure<$>[0..]
                                    f n=[a-k:k:t|a:t<-f$n-1,k<-[0..a]]


                                    Try it online!



                                    Recursively stretches all n-1-tuples into all n-tuples by splitting the first number a of each n-1-tuple into two numbers a-k,k that sum to it, in every possible way.






                                    share|improve this answer









                                    $endgroup$




                                    Haskell, 50 bytes





                                    f n=[l|k<-[0..],l<-mapM([0..k]<$f)[0..n],sum l==k]


                                    Try it online!



                                    Lists n-tuples sorted by sum. mapM does the heavy lifting to generate all n-tuples of numbers from 0 to k. The <$f trick is explained here.




                                    Haskell, 51 bytes





                                    f 1=pure<$>[0..]
                                    f n=[a-k:k:t|a:t<-f$n-1,k<-[0..a]]


                                    Try it online!



                                    Recursively stretches all n-1-tuples into all n-tuples by splitting the first number a of each n-1-tuple into two numbers a-k,k that sum to it, in every possible way.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 1 hour ago









                                    xnorxnor

                                    94.1k18192451




                                    94.1k18192451





















                                        0












                                        $begingroup$


                                        VDM-SL, 51 bytes



                                        g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                        Recursive set comprehension with sequence concatenation..



                                        Not on TIO, you could run in a program (if you turn on limits for nat type or it wont terminate):



                                        functions 
                                        g:nat->set of ?
                                        g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                        Includes the optional 0s in answer otherwise it would be 52 bytes binding on nat1






                                        share|improve this answer









                                        $endgroup$

















                                          0












                                          $begingroup$


                                          VDM-SL, 51 bytes



                                          g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                          Recursive set comprehension with sequence concatenation..



                                          Not on TIO, you could run in a program (if you turn on limits for nat type or it wont terminate):



                                          functions 
                                          g:nat->set of ?
                                          g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                          Includes the optional 0s in answer otherwise it would be 52 bytes binding on nat1






                                          share|improve this answer









                                          $endgroup$















                                            0












                                            0








                                            0





                                            $begingroup$


                                            VDM-SL, 51 bytes



                                            g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                            Recursive set comprehension with sequence concatenation..



                                            Not on TIO, you could run in a program (if you turn on limits for nat type or it wont terminate):



                                            functions 
                                            g:nat->set of ?
                                            g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                            Includes the optional 0s in answer otherwise it would be 52 bytes binding on nat1






                                            share|improve this answer









                                            $endgroup$




                                            VDM-SL, 51 bytes



                                            g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                            Recursive set comprehension with sequence concatenation..



                                            Not on TIO, you could run in a program (if you turn on limits for nat type or it wont terminate):



                                            functions 
                                            g:nat->set of ?
                                            g(i)==if i=0thenelsex:nat,y in set g(i-1)


                                            Includes the optional 0s in answer otherwise it would be 52 bytes binding on nat1







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered 11 hours ago









                                            Expired DataExpired Data

                                            948217




                                            948217





















                                                0












                                                $begingroup$


                                                MATL, 16 bytes



                                                `@:GZ^t!Xs@=Y)DT


                                                Tuples are ordered by increasing sum, and within a given sum they are ordered lexicographically.



                                                Try it online!






                                                share|improve this answer











                                                $endgroup$












                                                • $begingroup$
                                                  You are supposed to take input
                                                  $endgroup$
                                                  – H.PWiz
                                                  10 hours ago










                                                • $begingroup$
                                                  @H.PWiz Thanks. I got it wrong
                                                  $endgroup$
                                                  – Luis Mendo
                                                  9 hours ago










                                                • $begingroup$
                                                  @H.PWiz Solved now
                                                  $endgroup$
                                                  – Luis Mendo
                                                  6 hours ago















                                                0












                                                $begingroup$


                                                MATL, 16 bytes



                                                `@:GZ^t!Xs@=Y)DT


                                                Tuples are ordered by increasing sum, and within a given sum they are ordered lexicographically.



                                                Try it online!






                                                share|improve this answer











                                                $endgroup$












                                                • $begingroup$
                                                  You are supposed to take input
                                                  $endgroup$
                                                  – H.PWiz
                                                  10 hours ago










                                                • $begingroup$
                                                  @H.PWiz Thanks. I got it wrong
                                                  $endgroup$
                                                  – Luis Mendo
                                                  9 hours ago










                                                • $begingroup$
                                                  @H.PWiz Solved now
                                                  $endgroup$
                                                  – Luis Mendo
                                                  6 hours ago













                                                0












                                                0








                                                0





                                                $begingroup$


                                                MATL, 16 bytes



                                                `@:GZ^t!Xs@=Y)DT


                                                Tuples are ordered by increasing sum, and within a given sum they are ordered lexicographically.



                                                Try it online!






                                                share|improve this answer











                                                $endgroup$




                                                MATL, 16 bytes



                                                `@:GZ^t!Xs@=Y)DT


                                                Tuples are ordered by increasing sum, and within a given sum they are ordered lexicographically.



                                                Try it online!







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 6 hours ago

























                                                answered 10 hours ago









                                                Luis MendoLuis Mendo

                                                75.3k889292




                                                75.3k889292











                                                • $begingroup$
                                                  You are supposed to take input
                                                  $endgroup$
                                                  – H.PWiz
                                                  10 hours ago










                                                • $begingroup$
                                                  @H.PWiz Thanks. I got it wrong
                                                  $endgroup$
                                                  – Luis Mendo
                                                  9 hours ago










                                                • $begingroup$
                                                  @H.PWiz Solved now
                                                  $endgroup$
                                                  – Luis Mendo
                                                  6 hours ago
















                                                • $begingroup$
                                                  You are supposed to take input
                                                  $endgroup$
                                                  – H.PWiz
                                                  10 hours ago










                                                • $begingroup$
                                                  @H.PWiz Thanks. I got it wrong
                                                  $endgroup$
                                                  – Luis Mendo
                                                  9 hours ago










                                                • $begingroup$
                                                  @H.PWiz Solved now
                                                  $endgroup$
                                                  – Luis Mendo
                                                  6 hours ago















                                                $begingroup$
                                                You are supposed to take input
                                                $endgroup$
                                                – H.PWiz
                                                10 hours ago




                                                $begingroup$
                                                You are supposed to take input
                                                $endgroup$
                                                – H.PWiz
                                                10 hours ago












                                                $begingroup$
                                                @H.PWiz Thanks. I got it wrong
                                                $endgroup$
                                                – Luis Mendo
                                                9 hours ago




                                                $begingroup$
                                                @H.PWiz Thanks. I got it wrong
                                                $endgroup$
                                                – Luis Mendo
                                                9 hours ago












                                                $begingroup$
                                                @H.PWiz Solved now
                                                $endgroup$
                                                – Luis Mendo
                                                6 hours ago




                                                $begingroup$
                                                @H.PWiz Solved now
                                                $endgroup$
                                                – Luis Mendo
                                                6 hours ago











                                                0












                                                $begingroup$


                                                Wolfram Language (Mathematica), 131 bytes



                                                While[0<1,If[a~FreeQ~#,Print@#]&/@(b=Table[Select[Range@t~Tuples~s,Tr@#==k&],k,t,t(s=#)]~Flatten~1);a=a~Join~b;t++]&
                                                t=1
                                                a=


                                                Try it online!






                                                share|improve this answer











                                                $endgroup$

















                                                  0












                                                  $begingroup$


                                                  Wolfram Language (Mathematica), 131 bytes



                                                  While[0<1,If[a~FreeQ~#,Print@#]&/@(b=Table[Select[Range@t~Tuples~s,Tr@#==k&],k,t,t(s=#)]~Flatten~1);a=a~Join~b;t++]&
                                                  t=1
                                                  a=


                                                  Try it online!






                                                  share|improve this answer











                                                  $endgroup$















                                                    0












                                                    0








                                                    0





                                                    $begingroup$


                                                    Wolfram Language (Mathematica), 131 bytes



                                                    While[0<1,If[a~FreeQ~#,Print@#]&/@(b=Table[Select[Range@t~Tuples~s,Tr@#==k&],k,t,t(s=#)]~Flatten~1);a=a~Join~b;t++]&
                                                    t=1
                                                    a=


                                                    Try it online!






                                                    share|improve this answer











                                                    $endgroup$




                                                    Wolfram Language (Mathematica), 131 bytes



                                                    While[0<1,If[a~FreeQ~#,Print@#]&/@(b=Table[Select[Range@t~Tuples~s,Tr@#==k&],k,t,t(s=#)]~Flatten~1);a=a~Join~b;t++]&
                                                    t=1
                                                    a=


                                                    Try it online!







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited 4 hours ago

























                                                    answered 6 hours ago









                                                    J42161217J42161217

                                                    14k21353




                                                    14k21353





















                                                        0












                                                        $begingroup$

                                                        perl -M5.010 122 bytes



                                                        $n=shift;
                                                        $s.="for$x$_(1..$m)"for 1..$n;
                                                        $t.="$x$_ "for 1..$n;
                                                        $u.=''x$n;
                                                        eval"$m++;$s$_=qq' $t';/ $
                                                        m /&&say$u;redo"


                                                        Added some newlines for readabilities sake (not counted in the byte count)






                                                        share|improve this answer











                                                        $endgroup$

















                                                          0












                                                          $begingroup$

                                                          perl -M5.010 122 bytes



                                                          $n=shift;
                                                          $s.="for$x$_(1..$m)"for 1..$n;
                                                          $t.="$x$_ "for 1..$n;
                                                          $u.=''x$n;
                                                          eval"$m++;$s$_=qq' $t';/ $
                                                          m /&&say$u;redo"


                                                          Added some newlines for readabilities sake (not counted in the byte count)






                                                          share|improve this answer











                                                          $endgroup$















                                                            0












                                                            0








                                                            0





                                                            $begingroup$

                                                            perl -M5.010 122 bytes



                                                            $n=shift;
                                                            $s.="for$x$_(1..$m)"for 1..$n;
                                                            $t.="$x$_ "for 1..$n;
                                                            $u.=''x$n;
                                                            eval"$m++;$s$_=qq' $t';/ $
                                                            m /&&say$u;redo"


                                                            Added some newlines for readabilities sake (not counted in the byte count)






                                                            share|improve this answer











                                                            $endgroup$



                                                            perl -M5.010 122 bytes



                                                            $n=shift;
                                                            $s.="for$x$_(1..$m)"for 1..$n;
                                                            $t.="$x$_ "for 1..$n;
                                                            $u.=''x$n;
                                                            eval"$m++;$s$_=qq' $t';/ $
                                                            m /&&say$u;redo"


                                                            Added some newlines for readabilities sake (not counted in the byte count)







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited 2 hours ago

























                                                            answered 3 hours ago









                                                            AbigailAbigail

                                                            46617




                                                            46617





















                                                                0












                                                                $begingroup$


                                                                Wolfram Language (Mathematica), 62 bytes



                                                                Do[Print/@Permutations@#&/@n~IntegerPartitions~#,n,#,∞]&


                                                                Try it online!




                                                                -3 bytes with inconsistent separation (delete @#&)



                                                                Try it online!






                                                                share|improve this answer









                                                                $endgroup$

















                                                                  0












                                                                  $begingroup$


                                                                  Wolfram Language (Mathematica), 62 bytes



                                                                  Do[Print/@Permutations@#&/@n~IntegerPartitions~#,n,#,∞]&


                                                                  Try it online!




                                                                  -3 bytes with inconsistent separation (delete @#&)



                                                                  Try it online!






                                                                  share|improve this answer









                                                                  $endgroup$















                                                                    0












                                                                    0








                                                                    0





                                                                    $begingroup$


                                                                    Wolfram Language (Mathematica), 62 bytes



                                                                    Do[Print/@Permutations@#&/@n~IntegerPartitions~#,n,#,∞]&


                                                                    Try it online!




                                                                    -3 bytes with inconsistent separation (delete @#&)



                                                                    Try it online!






                                                                    share|improve this answer









                                                                    $endgroup$




                                                                    Wolfram Language (Mathematica), 62 bytes



                                                                    Do[Print/@Permutations@#&/@n~IntegerPartitions~#,n,#,∞]&


                                                                    Try it online!




                                                                    -3 bytes with inconsistent separation (delete @#&)



                                                                    Try it online!







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered 2 hours ago









                                                                    attinatattinat

                                                                    5597




                                                                    5597





















                                                                        0












                                                                        $begingroup$


                                                                        Python 2, 126 112 106 101 bytes





                                                                        n=input()
                                                                        i=0;p=1
                                                                        while 1:
                                                                        b=map(len,bin(i+p)[3:].split('0'));i=-~i%p;p<<=i<1
                                                                        if len(b)==n:print b


                                                                        Try it online!



                                                                        5 bytes thx to mypetlion



                                                                        Construct the ordered partitions of m into n bins, for m = 0,1,2,3,... by selecting for binary numbers with n-1 0s and m 1s.






                                                                        share|improve this answer











                                                                        $endgroup$












                                                                        • $begingroup$
                                                                          if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                          $endgroup$
                                                                          – mypetlion
                                                                          4 hours ago















                                                                        0












                                                                        $begingroup$


                                                                        Python 2, 126 112 106 101 bytes





                                                                        n=input()
                                                                        i=0;p=1
                                                                        while 1:
                                                                        b=map(len,bin(i+p)[3:].split('0'));i=-~i%p;p<<=i<1
                                                                        if len(b)==n:print b


                                                                        Try it online!



                                                                        5 bytes thx to mypetlion



                                                                        Construct the ordered partitions of m into n bins, for m = 0,1,2,3,... by selecting for binary numbers with n-1 0s and m 1s.






                                                                        share|improve this answer











                                                                        $endgroup$












                                                                        • $begingroup$
                                                                          if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                          $endgroup$
                                                                          – mypetlion
                                                                          4 hours ago













                                                                        0












                                                                        0








                                                                        0





                                                                        $begingroup$


                                                                        Python 2, 126 112 106 101 bytes





                                                                        n=input()
                                                                        i=0;p=1
                                                                        while 1:
                                                                        b=map(len,bin(i+p)[3:].split('0'));i=-~i%p;p<<=i<1
                                                                        if len(b)==n:print b


                                                                        Try it online!



                                                                        5 bytes thx to mypetlion



                                                                        Construct the ordered partitions of m into n bins, for m = 0,1,2,3,... by selecting for binary numbers with n-1 0s and m 1s.






                                                                        share|improve this answer











                                                                        $endgroup$




                                                                        Python 2, 126 112 106 101 bytes





                                                                        n=input()
                                                                        i=0;p=1
                                                                        while 1:
                                                                        b=map(len,bin(i+p)[3:].split('0'));i=-~i%p;p<<=i<1
                                                                        if len(b)==n:print b


                                                                        Try it online!



                                                                        5 bytes thx to mypetlion



                                                                        Construct the ordered partitions of m into n bins, for m = 0,1,2,3,... by selecting for binary numbers with n-1 0s and m 1s.







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited 2 hours ago

























                                                                        answered 6 hours ago









                                                                        Chas BrownChas Brown

                                                                        5,2291523




                                                                        5,2291523











                                                                        • $begingroup$
                                                                          if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                          $endgroup$
                                                                          – mypetlion
                                                                          4 hours ago
















                                                                        • $begingroup$
                                                                          if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                          $endgroup$
                                                                          – mypetlion
                                                                          4 hours ago















                                                                        $begingroup$
                                                                        if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                        $endgroup$
                                                                        – mypetlion
                                                                        4 hours ago




                                                                        $begingroup$
                                                                        if i==p:i=0;p*=2 can become i%=p;p<<=i<1 to save 5 bytes.
                                                                        $endgroup$
                                                                        – mypetlion
                                                                        4 hours ago











                                                                        -2












                                                                        $begingroup$

                                                                        Python3 (56 characters)



                                                                        This runs, but never outputs/returns any values, because the permutations function keeps pulling numbers from count. But in theory, this would return the requested permutations.



                                                                        from itertools import*
                                                                        lambda n:permutations(count(1),n)


                                                                        Proof that this works for limited integer range:



                                                                        from itertools import*
                                                                        l = lambda n: permutations(range(1, 10), n)
                                                                        print(list(l(3))) # returns all permutations of (1, 2, 3, ..., 10) of length 3





                                                                        share|improve this answer









                                                                        $endgroup$








                                                                        • 1




                                                                          $begingroup$
                                                                          This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                          $endgroup$
                                                                          – alexis
                                                                          6 hours ago















                                                                        -2












                                                                        $begingroup$

                                                                        Python3 (56 characters)



                                                                        This runs, but never outputs/returns any values, because the permutations function keeps pulling numbers from count. But in theory, this would return the requested permutations.



                                                                        from itertools import*
                                                                        lambda n:permutations(count(1),n)


                                                                        Proof that this works for limited integer range:



                                                                        from itertools import*
                                                                        l = lambda n: permutations(range(1, 10), n)
                                                                        print(list(l(3))) # returns all permutations of (1, 2, 3, ..., 10) of length 3





                                                                        share|improve this answer









                                                                        $endgroup$








                                                                        • 1




                                                                          $begingroup$
                                                                          This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                          $endgroup$
                                                                          – alexis
                                                                          6 hours ago













                                                                        -2












                                                                        -2








                                                                        -2





                                                                        $begingroup$

                                                                        Python3 (56 characters)



                                                                        This runs, but never outputs/returns any values, because the permutations function keeps pulling numbers from count. But in theory, this would return the requested permutations.



                                                                        from itertools import*
                                                                        lambda n:permutations(count(1),n)


                                                                        Proof that this works for limited integer range:



                                                                        from itertools import*
                                                                        l = lambda n: permutations(range(1, 10), n)
                                                                        print(list(l(3))) # returns all permutations of (1, 2, 3, ..., 10) of length 3





                                                                        share|improve this answer









                                                                        $endgroup$



                                                                        Python3 (56 characters)



                                                                        This runs, but never outputs/returns any values, because the permutations function keeps pulling numbers from count. But in theory, this would return the requested permutations.



                                                                        from itertools import*
                                                                        lambda n:permutations(count(1),n)


                                                                        Proof that this works for limited integer range:



                                                                        from itertools import*
                                                                        l = lambda n: permutations(range(1, 10), n)
                                                                        print(list(l(3))) # returns all permutations of (1, 2, 3, ..., 10) of length 3






                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered 6 hours ago









                                                                        agtoeveragtoever

                                                                        1,410425




                                                                        1,410425







                                                                        • 1




                                                                          $begingroup$
                                                                          This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                          $endgroup$
                                                                          – alexis
                                                                          6 hours ago












                                                                        • 1




                                                                          $begingroup$
                                                                          This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                          $endgroup$
                                                                          – alexis
                                                                          6 hours ago







                                                                        1




                                                                        1




                                                                        $begingroup$
                                                                        This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                        $endgroup$
                                                                        – alexis
                                                                        6 hours ago




                                                                        $begingroup$
                                                                        This is not a solution :-( The last element of the tuple will increase forever, so the other elements will never be reached. ("After infinity" does not count.) Also you never visit (1,1,1), etc., even in the demo case.
                                                                        $endgroup$
                                                                        – alexis
                                                                        6 hours ago

















                                                                        draft saved

                                                                        draft discarded
















































                                                                        If this is an answer to a challenge…



                                                                        • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                        • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                          Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                        • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                                                        More generally…



                                                                        • …Please make sure to answer the question and provide sufficient detail.


                                                                        • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function ()
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f183225%2flist-all-the-tuples%23new-answer', 'question_page');

                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        -code-golf, sequence

                                                                        Popular posts from this blog

                                                                        Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

                                                                        What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?

                                                                        Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?