Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.9K Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Can list be a loop counter?

Posted 10 years ago

Hello, Community! A problem: there is a list (counted before, not to be count in parallel with next step), now it's a base for next step of computation. I need to take one element of a list (its place is important) and use it to compute a sublist of the first list. Then exclude this sublist from the first list, and take new element (of a new shorter list), compute new sublist... Repeate a loop till the first list becomes {}. If a loop counter is a number - all is OK: increments ++,-- work good. But when i try list as a loop counter and decrease it by Complement - have a problem. First i did it by hands - in one notebook count sublist, in second - exclude it from first list, take this result to the first notebook and so on. Example - see attached file

Attachments:
6 Replies

Hello, Otto (thanx for your interest) - i change a description of a problem, hope now it's more understandable.

Hello, Henrik! Your questions help me to understand what i want (thanx) - need to change the base list inside the loop many times with some (not changing) operations. Another attempt - see attached file

Attachments:
POSTED BY: Henrik Schachner

Very well, it works! Thanks a lot!!!

Hi Ampo,

I am not sure: Could this be a minimal example of what you are intending?

ClearAll["Global`*"]

a = Range[10];
result = Reap[While[Length[a] > 1,
     (* calculation of a specific index, e.g.: *)
     fIndx = 1 + Ceiling[(Length[a] - 1) Abs[Sin[Length[a]]]];
     (* calculation of depending sublist: *)
     subA = RandomSample[Range[fIndx], 2];
     (* removing elements of sublist from list: *)
     a = Complement[a, a[[subA]]];
     Sow[a]]][[2, 1]];

result // TableForm

Regards -- Henrik

POSTED BY: Henrik Schachner

Hello Podchufarov,

I would like to contribute, but I find the description hard to follow. Could you try to clarify? For example, you say that you take an element of a list (at random?) and use it to compute (by calling an existing function) a sublist of a list (of a different list or of the same one?).

Also, could you be more specific about the sizes of the lists? One could come up with something that works fine for a list of 10 elements, but that crashes on a list of 80K elements.

Thanks,

OL.

POSTED BY: Otto Linsuain
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard