I have a linq query for project euler problem 243:
var y = from n in factors
from m in factors where m != n
select n * m;
The problem is, for prime factors 2 and 3, it produces the y = {6, 6} where it needs to just be {6}.
Is there a way to do this without calling y.Distinct() or y.Contains() multiple times?
I also thought about using two foreach loops, but the problem is – I can’t use indexing so it’d just be cumbersome and awkward.
As stated by Rick Sladkey, changing
to
produces the correct result without having to use
.Distinct().