diff --git a/challenges/findExplodedMineRadius/findExplodedMineRadius.test.js b/challenges/findExplodedMineRadius/findExplodedMineRadius.test.js new file mode 100644 index 0000000..df88356 --- /dev/null +++ b/challenges/findExplodedMineRadius/findExplodedMineRadius.test.js @@ -0,0 +1,15 @@ +const findMineBlastRadius = require('./findMineBlastRadius'); + +describe('findMineBlastRadius Test', () => { + test('testOne', () => { + const minesList = [ + [1.01, 1, 2], + [6, 6, 1], + [1, 2, 3], + [-1, -1, 3], + ]; + const answer = [[-1, -1, 3], 3]; + const result = findMineBlastRadius(minesList); + expect(result).toEqual(answer); + }); +}); diff --git a/challenges/findExplodedMineRadius/findExplodedMineRadiusNotes.md b/challenges/findExplodedMineRadius/findExplodedMineRadiusNotes.md new file mode 100644 index 0000000..f4a6a42 --- /dev/null +++ b/challenges/findExplodedMineRadius/findExplodedMineRadiusNotes.md @@ -0,0 +1 @@ +findExplodedMineRadius Notes go here! diff --git a/challenges/findExplodedMineRadius/findExplodedMineRadiusSpec.md b/challenges/findExplodedMineRadius/findExplodedMineRadiusSpec.md new file mode 100644 index 0000000..04dd324 --- /dev/null +++ b/challenges/findExplodedMineRadius/findExplodedMineRadiusSpec.md @@ -0,0 +1,19 @@ +findExplodedMineRadius Spec goes here! + +// A minefield is made up of mines placed on a continuous 2D plane. A mine is +// represented as a tuple with the values (x, y, blast_radius). When a mine blows up, +// all other mines whose coordinates are within the blast radius also blow up. When +// those mines blow up, any mines within their blast radius also blow up, and so on +// and so on, triggering a chain reaction. + +// Given a list of mines, determine which mine would blow the most total number of +// mines if it were to blow up. The output should be a pair of the mine and the +// total number of mines that it blows up, including itself. + +// mines = [ +// (1.01, 1, 2), +// (6, 6, 1), +// (1, 2, 3), +// (-1, -1, 3), +// ] +// print(most_blown_up(mines)) == ((-1, -1, 3), 3) diff --git a/challenges/findExplodedMineRadius/findMineBlastRadius.js b/challenges/findExplodedMineRadius/findMineBlastRadius.js new file mode 100644 index 0000000..9e8c9b1 --- /dev/null +++ b/challenges/findExplodedMineRadius/findMineBlastRadius.js @@ -0,0 +1,52 @@ +// returns boolean +function isWithinBlastRadius(explodingMine, secondMine) { + // name is redudant + const explodingMineX1 = explodingMine[0]; + const explodingMineY1 = explodingMine[1]; + const explodingMineRadius = explodingMine[2]; + + const secondMineX2 = secondMine[0]; + const secondMineY2 = secondMine[1]; + + const distanceBetweenPoints = Math.sqrt((explodingMineX1 - secondMineX2) ^ 2 + + (explodingMineY1 - secondMineY2) ^ 2); + + return explodingMineRadius > distanceBetweenPoints; +} + +function findMineBlastRadius(minesList) { + // greedy algo counter, + // compared outputs to this mostMinesBlown counter, + // if the blowup chain exceeds, replace the counter/mine + const mostMinesBlown = 0; + const mostDestructiveMine = []; + + const explodingMinesQueue = []; + + const firstMine = minesList.unshift(); + + if (explodingMinesQueue.length === 0) { + explodingMinesQueue.push(items); + } + + while (explodingMinesQueue.length > 0) { + const nextMine = minesList.unshift(); + // if the next mine is with the radius, add it to the queue + const recentlyExplodedMine = explodingMinesQueue[explodingMinesQueue.length]; + // if(explodingMinesQueue[]) + } + + + for (let i = 0; i < minesList.length; i++) { + const firstMine = minesList[i]; + const blownMinesMap = { }; + for (let j = 1; j < minesList.length; j++) { + const nextMine = minesList[j]; + if (isWithinBlastRadius(firstMine, nextMine)) { + // second layer + } + } + } +} + +module.exports = { isWithinBlastRadius, findMineBlastRadius }; diff --git a/helpers/generateBoilerPlate.js b/helpers/generateBoilerPlate.js index 3d9a776..935583a 100644 --- a/helpers/generateBoilerPlate.js +++ b/helpers/generateBoilerPlate.js @@ -5,7 +5,7 @@ const fs = require('fs'); // TODO: split up challenges // TODO: add appDesignSection? // ////SETUP HERE////// -const solutionName = 'findArrayIntersect'; +const solutionName = 'findExplodedMineRadius'; // TODO: look into setting up map or enum for this /* challenge || dataStructure || algorithm || designPattern || concept */ const codeChallengeType = 'challenge';