r/dailyprogrammer • u/jnazario 2 0 • Jul 22 '15
[2015-07-22] Challenge #224 [Intermediate] Detecting Four Sided Figures
Description
I got this idea from the Mensa quiz, specifically question 17. It's a basic scanning challenge: can your program detect and count intersecting bounding boxes from an ASCII art input? A four-sided figure is an ASCII art rectangle. Note that it can overlap another one, as long as the four corners are fully connected.
Formal Inputs & Outputs
Your program will be given an ASCII art chart showing boxes and lines. - and | characters indicate horizontal and vertical lines, respectively, while "+" characters show intersections.
Your program should emit an integer, N, of how many unique four sided figures it found. Rectangles and squares both count.
Example Input
+----+
| |
+-------------------------+-----+----+
| | | |
| +-------------------+-----+ |
| | | | |
| | | | |
+-----+-------------------+-----+ |
| | | |
| | | |
+-------------------+-----+ |
| | |
| | |
| | |
+-----+----+
| |
| |
| |
+----+
Example Output
For the above diagram your program should find 25 four sided figures.
Challenge Input
This one adds a bit to the complexity by throwing in some three sided figures. This should catch more naive implementations.
+-----------+
| |
| |
| |
| |
+-------------+-----------+-------------+
| | | |
| | | |
| | | |
| | | |
+-------------+-----------+-------------+
| |
| |
| |
| |
+-------------+-----------+-------------+
| | | |
| | | |
| | | |
| | | |
+-------------+-----------+-------------+
| |
| |
| |
| |
+-----------+
Challenge Output
For the challenge diagram your program should find 25 four sided figures.
Finally
Have a good challenge idea? Consider submitting it to /r/dailyprogrammer_ideas
View all comments
Show parent comment
1
u/adrian17 1 4 Jul 23 '15
...huh? I didn't get your point at all. How does it make you lose "ease of access"? If there's one thing that everyone agrees that reduces readibility, that's extremely deep nesting.
In fact, some IDEs/plugins recognize this as a bad practice and let you switch between these forms with a push of a button: http://puu.sh/ja9a9/73a27f0692.mp4