23
You are the roughest, toughest, coolest cowboy west of the Mississippi. However, some weird guy on a wacky nerd website decided that it would be cool to plop you into random unfinished landscapes and fight. No matter, you'll still win. However, to help you win those grueling gunfights you'll write home about, it's helpful to know how many bullets the coward lurking in the landscape has.
How about you help this poor guy out. Given an ASCII landscape, find the gun inside it and tell him how many bullets are loaded into it. This is the gun:
(X)
(X\ /X)
(XVX)
\X/
Each X
in the above picture is a potential slot for a bullet. The slot will either contain a space or one of 0,O,o
(may not be consistent - the cowboy may have loaded different types of bullets in his gun).
There will always be exactly one gun, matching the above description, in the landscape. However, please note that the spaces around and inside the gun can contain anything.
Input
You will be given a string containing printable ASCII (so not tabs) and newlines to separate lines. You may also take a list of strings, if you wish. Strings will all be padded with spaces, so they will all be the same length. The input will be at least 4 rows high and 7 columns wide.
There will always be exactly one gun in the landscape.
Output
You will output how many bullets (0, O, o
) there are in the gun, so your output will always between 0
and 6
.
Test Cases
(0) ( )
(o\ /o( \ / )
(oVo) ( V )
\o/ \ /
0
----------------------------
////////////////////////////
////////////////////////////
/////////////(o)////////////
///////////(0\// )//////////
////////////( Vo)///////////
/////////////\ /////////////
////////////////////////////
----------------------------
3
()()()()()()()()()()()()()()()()\)/)()()()()()()()()()()()()
()()()()()()()()()()()()()()()()(V)()()()()()()()()()()()()(
()()()()()()()(\0/)()()()()()()()()()()()()()()()()()()()()(
()()()()()()()()()()()()()()()()()()()()()()()( )()()()()()(
()()()()()()(o)()()()()()()()(00)()()()()()(( \(/0)()()()()(
()()()()()()()()()()()()()()()()()()()()()()(( V )()()()()()
()()()()()()()()()()()()()()()()()()()()()()()\O/()()()()()(
2
------(0)---
||||(0\|/0)
-----(0V0)--
||||||\0/
-------_------
|||||||-|
------|-|
|||||||-|
------|-|
6
00ooOO(0)/\\/V
( )
( \\/ )
( V )
\\ /
00OOoo()()()())))
0
(\) (0)
(0\\/0) ( \0/ )
(0V0) ( V )
\\0/ \ /
1 (left gun is invalid because of the `\` in the bullet slot)
-00(0)00\0
-(O\0/o)\
- (OVo)o\0
-o \ /oo/
5
This is code-golf, so shortest answer in bytes wins.
Sandbox – Stephen – 2017-07-01T17:45:22.050
10+1 If someone FGITWs this challenge ;) – Beta Decay – 2017-07-01T18:02:00.990
2You should add a test case where there's a
0
inside the gun's bounding box but outside the gun. – Martin Ender – 2017-07-01T18:20:03.147@StepHen Oh right, there's the one zero inside the gun that doesn't belong to it. It would be good to have zeros outside the gun but within its bounding box as well though. – Martin Ender – 2017-07-01T18:21:03.093
"The input will be at least 4 rows high and 5 columns wide." - if there is always a gun then the input must be at least 7 columns wide. – manassehkatz-Moving 2 Codidact – 2017-07-02T14:30:36.263