/home/toolbox/public_html/solutions/6/694/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 10
18 * Purpose:
19 * Problem: 694
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 int A; /* starting value */
27 int L; /* limit */
28 int cse = 0;
29
30 void init()
31 {
32 /* FUNCTION init */
33 } /* FUNCTION init */
34
35 void dump()
36 {
37 /* FUNCTION dump */
38 } /* FUNCTION dump */
39
40 int getInput()
41 {
42 /* FUNCTION getInput */
43 int dataReadFlag;
44
45 scanf(" %d %d ", &A, &L);
46 dataReadFlag = ((-1 != A) && (-1 != L));
47 return (dataReadFlag);
48 } /* FUNCTION getInput */
49
50 void process()
51 {
52 /* FUNCTION process */
53 int term = 1;
54 int belowLimit = TRUE;
55 int a;
56
57 a = A;
58 while ((1 != a) && belowLimit)
59 {
60 /* while */
61 term++;
62 if (0 == (a % 2))
63 {
64 /* even */
65 a = a / 2;
66 } /* even */
67 else
68 {
69 /* odd */
70 belowLimit = a <= (L - 1) / 3;
71 if (belowLimit)
72 {
73 /* below limit */
74 a = (a * 3) + 1;
75 } /* below limit */
76 else
77 {
78 /* over limit */
79 term--;
80 } /* over limit */
81 } /* odd */
82 } /* while */
83 cse++;
84 printf("Case %d: A = %d, limit = %d, number of terms = %d\n", cse, A, L, term);
85 } /* FUNCTION process */
86
87 int main()
88 {
89 /* main */
90 int moreToDo;
91
92 init();
93 moreToDo = getInput();
94 while (moreToDo)
95 {
96 /* while */
97 process();
98 moreToDo = getInput();
99 } /* while */
100
101 return EXIT_SUCCESS;
102 } /* main */
103