6 kyu

I guess this is a 6kyu kata #5: Whac-A-Mole

117 of 225myjinxin2015

Description:

Description

Let's play the game "Whac-A-Mole". Give you an 2D array:

[
[1,1,2,2],
[3,3,4,4],
[4,8,8,8]
]

The meaning of numbers in the array is that the mole will disappear after n seconds(0 means no mole). You are holding a big hammer and every second can hit two moles. Please calculate the maximum number of moles you can hit.

In accordance with the above example:

[
[1,1,2,2],
[3,3,4,4],
[4,8,8,8]
]

After 1 second(hit 2, total=2)
[
[x,x,1,1],
[2,2,3,3],
[3,7,7,7]
]

After 2 seconds(hit 2, total=4)
[
[x,x,x,x],
[1,1,2,2],
[2,6,6,6]
]

After 3 seconds(hit 2, total=6)
[
[x,x,x,x],
[x,x,1,1],
[1,5,5,5]
]

After 4 seconds(hit 2, total=8)
[
[x,x,x,x],
[x,x,x,x],
[0,4,4,4]
]

After 5 seconds(hit 2, total=10)
[
[x,x,x,x],
[x,x,x,x],
[0,x,x,3]
]

After 6 seconds(hit 1, total=11)
[
[x,x,x,x],
[x,x,x,x],
[0,x,x,x]
]

We hit a total of 11 moles.

Another example:

[
[6,4,1,1],
[4,4,4,4],
[1,2,3,3]
]

After 1 second(hit 2, total=2)
[
[5,3,x,x],
[3,3,3,3],
[0,1,2,2]
]

After 2 second(hit 2, total=4)
[
[4,2,x,x],
[2,2,2,2],
[0,x,x,1]
]

After 3 second(hit 2, total=6)
[
[3,x,x,x],
[1,1,1,1],
[0,x,x,x]
]

After 4 second(hit 2, total=8)
[
[2,x,x,x],
[x,x,0,0],
[0,x,x,x]
]


After 5 second(hit 1, total=9)
[
[x,x,x,x],
[x,x,0,0],
[0,x,x,x]
]

We hit a total of 9 moles.

OK, that's all. I guess this is a 6kyu kata. If you agree, please rank it as 6kyu and vote very;-) If you think this kata is too easy or too hard, please shame me by rank it as you want and vote somewhat or none :[

Task

Complete function whacAMole that accepts a argument arr, return the maximum number of moles you can hit.

Puzzles
Fundamentals

Stats:

CreatedSep 9, 2016
PublishedSep 9, 2016
Warriors Trained583
Total Skips28
Total Code Submissions977
Total Times Completed225
JavaScript Completions117
Python Completions119
Haskell Completions6
Total Stars13
% of votes with a positive feedback rating95% of 77
Total "Very Satisfied" Votes70
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • dfhwze Avatar
  • tobeannouncd Avatar
Ad