Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- 'use strict';
- let matrix = [];
- let snowBallDamage = 0;
- let killedBunnies = 0;
- let matrixRow = arr.length-1;
- let matrixCol = arr[0].split(/\s+/).length;
- let coor = arr[arr.length-1]
- .split(' ')
- .filter(a=>a !== '');
- for (let i = 0; i < arr.length-1; i++) {
- matrix.push(arr[i].split(/\s+/).map(Number));
- }
- for (let i = 0; i <coor.length; i++) {
- let innerArr = coor[i].split(/[,]/).filter(a=>a!=='').map(Number);
- let bombRow = Number(innerArr[0]);
- let bombCol = Number(innerArr[1]);
- let bombValue = matrix[bombRow][bombCol];
- for (let row = bombRow-1; row <= bombRow+1; row++) {
- for (let col = bombCol-1; col <= bombCol+1; col++) {
- if((row>=0)&&(col>=0)&&(row < matrixRow)&&(col < matrixCol)){
- matrix[row][col] -= bombValue;
- }
- }
- }
- killedBunnies++;
- snowBallDamage += bombValue;
- }
- for (let row = 0; row < matrix.length; row++) {
- for (let col = 0; col < matrix[row].length; col++) {
- if(matrix[row][col]>0){
- snowBallDamage += matrix[row][col];
- killedBunnies++;
- }
- }
- }
- console.log(snowBallDamage);
- console.log(killedBunnies);
- }
- solve(['10 100 100',
- '100 100 100',
- '100 100 100',
- '0,0 2,2']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement