Skip to content

Commit

Permalink
add a primitive algo
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianrobotka committed Jan 23, 2017
1 parent ba8ec7d commit 548820e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
*.iml
.idea/

# Cmake files
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
collatz_tester

# Compiled Object files
*.slo
*.lo
Expand Down
42 changes: 40 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,45 @@

using namespace std;

int main()
{
/**
* Do Collatz algorithm on the number
*
* @param numberToTest Number to enumerate
*/
inline void enumerateNumber(unsigned long long int numberToTest) {
while (numberToTest != 1) {
if (numberToTest % 2 == 0) {
numberToTest = numberToTest >> 1;
} else {
numberToTest *= 3;
numberToTest++;
}
}
}

/**
* Entry point
*
* @return 0 or noting, in better case ;)
*/
int main() {
ios::sync_with_stdio(false);

unsigned long long int numberToTest = 2;
unsigned short int index = 1;

// until overflow
while (numberToTest != 1) {
if (index == 1) {
cout << ".";
cout.flush();
}

enumerateNumber(numberToTest);

numberToTest++;
index++;
}

return 0;
}

0 comments on commit 548820e

Please sign in to comment.