7
You should write a program or function which given a text as input outputs or returns the sum of the following three integers:
- Number of lowercase
x
's which are not part of a cross-formation. - Number of uppercase
X
's which are not part of a cross-formation. - Number of cross-formations which are made of neither
x
norX
.
A cross-formation is 5 copy of the same character positioned to each other in the following manner:
A A
A
A A
Cross-formations can overlap with each other.
Detailed example
Input:
x-x+x+X++
-x-x+x++asd
x-x+x+X+
Info:
There is 1 x and 2 X's not in cross-formation and
there are 2 cross-formations of +'s as shown here:
+ +X+
+x+
+ +X+
Output:
5
Input
- A string containing only printable ascii characters (codepoint 32-126) and newlines.
- The string will contain at least one printable character.
Output
- A single positive integer, the sum of the number of occurrences for the three property.
Examples
After each output the values of the 3 properties (x
's, X
's and crosses) are provided in parens but note that those are not part of the output.
Input:
a
Output:
0 (0,0,0)
Input:
x xxx
X x
x xxx
Output:
5 (4,1,0)
Input:
########
#####
########
Output:
4 (0,0,4)
Input:
a-a-a
0a0a
a-a-axXxX
0a0a
a-a-a
Output:
9 (2,2,5)
Input:
a c efghi
ab defgh
a c e ghij
abcd fgh
abc e g
Output:
2 (0,0,2)
Input:
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
#####x-x+x+X++
#####-x-x+x++###XX
#####x-x+x+X+
/\/\/\/\/\/\/\
\/\/\/\/\/\/\/
Output:
10 (1,4,5)
Input:
xxxxxxxxxx
xxxxxxxXX
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxx
Output:
5 (3,2,0)
This is code-golf so the shortest entry wins.
Example 4 contains 2 cross formation of printable character codepoint 32 (space) that are not counted in output. Do spaces count? – edc65 – 2015-05-08T21:29:45.857
@edc65 i think space isnt allowed as counted for a cross , but i had similar question about if the line must be filled up with spaces until a newline , my work ll be based on positive assumption . – Abr001am – 2015-05-08T21:34:08.417
@edc65 Spaces do count, sorry about the incorrect example. :/ Corrected it. – randomra – 2015-05-08T21:39:29.437
so this s whole different thing , :S – Abr001am – 2015-05-08T21:44:34.203
@Agawa001 The lines are not necessary of equal lengths as you can see in the examples. – randomra – 2015-05-08T21:45:51.907
i was talkin about space bars , that wuld extend a line to similar size , but now everything is clear , too late thu , imust redo my code from beginning :( – Abr001am – 2015-05-08T21:47:10.367
No vote on any answers? Did we get somethign wrong? – edc65 – 2015-05-11T11:00:40.143
@edc65 Don't think so. I guess I was waiting for some more submissions to go through them and upvote at one run but the more submissions part never happened. :) – randomra – 2015-05-11T11:07:21.303