You will be given as input an infinite stream of positive integers.
Your task is to write a program which outputs an infinite sequence of lists with two requirements:
- All lists in the output are finite sub-lists of the input stream.
- Every sub-list must be output eventually by your program.
Sub-lists are not necessarily contiguous, so [1,1]
is a sub-list of [0,1,0,1,0,...
, and should be included in your output if your input was [0,1,0,1,0,...
.
The empty list []
is a sub-list of every possible input, so it should always be output at some point.
Aside from this, you can do what you want. You can output them in whatever order suits you, you can output any sub-list any (positive) number of times. It's up to you to figure out what's best.
This is code-golf so answers will be scored in bytes with fewer bytes being the goal.
IO
Outputting an infinite sequence is done as per the defaults of the sequence tag wiki.
Input of an infinite sequence is basically the dual of those rules. You may:
- Take the input as a black-box function which takes \$n\$ and outputs the \$n\$th term
- Take the input as a black-box function which takes \$n\$ and outputs all terms up to the \$n\$th term
- Take the input as a lazy list, generator or stream.
- Take the input by repeatedly querying STDIN each time receiving the next term of the sequence.
[3,2,1]
a sublist of[1,2,3...
, and if so, are [1,2,3] and [3,2,1] both required outputs? etc \$\endgroup\$