Last active
September 28, 2015 00:48
-
-
Save tssm/1358660 to your computer and use it in GitHub Desktop.
Revisions
-
tssm revised this gist
Mar 6, 2014 . 10 changed files with 91 additions and 62 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ int getFactorialOf(unsigned number) { if (number == 0) { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ def isNarcissistic(number): # Determines the number of digits: digits = 0 for (dividend = number; dividend > 0; dividend //= 10): This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,18 @@ bool isHappy(unsigned int number) { unsigned int sum; do { sum = 0; for (; number > 0; sum += (number % 10) * (number % 10), number /= 10); if (sum < 10) break; number = sum; } while (true); if (sum == 1) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,12 @@ bool isRepunit(number) { while (number > 0) { if (number % 10 != 1) return false; number /= 10; } return true; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ bool isPrime(long int number) { if (number <= 1) return false; if (number == 2) return true; for (unsigned int i = 2; i < (number / 2) + 1; ++i) { if (number % i == 0) return false; } return true; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,15 @@ bool isAutomorphic(number) { unsigned int digits = 0, divisor = 1, squareNumber = number * number; // Calculate the number of digits: for (unsigned int i = number; i > 0; i /= 10, ++digits); // Calculate the divisor to use: for (int i = 1; i <= digits; divisor *= 10, i++); if ((squareNumber % divisor) == number) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,12 @@ bool isPalindromic(unsigned int number) { int reversed = 0; // Reverse the number: for (unsigned int i = number; i > 0; reversed = (10 * reversed) + (i % 10), i /= 10); if (reversed == number) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,23 @@ bool isPerfect(unsigned int number) { unsigned int divisorsSum = 1; for (divisor = 2; divisor <= (number / 2) + 1; ++divisor) { if (number % divisor == 0) { divisorsSum += divisor; } } if (number == divisorsSum) { return true; } return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # Change the base of a decimal base integer unsigned int(unsigned int number, unsigned short int newBase) { unsigned int baseChanged = 0, exponent = 1; for (unsigned int quotient = number; quotient > 0; quotient /= base) { baseChanged += exponent * (quotient % base); exponent = (10 * exponent); } return baseChanged; } -
tssm revised this gist
Mar 6, 2014 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ int calculateFactorialOf(unsigned number) { if (number == 0) { return 1; } unsigned int factorial, i; for (factorial = i = 1; i <= number; factorial *= i, i++); return factorial; } -
tssm revised this gist
Jul 30, 2013 . No changes.There are no files selected for viewing
-
tssm revised this gist
Jul 30, 2013 . 8 changed files with 82 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ bool isHappy(unsigned int number) { unsigned int sum; do { sum = 0; for (; number > 0; sum += (number % 10) * (number % 10), number /= 10); if (sum < 10) break; number = sum; } while (true); if (sum == 1) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ bool isRepunit(number) { while (number > 0) { if (number % 10 != 1) return false; number /= 10; } return true; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ bool isPrime(long int number) { if (number <= 1) return false; if (number == 2) return true; for (unsigned int i = 2; i < (number / 2) + 1; ++i) if (number % i == 0) return false; return true; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ bool isAutomorphic(number) { unsigned int digits = 0, divisor = 1, squareNumber = number * number; // Calculate the number of digits: for (unsigned int i = number; i > 0; i /= 10, ++digits); // Calculate the divisor to use: for (int i = 1; i <= digits; divisor *= 10, i++); if ((squareNumber % divisor) == number) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ bool isPalindromic(unsigned int number) { int reversed = 0; // Reverse the number: for (unsigned int i = number; i > 0; reversed = (10 * reversed) + (i % 10), i /= 10); if (reversed == number) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ bool isPerfect(unsigned int number) { unsigned int divisorsSum = 1; for (divisor = 2; divisor <= (number / 2) + 1; ++divisor) { if (number % divisor == 0) divisorsSum += divisor; } if (number == divisorsSum) return true; return false; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # Change the base of a decimal base integer unsigned int(unsigned int number, unsigned short int newBase) { unsigned int baseChanged = 0, exponent = 1; for (unsigned int quotient = number; quotient > 0; quotient /= base) { baseChanged += exponent * (quotient % base); exponent = (10 * exponent); } return baseChanged; } -
tssm revised this gist
May 3, 2012 . 1 changed file with 6 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,15 @@ def isNarcissistic(number): # Determines the number of digits: digits = 0 for (dividend = number; dividend > 0; dividend //= 10): digits += 1 # Calculates the sum of the squared digits: digitsSum = 0 for (dividend = number; dividend > 0; dividend //= 10): digitsSum += (dividend % 10) ** digits # Returns the answer: if (digitsSum == number): return true -
tssm created this gist
Nov 11, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ def isNarcissistic(number): digits = digitsSum = 0 # Determines the number of digits: dividend = number while (dividend > 0): dividend //= 10 digits = digits + 1 # Calculates the sum of the squared digits: dividend = number while (dividend > 0): digitsSum += (dividend % 10) ** digits dividend //= 10 # Returns the answer if (digitsSum == number): return true return false