Created
July 6, 2021 08:43
-
-
Save kharioki/3d3efce000d1a277d88cd8630adf63b6 to your computer and use it in GitHub Desktop.
Calculation hit probability in battleship game in 2d array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getHitProbability(R, C, G) { | |
| // Write your code here | |
| let empty = 0; | |
| let filled = 0; | |
| let tot = R*C | |
| for(let i = 0; i < R; i++){ | |
| for(let j = 0; j < C; j++){ | |
| G[i] && G[i][j] === 1 ? filled++ : empty++ | |
| } | |
| } | |
| let prob = filled / tot | |
| return prob.toFixed(6); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to do this in java?