/home/toolbox/public_html/solutions/1/151/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2015-03-11
18 * Purpose:
19 * Problem: 151
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAX_SIZE 101
27
28 int reg;
29 int ary[MAX_SIZE];
30
31 void init()
32 {
33 /* FUNCTION init */
34 int i;
35
36 for (i=0; i<reg; i++)
37 {
38 /* for */
39 ary[i] = 1;
40 } /* for */
41 } /* FUNCTION init */
42
43 void dump()
44 {
45 /* FUNCTION dump */
46 } /* FUNCTION dump */
47
48 int getInput()
49 {
50 /* FUNCTION getInput */
51 int dataReadFlag;
52
53 scanf(" %d ", ®);
54 DEBUG printf("Input: %d\n", reg);
55 dataReadFlag = (0 != reg);
56 return (dataReadFlag);
57 } /* FUNCTION getInput */
58
59 int circle(int num)
60 {
61 /* FUNCTION circle */
62 int i;
63 int cnt = 0;
64 int where = 0;
65 int skip;
66
67 while ((1+cnt) < reg)
68 {
69 /* while */
70 DEBUG printf("marking off region: %d\n", where);
71 ary[where] = 0;
72 skip = 0;
73 DEBUG printf("outer: cnt: %d skip: %d ary[%d] = %d reg = %d\n", cnt, skip, where, ary[where], reg);
74 while (num > skip)
75 {
76 /* while */
77 where++;
78 if (where >= reg)
79 {
80 where = where - reg;
81 }
82 DEBUG printf("inner: cnt: %d skip: %d ary[%d] = %d reg = %d\n", cnt, skip, where, ary[where], reg);
83 if (1 == ary[where])
84 {
85 /* found a remaining region */
86 skip++;
87 } /* found a remaining region */
88 } /* while */
89 cnt++;
90 } /* while */
91 DEBUG printf("bottom: ary[%d] = %d\n", 12, ary[12]);
92 return (1 == ary[12]);
93 } /* FUNCTION circle */
94
95 void process()
96 {
97 /* FUNCTION process */
98 int i = 0;
99 int notFound = TRUE;
100
101 while (notFound)
102 {
103 /* while */
104 init();
105 i++;
106 DEBUG printf("trying: %d\n", i);
107 notFound = ! circle(i);
108 } /* while */
109 printf("%d\n", i);
110 } /* FUNCTION process */
111
112 int main()
113 {
114 /* main */
115 int moreToDo;
116
117 moreToDo = getInput();
118 while (moreToDo)
119 {
120 /* while */
121 process();
122 moreToDo = getInput();
123 } /* while */
124
125 return EXIT_SUCCESS;
126 } /* main */
127