Refactor Day08 to improve readability with LINQ
This commit is contained in:
parent
7a02ba6b0e
commit
629467f376
|
|
@ -123,10 +123,14 @@ public class Day08
|
|||
return combinations;
|
||||
}
|
||||
|
||||
private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values)
|
||||
private IEnumerable<(TValue a, TValue b)> Combinations<TValue>(IEnumerable<TValue> values) where TValue:IComparable
|
||||
{
|
||||
var enumerated = values.ToArray();
|
||||
return enumerated
|
||||
.SelectMany((valueA, ix) => enumerated.Skip(ix + 1).Select(valueB => (valueA, valueB)));
|
||||
var enumeratedValues = values.Index().ToArray();
|
||||
var pairs =
|
||||
from a in enumeratedValues
|
||||
from b in enumeratedValues
|
||||
where a.Index < b.Index
|
||||
select (a.Item, b.Item);
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue