-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.c
72 lines (69 loc) · 1.66 KB
/
maze.c
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
69
70
71
72
#include <stdio.h>
void posRight(int arr[3][3], int position[2]);
void posDown(int arr[3][3], int position[2]);
void posLeft(int arr[3][3], int position[2]);
void posUp(int arr[3][3], int position[2]);
int main()
{
int a[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
int position[2] = {0, 0};
int count = 0;
while (1)
{
if (position[0] == 0 && position[1] == 0 && a[0][0] == 1)
count++;
posRight(a, position);
posDown(a, position);
posLeft(a, position);
posUp(a, position);
}
return 0;
}
void posRight(int arr[3][3], int position[2])
{
int j = position[1];
while (arr[position[0], j] != 1)
{
if (position[0] < 0 || position[0] > 2)
printf("%d %d", position[0], position[1]);
return 0;
position[0]++;
}
return;
}
void posDown(int arr[3][3], int position[2])
{
int j = position[0];
while (arr[j, position[1]] != 1)
{
if (position[1] < 0 || position[1] > 2)
printf("%d %d", position[0], position[1]);
return 0;
position[1]++;
}
return;
}
void posLeft(int arr[3][3], int position[2])
{
int j = position[1];
while (arr[position[0], j] != 1)
{
if (position[0] < 0 || position[0] > 2)
printf("%d %d", position[0], position[1]);
return 0;
position[0]--;
}
return;
}
void posUp(int arr[3][3], int position[2])
{
int j = position[0];
while (arr[j, position[1]] != 1)
{
if (position[1] < 0 || position[1] > 2)
printf("%d %d", position[0], position[1]);
return 0;
position[1]--;
}
return;
}