6 kyu
Counting ASCII Art Squares
63 of 99mnemonix666
Loading description...
Geometry
Algorithms
Puzzles
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Nice one of the ASCII art series, funny to practice objects detection with.
Rust solution setup uses a template:
Nice Kata!
Apparently,
"-"
and"|"
can appear at intersections too, and nothing's told about how such cases should be handled.I mean, those are not meant to be intersections, obviously. I don't think this is really an issue.
The text is actually correct, so the issue is a different one: the description should have this as an example.
.
C++ version generates warnings.
Fixed
Language: C++
random_medium
```
+------++---+| | | || || | | || || | | || || | | || +++--------+------+-+ | || || +-----------+-+-+ | || || | | | | +------+| || | | | | | || | | | | +----+-+++ | | | | | ||| | | | | | ||| | | | | | ||| | | | | +--+------+|| | | | | | | ||| | | | | | | ||| | | | | +-+--+------+++----++ | | | | | | ||| || | | | | | | ||| || | | | | | | ||| || | | | | | | ||+----++---+------+-++| | | | || ++---+------+--++ | | | |+------+---+------+ | | +--+------+ | | | +----+------+-------+ | | | | | | | | | | | | +---------+ ```
What should be the expected square for this?
I have checked with my 3 implementations, and they all say there should be 11 squares.
So, it's 11. :)
Thanks, finally completed :D
I believe there's something wrong Rust translation of this kata...
For those trying to solve it as well, the function signature is:
I also deleted the sample test cases.
Thank you.
Is the issue truly resolved? I'm still getting the same solution setup as in the original post even when I hit the reset button.
This comment has been hidden.
Sorry, some places I wrote 1x1 which is 2x2 square.
Here:
There are two squares here, not only one: a 2x2 and a 3x3. They both share the upper left corner. The 3x3 square is this one:
(center
+
removed).thanks, for the correction.
my query is that the above figure has more squares than just "3" [3 is the Expected answer]!! what is wrong in my understanding!!
I see. I've fed the picture into my own solution (which is also used in the random checks as reference) as well as into another C++ solution sent by another user. Both return 11. That is, the expected answer should definitely be 11 for your input, not 3.
What's a bit odd about your input are the first few lines:
The generator shouldn't be able to generate broken shapes like this. It generates coordinates for random rectangles and squares within given constraints, and stores these coordinates in a vector. In a second step, the shapes are drawn into an array of strings, preallocated so that writing beyond any boundaries is impossible. In the last step, any trailing spaces are removed from all strings, leading and trailing empty lines are discarded from the final picture.
Are you sure that your dump is accurate? Do we see multiple overlapping pictures here? Any chance there could be any "junk" left between invocations of your function?
thanks for the update.
Yes, the figure might not be exactly accurate, since I had manually copied it for explaining my understanding, so that might have created the issue.
hello,
I used C++ language. My solution works fine for Sample. When I attempt to submit, it says 'Time: 2279ms Passed: 6 Failed: 0 Exit Code: 139'!!
Segfault.
As already suggested by FArekkusu, exit code 139 should correspond to signal 11 (SIGSEGV).
You can try sprinkling
std::cout
over your code to help you tracking down the line where your program crashes (assuming it is your program that is crashing the tests). Your program may access memory beyond the end of some line.Yes, thank you guys. It was due to memory mismanagement.
Hope, I will be able to solve the last few "figures" left to submit!!
Me, too, when I try to submit my solution I get the same error saying "main.cpp:433:20: error: use of undeclared identifier 'is_valid_horizontal'...", etc. It's a nicely challenging kata which I'm enjoying though :)
Thank you for reporting, I have fixed the tests (see my other reply for some details). Please try again, it should work now.
Thank you for your reply! Yes, the tests work perfectly now. I'm still failing a couple of them so just need to fix my code, haha :p
ISSUE: unexepected compile error in C++
Hi! When I try to submit (not "run tests") the final version of my solution, I get unexpected compile errors which have nothing to do with my code (see below). Functions is_valid_horizontal and is_valid_vertical are not in my code.
[Note: this is a really good kata, I've enjoyed working on it.]
kbenj
STDERR: main.cpp:345:20: error: use of undeclared identifier 'is_valid_horizontal' is_valid_horizontal(lines[a->y], a->x, b->x) && ^ main.cpp:346:20: error: use of undeclared identifier 'is_valid_horizontal' is_valid_horizontal(lines[b->y], a->x, b->x) && ^ main.cpp:347:20: error: use of undeclared identifier 'is_valid_vertical' is_valid_vertical(lines, a->x, a->y, b->y) && ^ main.cpp:348:20: error: use of undeclared identifier 'is_valid_vertical' is_valid_vertical(lines, b->x, a->y, b->y)) ^ 4 errors generated.
Thank you for reporting this. The tests picked up two functions defined only in my own solution, but not in the tests themselves. Running the tests against my own solution worked, so that's why the problem wasn't detected by the built-in validation. I'll know better next time. :)
It should work now, please try again.
It works fin now. Thanks.
nice kata
needs random tests (but that won't be easy to implement)
Thank you for your feedback! I think I could add random tests (see below). Out of curiosity: did you find any concrete corner cases that are not addressed by the existing tests?
For the random tests, I am thinking about two different kinds of picture generators: one which generates instances with only non-touching rectangles/squares, and another one which generates completely random instances. The restricted generator will be harder to implement, but the expected results will be trivial to check. The unrestricted generator will be easier to implement, but I will have to use and trust my own (or another) solution as reference to figure out the expected result.
edge cases: nope, that seems a good case coverage already. Maybe just add this one:
to have something complementary of your
pattern 2 of five squares
test.About the random tests, I believe I'd try something like having default full grids of different sizes like:
then pick a random number of corners to delete, then clean up the global structure.
Using different densities of the default grid and different shapes and sizes, you should be able to generate almost any kind of case. tho the variability of the generated grids needs to be high, so the parameters used would need some fine tunning.
I have added your example to the tests. Thank you for putting so much time into this! :)
I have also played around with random tests. So far, I have implemented a simple random generator which generates shapes of random size at random positions. Squares and rectanges are generated with equal probabilities, picture dimensions and min/max rectangle/square sizes can be given as parameters. There are 3 sets of random tests now, each generating 150 random pictures for a defined set of parameters passed to the generator. This gives us a total of 450 checks against random pictures.
To be reasonably sure that my own solution can serve as a reference implementation in the tests (there is no way to tell how many squares there are in the random instances other than counting them), I have generated a few 10000 of random pictures and threw them at my own implementation as well as at all the solutions submitted for this kata (4 for Python, 1 for C++). Each of them returned the same answers for any given picture, so this should be fine.
The random pictures can become pretty wild. I don't think other kinds of generators will be needed.