Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions challenges/findExplodedMineRadius/findExplodedMineRadius.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
findExplodedMineRadius Notes go here!
19 changes: 19 additions & 0 deletions challenges/findExplodedMineRadius/findExplodedMineRadiusSpec.md
Original file line number Diff line number Diff line change
@@ -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)
52 changes: 52 additions & 0 deletions challenges/findExplodedMineRadius/findMineBlastRadius.js
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 1 addition & 1 deletion helpers/generateBoilerPlate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down