0

Lets say I have a 2D grid:

\begin{array}{} \dots & C & \dots\\ C & B_2 & C\\ B_1 & A & B_3\\ \dots & B_4 & \dots \end{array}

The $B$'s are neighbours of $A$. And every $B$ has neighbours $C$. Now I want to say that I want to perform an action on every $C$ for every $B$. This last sentence is somehow inaccurate since the $C$'s are not equal and change their positions. I came up with something like:

For every $C_{B_{m}n}$, I do $X$ so that $B_m$ will be $Y$,

$m = {1,2,3,4}$,
$n = {1,2,3}$.

But this still sounds wrong. I just want to consider the three neighbours $C$ for every step. One step would be to go to the next $B$. I have trouble to come up with a notation/phrasing since I'm not used to it.

Bonnaduck
  • 4,058
  • It's somewhat unclear what you're trying to do or state. Are you just trying to refer to the neighbors of the neighbors of A? Are you worried about ensuring each neighbor is acted upon exactly once? – Karl Feb 18 '22 at 16:32
  • @Karl I want to do an action on the neighbours of B1 (C1,C2,C3) then the neighbours of B2 (C4,C5,C6) and so on. I want to generalizes this behaviour, so that I can describe it in one or two sentences without writing a huge paragraph. I want to reference the neighbours of a B based on some index. If I say "for all neighbours of B's" i would refer C1 - C8 (excluding the duplicates). However I just want to consider only the three neighbours based on the actual B (including the duplicated)... for all B's. So there has to be an index which for the B's and then a for-all index for the (three) C's. – AliceTheCat Feb 18 '22 at 17:44
  • Maybe the suggestion of mine is already what I want. @Karl do you see an general issue with the suggestion in my question? – AliceTheCat Feb 18 '22 at 17:49
  • Well, the "$C_{{B_m}n}$" notation is nonsensical. There's not a straightforward way to express your intent using indexes. Instead, I'd recommend imperative pseudocode like "For each neighbor B of A: for each neighbor C of B: take the following action: ...". Or "For each pair $(B,C)$ such that $B$ is a neighbor of both $A$ and $C$: ...". Note that the same $C$ can appear in multiple such pairs, so it's clear that you want the duplication. – Karl Feb 18 '22 at 21:41
  • @Karl Thanks for the reply. I agree, I think I thought about this one too much. I just needed a place to talk about this. I will take your reply as my answer. – AliceTheCat Feb 21 '22 at 14:12

0 Answers0