Last active
November 17, 2017 03:59
-
-
Save mfurquimdev/b52b2ce4dc8c6b0b5ffc77e6e0db32b1 to your computer and use it in GitHub Desktop.
Numberphile sequences
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 characters
| // The Kolakoski Sequence | |
| // https://youtu.be/co5sOgZ3XcM | |
| #include <stdio.h> | |
| #define MAX 99 | |
| int main() | |
| { | |
| unsigned int seq[MAX]; | |
| seq[0] = 1; | |
| seq[1] = 2; | |
| int i = 2; | |
| int s = 1; | |
| int a = 2; | |
| for (i = 1, s = 1; i < MAX; s++) { | |
| int j = seq[s]; | |
| for (j = seq[s]; j != 0; j--) { | |
| seq[i] = a; | |
| i++; | |
| if (i == MAX) { | |
| break; | |
| } | |
| } | |
| (a == 1) ? (a = 2) : (a = 1); | |
| } | |
| for (i = 0; i < MAX; i++) { | |
| printf("%d", seq[i]); | |
| } | |
| printf("\n"); | |
| return 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 characters
| // 5040 and other Anti-Prime Numbers | |
| // https://youtu.be/2JM2oImb9Qg | |
| #include <iostream> | |
| #include <cstdlib> | |
| #include <map> | |
| using namespace std; | |
| int main(int argc, char* argv[]) | |
| { | |
| int max_num = 12; | |
| if (argc == 2) { | |
| max_num = atoi(argv[1]); | |
| } | |
| map<int, map<int,int> > numbers; | |
| int number = 1; | |
| map<int, int> factors; | |
| int prime = 0; | |
| number = 1; | |
| prime = 1; | |
| factors[prime] = 1; | |
| numbers[number] = factors; | |
| for (number = 2; number <= max_num; number++) { | |
| factors.clear(); | |
| int n = number; | |
| for (prime = 2; prime <= n; prime++) { | |
| factors[prime] = 0; | |
| while (n % prime == 0) { | |
| n = n/prime; | |
| factors[prime]++; | |
| } | |
| } | |
| numbers[number] = factors; | |
| } | |
| for (int i = 1; i <= max_num; i++) { | |
| cout << i << ": "; | |
| int sum = 1; | |
| if (i != 1) { | |
| for (int p = 1; p <= max_num; p++) { | |
| if (numbers[i][p] != 0) { | |
| sum *= (numbers[i][p]+1); | |
| } | |
| } | |
| } | |
| cout << sum << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment