-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFall Rot.cpp
69 lines (59 loc) · 1.6 KB
/
Fall Rot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Fall Rot.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Matrix {//I fraking hate 2d arrays
private:
int* arr;
int rows;
int columns;
public:
Matrix() {};
Matrix(int rows, int columns) {
this->rows = rows;
this->columns = columns;
arr = new int[rows*columns];
};
void set(int x, int y, int value) { arr[x*rows + y] = value; }
int at(int x, int y){return arr[x*rows + y]; }
int getRows() { return rows; }
int getColumns() { return columns; }
bool exists(int x, int y) {
if (x >= 0 && y >= 0 && x < getRows() && y < getColumns()) return true;
else return false;
}
};
bool update(Matrix* targetMatrix, int x, int y) {
if ((targetMatrix->exists(x - 1, y) && targetMatrix->at(x - 1, y) == 2) ||
(targetMatrix->exists(x + 1, y) && targetMatrix->at(x + 1, y) == 2) ||
(targetMatrix->exists(x, y + 1) && targetMatrix->at(x, y + 1) == 2) ||
(targetMatrix->exists(x, y - 1) && targetMatrix->at(x, y - 1) == 2)){
targetMatrix->set(x, y, 2);
return true;
}
else return false;
}
int doStuff(Matrix* targetMatrix) {
bool invariancy = true;//if at end of cycle invariancy is flase means no change happened so cycle solhsd break
int result = 0;
int n = targetMatrix->getRows();
int m = targetMatrix->getColumns();
while (invariancy) {
invariancy = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (targetMatrix->at(i, j) == 1) {
invariancy = invariancy || update(targetMatrix, i, j);
}
}
}
result++;
}
return result;
}
int main()
{
Matrix asdfgh(5, 5);
return 0;
}