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;
|
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();
|
var enumeratedValues = values.Index().ToArray();
|
||||||
return enumerated
|
var pairs =
|
||||||
.SelectMany((valueA, ix) => enumerated.Skip(ix + 1).Select(valueB => (valueA, valueB)));
|
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