Skip to content

Instantly share code, notes, and snippets.

@s25g5d4
Created May 5, 2015 14:33
Show Gist options
  • Save s25g5d4/d03d9847a77670f140e7 to your computer and use it in GitHub Desktop.
Save s25g5d4/d03d9847a77670f140e7 to your computer and use it in GitHub Desktop.
/* correct */
for (int i = 1; i < n; ++i) {
if (ants[i].pos == ants[i - 1].pos) {
ants[i].direction = 'T';
ants[i - 1].direction = 'T';
}
}
/* wrong */
for (auto it = ants.begin() + 1; it != ants.begin() + n; ++it) {
if (it->pos == (it - 1)->pos) {
it->direction = 'T';
(it - 1)->direction = 'T';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment