Note that there are some explanatory texts on larger screens.

plurals
  1. POComparing lists of integers and then ordering them based on similarity.
    primarykey
    data
    text
    <p>I have a list of players that each contain a list of skill ratings. What I am trying to do is order those players based on the ratings matched to a specific search list.</p> <p>Here is an example of four players:</p> <pre><code> List&lt;Skill&gt; skillsA = new List&lt;Skill&gt;(); List&lt;Skill&gt; skillsB = new List&lt;Skill&gt;(); List&lt;Skill&gt; skillsC = new List&lt;Skill&gt;(); List&lt;Skill&gt; skillsD = new List&lt;Skill&gt;(); skillsA.Add(new Skill() { Name = "Speed", Value = 1 }); skillsA.Add(new Skill() { Name = "Agility", Value = 5 }); skillsA.Add(new Skill() { Name = "Strength", Value = 3 }); skillsA.Add(new Skill() { Name = "Endurance", Value = 4 }); skillsB.Add(new Skill() { Name = "Speed", Value = 5 }); skillsB.Add(new Skill() { Name = "Agility", Value = 2 }); skillsB.Add(new Skill() { Name = "Strength", Value = 1 }); skillsB.Add(new Skill() { Name = "Endurance", Value = 3 }); skillsC.Add(new Skill() { Name = "Speed", Value = 5 }); skillsC.Add(new Skill() { Name = "Agility", Value = 3 }); skillsC.Add(new Skill() { Name = "Strength", Value = 2 }); skillsC.Add(new Skill() { Name = "Endurance", Value = 2 }); skillsD.Add(new Skill() { Name = "Speed", Value = 1 }); skillsD.Add(new Skill() { Name = "Agility", Value = 2 }); skillsD.Add(new Skill() { Name = "Strength", Value = 5 }); skillsD.Add(new Skill() { Name = "Endurance", Value = 4 }); Player A = new Player() { Skills = skillsA }; Player B = new Player() { Skills = skillsB }; Player C = new Player() { Skills = skillsC }; Player D = new Player() { Skills = skillsD }; </code></pre> <p>This would be the search list I compare to:</p> <pre><code> List&lt;Skill&gt; matchSkill = new List&lt;Skill&gt;(); matchSkill.Add(new Skill() { Name = "Speed", Value = 5 }); matchSkill.Add(new Skill() { Name = "Agility", Value = 2 }); matchSkill.Add(new Skill() { Name = "Strength", Value = 1 }); matchSkill.Add(new Skill() { Name = "Endurance", Value = 1 }); SkillSearch SkillSearch = new SkillSearch() { Skills = matchSkill }; </code></pre> <p>I should get back a list of players ordered PlayerB, PlayerC, PlayerD, PlayerA</p> <p>The skill lists will always be the same size and in the same order. The skills always range from 1-5. I have tried comparing the difference between the values using absolute value. For example if a search is for a (3) 2 and 4 would be a closer match than 1 or 5.</p> <p>In short if you just look at them as numeric array's you would have:</p> <pre><code> search = { 5, 2, 1, 1} playerb = { 5, 2, 1, 3} : difference {0,0,0,2} (2 total) playerc = { 5, 3, 2, 2} : difference {0,1,1,1} (3 total) playerd = { 1, 2, 5, 4} : difference {4,0,4,3} (11 total) playera = { 1, 5, 3, 4} : difference {4,3,2,3} (12 total) </code></pre> <p>How would I order these using C#? I would prefer a linq result. I am just not sure how to get these to order.</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