Add .clang-format and apply it
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
|
||||
using Array = std::vector<std::string>;
|
||||
|
||||
char next_state(Array const &a, std::size_t row, std::size_t col) {
|
||||
char next_state(Array const& a, std::size_t row, std::size_t col)
|
||||
{
|
||||
unsigned occupied = 0;
|
||||
if (row > 0) {
|
||||
if (col > 0) {
|
||||
@@ -38,16 +39,19 @@ char next_state(Array const &a, std::size_t row, std::size_t col) {
|
||||
|
||||
if (a[row][col] == 'L' && occupied == 0) {
|
||||
return '#';
|
||||
} else if (a[row][col] == '#' && occupied >= 4) {
|
||||
}
|
||||
else if (a[row][col] == '#' && occupied >= 4) {
|
||||
return 'L';
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return a[row][col];
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long count_occupied(Array const &a) {
|
||||
unsigned long count_occupied(Array const& a)
|
||||
{
|
||||
unsigned long count = 0;
|
||||
for (auto const &row : a) {
|
||||
for (auto const& row : a) {
|
||||
for (auto col : row) {
|
||||
count += (col == '#');
|
||||
}
|
||||
@@ -56,7 +60,8 @@ unsigned long count_occupied(Array const &a) {
|
||||
return count;
|
||||
}
|
||||
|
||||
unsigned long run_to_steady_state(Array const &a) {
|
||||
unsigned long run_to_steady_state(Array const& a)
|
||||
{
|
||||
Array current = a;
|
||||
bool changed = true;
|
||||
unsigned i = 0;
|
||||
@@ -81,7 +86,8 @@ unsigned long run_to_steady_state(Array const &a) {
|
||||
|
||||
return count_occupied(current);
|
||||
}
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Array array;
|
||||
|
||||
for (std::string line; std::getline(std::cin, line);) {
|
||||
|
Reference in New Issue
Block a user