Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make a new list of strings from another list based on certain criteria?
    primarykey
    data
    text
    <p>That's the best way I could think to ask the question, the detail is below. It's taken me an hour just to figure out how to ask the question!</p> <p>Let's say that I have 5 (or more) types of text files - they are generated by a scientific instrument and each has certain results. Let's call these "types" A, B, C, D, E. The actual names of the text files don't give this away so the user can't easily see what they are just by the name. If it makes it easier, we could just consider a list of "strings". { I have NO idea what to do about replcate types but I'll worry about that later)</p> <p>I wish to give the user the option to combine the text files into a conglomerate file but the challenge is, it doesn't make sense to combine certain types (for reasons that I don't feel it worthwhile to go into).</p> <p>I've constructed and example matrix of compatibility</p> <pre><code> A B C D E A 1 1 1 1 0 B 1 1 1 0 0 C 1 1 1 1 0 D 1 0 1 1 1 E 0 0 0 1 1 </code></pre> <p>So, this is saying that I could combine A with B, C, D but not E (and so on).</p> <p>Now if a user chooses files that have types "A, B and C" from a list of files (that aren't obviously typed) I would like to check the selections and say "yes, ABC is a legal merge" and perform the merge.</p> <p>If the user selects A,B,C,D, I would like to say, NO, you can't do that as D is not compatible with B - however, you could do A,B,C or A,C,D (as D should not be where B would be).</p> <p>Still with me?</p> <p>I created the above matrix in code and have got to a looping structure where I started to get a bit muddled and thought I might ask for some help before I find myself losing my home and family. I've got a fairly large comment section on how I'm trying to make choices. Remember that "A" could be "Dog" and "B" could be "Cat" etc.</p> <pre><code>internal class CompatibilityCheck { private List&lt;string&gt; FileTypes; public CompatibilityCheck() { //Strings are unique types for text files FileTypes = new List&lt;string&gt; {"A", "B", "C", "D", "E"}; int[,] CompatibilityMatrix = { {1, 1, 1, 1, 0}, {1, 1, 1, 0, 0}, {1, 1, 1, 1, 0}, {1, 0, 1, 1, 1}, {0, 0, 0, 1, 1} }; /* Scenario 1 */ //List of file names from user = ALL LEGAL var userSelection = new List&lt;string&gt; {"A", "B", "C"}; /* Go through each item in userSelection and make arrays of "legal" file combinations? * start with A and find the compatible matches, B and C. Check that B and C are okay. * Answer should look like this as A, B and C can be combined */ /* Scenario 2 */ // List of file names from user = NOT ALL LEGAL =&gt; D and B are incompatible var userSelection2 = new List&lt;string&gt; {"A", "B", "C", "D"}; /* In my head, I go through each item in userSelction2 * Take A and build "A,B,C,D" as it is compatible * check B with C(yes) and D(no) - remove D. * end [ A,B,C ] * * Start with B and build B,A,C * check A with C(yes) * end [ B,A,C ] * * Start with C and build C,A,B * check A with B(yes) * end [C,A,B] * * Start with D and build D,A,C * check A with C(yes) * end [D,A,C] * * take the nth string and compare to n+1, n+2 ... n+(length-n) * * the unique string sets woudld be A , B , C and A , C , D */ } } </code></pre> <p>I hope this is clear. So What is the best way to achieve such a task? Recursion, LINQ "Magic", matrix math?</p> <p>[EDIT:] An idea I just had that may be easier to implement, might be to Show a list of files and as a user selects them, I could "deactivate" the other choices that aren't compatible. Imagine a listBox or similar where you select an "A" type and if the above matrix is in play, type "E" files would be greyed out. I wonder if this will cause me less stress ...?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload