Solve 2025-08

This commit is contained in:
2025-12-08 14:09:00 +01:00
parent 63a7a93aba
commit 5421fde574
6 changed files with 119 additions and 1 deletions
+7
View File
@@ -135,6 +135,13 @@ export function uniqueCombinations<E>(arr: ReadonlyArray<E>): { a: E; b: E }[] {
arr.flatMap((b, bI) => (a !== b && aI > bI ? [{ a, b }] : []))
);
}
export function uniqueIndexCombinations<E>(
arr: ReadonlyArray<E>
): { aI: number; bI: number }[] {
return arr.flatMap((a, aI) =>
arr.flatMap((b, bI) => (a !== b && aI > bI ? [{ aI, bI }] : []))
);
}
/**
* Returns a filter lambda to be used in array.filter() to only allow the
+11 -1
View File
@@ -1,4 +1,4 @@
import { sumBy } from './array.ts';
import { sumArray, sumBy } from './array.ts';
export const Sides = {
TOP: 0,
@@ -167,3 +167,13 @@ export function calculateVariance<C extends Coordinate | CoordinateSide>(
coords.length
);
}
// TODO: add docs and tests
export function euclideanDistanceSqrtless(a: number[], b: number[]): number {
return sumArray(a.map((d, i) => Math.pow(d - b[i], 2)));
}
export function euclideanDistance(a: number[], b: number[]): number {
return Math.sqrt(euclideanDistanceSqrtless(a, b));
}