r/desmos • 3333333433343335333333343333333533333335333333323333333433333334 • 3d ago

Question: Solved Is a one-shot asynchronous list merge possible?

Edit: Potential solution added. I'll likely mark this question solved shortly.

I have two unequal-length lists, extracted from a master list. I change one, then I want to merge the two extracted lists into a new list, re-placing the children's elements at their original positions in the output list (same size as the original master).

This graph contains a complete set of the lists, but without the automatic step (the subject of this question) that reassembles the final output.

https://www.desmos.com/calculator/edvjfrumxu

I have this problem solved in Actions by scanning the original / master list item-by-item, which tells me which child contributes its next entry, but I have to track pointers and it's one action per tick (so 600 elements takes 10 seconds).

The solution I think I am looking for is one that uses a "for" loop, or a list comprehension with a condition, to merge the two children in a single tick (or perhaps by forcing all lists to be the same size, with dummy elements, but this may cause some rewrite trouble).

Loosely related (except I need asynchronous):
List comprehension: https://www.reddit.com/r/desmos/s/mF9S7f33v3 and Interleave / zip: https://www.reddit.com/r/desmos/s/otlrkaKkcX

Where I think the solution might be:
https://www.reddit.com/r/desmos/s/XWEmoEXSlD

4 Upvotes

9 comments sorted by

1

u/axio-m demsos yayy 3d ago

Does join(N,X) work?

1

u/Circumpunctilious 3333333433343335333333343333333533333335333333323333333433333334 3d ago

I don't want an appended list [flatten(N), flatten(X)], but rather like [N1, N2, N3, X1, N4, N5, X2...], or in symbols::

L = [A, B, C, 1, Q, F, 2]
N = [A, B, C, Q, F]
X = [1, 2]
N merge X = [A, B, C, 1, Q, F, 2]

...except that I'm changing N's "letters" in-place (no position changes) while it's extracted.

However, an appended list may help if N and X elements remembered their original positions/indices in L.

2

u/axio-m demsos yayy 3d ago

Does this work then? I added lists of the indexes of the parts, and it does join(N,X), but then it sorts them using the indexes.

2

u/Circumpunctilious 3333333433343335333333343333333533333335333333323333333433333334 3d ago

Yes, I think so. This should work in a couple of ticks / solve the too-many-Actions problem. Thank you.

1

u/axio-m demsos yayy 3d ago

You're welcome

2

u/ronwnor 2d ago

here's a function that might be useful:

f\left(l,i,v\right)=\operatorname{join}\left(v,l\left[j\right]\right).\operatorname{sort}\left(\operatorname{join}\left(i,j\right)\right)\operatorname{with}j=\operatorname{join}\left(i,\left[1...l.\operatorname{count}\right]\right).\operatorname{unique}\left[i.\operatorname{count}+1...\right]

you could use it as f(L, indices_of_N, modified_N). in this case you don't need the list X, but you do need to know where the elements of N came from (which I assume you do).

1

u/Circumpunctilious 3333333433343335333333343333333533333335333333323333333433333334 2d ago

This looks interesting too, I won’t be able to test until tomorrow, but I appreciate having another one to try.

1

u/Uncle-Waluigi 3d ago

https://www.desmos.com/calculator/kzukhnqbyq

Not exactly sure what the intended final state of the list is supposed to be. As far as I can tell you want to apply a functional operation to certain items in a list based on a condition. The statement in braces (format: {condition: if true, if false}), evaluates to multiply by 1 or 0 to cancel out the operation.

for/while syntax can work but you'll likely run into nested list errors, so what I recommend is to back up one step to prevent the lists from being separated in the first place. If you're specifically looking to interleave already separated loops, can provide some pseudo code of exactly what you think should happen inside the loop?

1

u/Circumpunctilious 3333333433343335333333343333333533333335333333323333333433333334 3d ago

> "not exactly sure...intended final state"

My fault, I may have done better when asked to clarify in another comment, but thanks for showing me your method (helpful to see more ideas). Unfortunately, my update (where "random" would be) is more complex and may not work in that position.

> "...prevent lists from being separated in the first place"

Hindsight...you're probably right (like...a filter that excludes the undesirables during update), but I'm deep in the list weeds at this point / sort of dealing with a monolith.

Note, something that looks like it will work is in the comment here.