Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Changing tabs to spaces on 'The 3n + 1 problem'
Browse files Browse the repository at this point in the history
  • Loading branch information
fjsj committed Oct 14, 2011
1 parent ef13f6b commit 8d02c57
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions The 3n + 1 problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ int cycleSize(int x) {
int cycle = 1;

while (x != 1) {
if (x % 2 == 0) { //if even
x = x / 2;
} else { //if odd
x = x * 3 + 1;
}
++cycle;
if (x % 2 == 0) { //if even
x = x / 2;
} else { //if odd
x = x * 3 + 1;
}
++cycle;
}
return cycle;
}

int maxCycleSizeBetween(int a, int b) {
if (a > b) { //if b > a, swap them
int temp = a;
a = b;
b = temp;
int temp = a;
a = b;
b = temp;
}
int maxCycle = 0;

for (; a <= b; a++) {
int thisCycleSize = cycleSize(a);
if (thisCycleSize > maxCycle) {
maxCycle = thisCycleSize;
}
int thisCycleSize = cycleSize(a);
if (thisCycleSize > maxCycle) {
maxCycle = thisCycleSize;
}
}
return maxCycle;
}
Expand All @@ -67,7 +67,7 @@ int main() {
int a, b; //input vars

while (scanf("%d %d", &a, &b) != EOF) {
printf("%d %d %d\n", a, b, maxCycleSizeBetween(a, b));
printf("%d %d %d\n", a, b, maxCycleSizeBetween(a, b));
}
return 0;
}

0 comments on commit 8d02c57

Please sign in to comment.