P
P
PyChan2020-08-26 13:56:01
C++ / C#
PyChan, 2020-08-26 13:56:01

How to keep array changes after filtering with where?

There is code that takes a sequence and removes numbers that are divisors of larger numbers in that sequence (for example, if it has 2 and 4, then you need to remove 2). It is necessary for me that if let's say one is removed from the sequence, the next time the cycle already filters the sequence without one. But every time the same sequence is filtered. Help me please. Thanks in advance.

for (int del = 1; del <= number / 2; del++)
                {
                    Console.WriteLine("Del: " + del);
                    group = group.Where(x => x % del != 0);
                    Console.WriteLine(String.Join(" ", group));
                    
                }

An example of input and output. Let's say number=10.
after each passage through the loop:
Del: 1
2 3 4 5 6 7 8 9 10
Del: 2
3 4 5 6 7 8 9 10
etc. until del=5
That is, in fact, it should remove the first 5 numbers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-08-26
@PyChan

group = group.Where(x => x % del != 0).ToList();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question