Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Problem Statement - Battle of the dead
Daenerys Targaryen is the mother of dragons, flying on her dragons towards the north to
destroy the army of dead(zombies). The zombies are oddly distributed in battlefield. She can
throw dragon fire to burn zombies in a circular spot of about 5 units in diameter but she can only
do this once before the dragon gets exhausted. She needs your help to decide where to throw
fire in order to burn maximum possible zombies.


Input
You will be given a collection of coordinates in battlefield where zombies are located.
Eg: [ { x: 10.5, y: 10.5 }, { x: 40.2, y: 30.6 },... ]


Output
Output the maximum number of zombies that can be burnt in one attack.

Method Signature
function burnThemAll( zombies ) => number

Limits
Time limit (s): 840.000
Memory limit (MB): 64

Constraints
● The size of battle field is constant (i.e. 50x50 units) for all the inputs.
● Both x and y values of the coordinates are in-between 0.0 unit and 50.0 unit.
● No two zombies are closer than 0.1 unit.
● Dragons may throw fire at any edge points of the battlefield also.
● If there is no zombie on battlefield, then return 0.
● Each zombie is considered a point. Each zombie is at a different position


What I have tried:

function burnThemAll ( zombies ) {
	var feild_area = 50*50
	var burt_area = 0
	let z  = zombies.sort(function(a, b){return b['x'] - a['y']})
	// console.log(z[0].x-z[8].x)
	for (let i=0;i<z.length;i++){
		for (let j=0;j<i+1;j++){
			console.log(z[i]['x']-z[j]['x']);
		}
			// console.log(z[i]['x']-z[j]['x'])
			// console.log(z[i]['x']);

	}
}
Posted
Updated 18-Mar-18 1:55am
Comments
Patrice T 18-Mar-18 7:52am    
And you have a question or you just want us to do your homework?
Kornfeld Eliyahu Peter 18-Mar-18 7:58am    
From that 'code' it seems you have no idea what to do. Is it because you were sleeping during class, or just picked the wrong exercise to begin with?

A question: do you know how to check if a point is inside a circle?

1 solution

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
And working out how to do this is a significant part of that task.

Try it yourself, you may find it is not as difficult as you think!
I'll give you a starting point though: How would you do it manually? Assume you have a chessboard with pawns placed randomly about it. Your "dragon fire" hits a radius of two, so it hits a 3 x 3 "chunk" of the board each time, centered about the point she aims at.
So how would you decide which spot to aim for if you had to do it yourself?
When you work that out, it should be reasonably easy to translate into computer code!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900