this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

it's not crashing now at least

+11 -12
+11 -12
2023/day05/part2.ts
··· 28 28 .split(" ") 29 29 .map((x) => parseInt(x)); 30 30 31 - const seeds = []; 32 - for (let i = 0; i < seedRanges.length; i += 2) { 33 - const from = seedRanges[i]; 34 - const to = from + seedRanges[i + 1]; 35 - for (let j = 0; j < to - from; j++) { 36 - seeds.push(seedRanges[i] + j); 37 - } 38 - } 39 - 40 31 const mapRanges: MapRanges[] = mapLines 41 32 .join("\n") 42 33 .split("\n\n") ··· 53 44 return { from, to, ranges }; 54 45 }); 55 46 56 - // start at `from: seed` to `to: location` 57 - const locationNumbers = seeds.map((s) => getLocationNumber(s, mapRanges)); 47 + let minLocNum = Infinity; 48 + for (let i = 0; i < seedRanges.length; i += 2) { 49 + const from = seedRanges[i]; 50 + const to = from + seedRanges[i + 1]; 51 + for (let j = 0; j < to - from; j++) { 52 + const seed = seedRanges[i] + j; 53 + const locNum = getLocationNumber(seed, mapRanges); 54 + if (locNum < minLocNum) minLocNum = locNum; 55 + } 56 + } 58 57 59 - return Math.min(...locationNumbers); 58 + return minLocNum; 60 59 } 61 60 62 61 function getLocationNumber(seed: number, mapRanges: MapRanges[]): number {