Post Reply 
How to write a program to output multiple results
10-26-2020, 12:49 PM
Post: #6
RE: How to write a program to output multiple results
(10-26-2020 10:27 AM)pinkman Wrote:  ret := CONCAT(ret, c);

CONCAT builds a new list, combining ret and c, using time of O(len(ret) + len(c))
We might speed it up by building nest-list, then flatten it.

ret := {{}}; // list of list
...
ret[0] := {ret[0], c}; // inplace update, not building long list (assumed 0-based indexing)
...
return flatten(ret);

Example:
XCas> lst := [[]]
XCas> lst[0] := [lst[0], [1,2,3]]
XCas> lst[0] := [lst[0], [4,5,6]]
XCas> flatten(lst)

[1,2,3,4,5,6]
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How to write a program to output multiple results - Albert Chan - 10-26-2020 12:49 PM



User(s) browsing this thread: 3 Guest(s)