Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread kerdemdemir via Digitalmars-d-learn
As for the problem itself, it can be solved without finding connected components. I won't post the solution right away because it is potentially a spoiler. See http://codeforces.com/blog/entry/53268 for problem analysis (828B) and http://codeforces.com/contest/828/submission/28637184 for an

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Ivan Kazmenko via Digitalmars-d-learn
On Monday, 17 July 2017 at 07:14:26 UTC, Andrea Fontana wrote: Probably using ndslice library could help you! Unfortunately, that's not possible on most online contest platforms like Codeforces. For each programming language and compiler available, only the most basic package is usually

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 16 July 2017 at 21:50:19 UTC, kerdemdemir wrote: Process(row-1,column-1, maxrow, maxcolumn); Process(row,column-1, maxrow, maxcolumn); Process(row+1,column-1, maxrow, maxcolumn);

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. You can also use a queue to avoid recursion that should improve performances and readibility. Probably using ndslice library

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
Of course now I will try to have it work first. Than replace for loops with Cartesian product calls. Than I will make 2D array template and even maybe with random access range. And finally for being able to use this class later in the some other coding challenge I will make Searching( == 'W'

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
Hi Guys, @Nicholas , thanks a lot for cool solution but actually I weren't working on image processing. I was trying to solve "http://codeforces.com/contest/828/problem/B;. I really needed finding connected components this time. @Ivan, your solution is much more elegant than what I did. But

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 19:10, Timon Gehr wrote: ... (This works even if there are * at the border.) Well, not really. :) Version that actually works if there are * at the border: import std.stdio, std.range, std.algorithm, std.array; char[][] arr; int componentSize(int row,int col){

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 18:55, Timon Gehr wrote: On 16.07.2017 12:37, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Timon Gehr via Digitalmars-d-learn
On 16.07.2017 12:37, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected '*' group in

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x ... Is there any

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected

Avoid if statements for checking neighboring indexes in a 2D array

2017-07-16 Thread kerdemdemir via Digitalmars-d-learn
My goal is to find connected components in a 2D array for example finding connected '*' chars below. x x x x x x x x x x x x x x * * x x x x * * x x x x x * * x * x x x x x There are two connected '*' group in this example. First group is composes of six