Replies: 1 comment
-
I think you might looking for using System;
using System.Linq;
using MoreLinq;
var cities = new[]
{
"New York",
"Los Angeles",
"Chicago",
"Houston",
"Phoenix"
};
var data =
from e in cities.Subsets(2).Zip(MoreEnumerable.Random(200))
select (e.First[0], e.First[1], e.Second);
foreach (var (a, b, distance) in data)
Console.WriteLine($"({a}, {b}) -> Distance: {distance}"); This should produce the output:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like something like Cartesian, but considering that (a, b) <==> (b, a).
So you would simply create a distance matrix with some code like:
var distances = cities.UniquePairs(cities, (a, b) => (A: a, B: b, Distance: Random.Shared(200)));
Beta Was this translation helpful? Give feedback.
All reactions