markyrocks

3x+1 demo

Apr 8th, 2022 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. //#include <vector>
  6. #include <Windows.h>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. class list {
  12. public:
  13.     unsigned long long size;
  14.     bool* masterlist;
  15.     list() {
  16.         masterlist = new bool[1];
  17.         size = 1;
  18.     }
  19.     list(unsigned long long ull) {
  20.         masterlist = new bool[ull];
  21.         size = ull;
  22.     }
  23.     ~list() {
  24.         if (masterlist) {
  25.             delete masterlist;
  26.         }
  27.     }
  28.  
  29.     void Realloc(unsigned long long ull) {
  30.         bool* m = new bool[ull];
  31.         ZeroMemory(m, ull);
  32.         //good place for a size check
  33.         memcpy(m, masterlist, size);
  34.         delete masterlist;
  35.         masterlist = m;
  36.         size = ull;
  37.     }
  38.  
  39.     bool& operator[](unsigned long long ull) {
  40.         if (ull > size - 1) { Realloc(ull + 1); }
  41.         return masterlist[ull];
  42.     }
  43.     void print() {
  44.         for (unsigned long long ull = 0; ull < size; ull++) {
  45.             if(masterlist[ull])
  46.                 cout << ull << '\n';
  47.         }
  48.     }
  49. };
  50.  
  51. class node {
  52. public:
  53.     node* prev;
  54.     node* next;
  55.     int num;
  56.  
  57.     node() :prev{ nullptr }, next{ nullptr }, num{ 0 }{}
  58.     node(int num=0,node* prev = nullptr, node* next = nullptr) :prev{ prev }, next{ next }, num{ num }{}
  59.     node(node* prev) : num{ 0 }, prev{ prev }, next{ nullptr }{}
  60.  
  61.     node* Next() { return next; }
  62.     node* Prev() { return prev; }
  63.  
  64.  
  65. };
  66.  
  67. unsigned long long xPlusOne(unsigned long long ull) {
  68.     if (ull & 1) { return (ull * 3) + 1; } //0dd
  69.     return ull >> 1; //bitwise operations... beastmode unlocked
  70. }
  71.  
  72. int main() {
  73.  
  74.     unsigned long long in = 3;
  75.     list l;
  76.     do {
  77.         in = xPlusOne(in);
  78.         l[in] = true;
  79.     } while (in != 1);
  80.     l.print();
  81. }
  82.  
  83.  
  84.  
Add Comment
Please, Sign In to add comment