Vegetarianboy30

cu,m in C++

Jan 20th, 2021
703
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include <boost/lexical_cast.hpp>
  4.  
  5. void Run( const std::string& v, int tgt, int start ) {
  6.     for( ; tgt >= 2 * start + 1; ++start )
  7.         Run( v + ' ' + boost::lexical_cast<std::string>( start ), tgt - start, start + 1 );
  8.     std::cout << v << ' ' << tgt << std::endl;
  9. }
  10.  
  11. int main() {
  12.     Run( std::string(), 10, 1 );
  13.     getchar();
  14. }
  15.  
  16.  
  17. Second paraphrasing is as follows:
  18.  
  19. #include <cassert>
  20. #include <cstdlib>
  21. #include <iostream>
  22.  
  23. class Cpu {
  24.   public:
  25.     virtual int dummy( int, int ) {}
  26.   private:
  27.     virtual int add_( int a, int b ) { return a + b; }  /* A */
  28.     virtual int sub_( int a, int b ) { return a - b; }  /* B */
  29.     virtual int mul_( int a, int b ) { return a * b; }  /* C */
  30.     virtual int div_( int a, int b ) { return a / b; }  /* D */
  31.     virtual int mod_( int a, int b ) { return a % b; }  /* E */
  32.     virtual int and_( int a, int b ) { return a & b; }  /* F */
  33.     virtual int or_( int a, int b )  { return a | b; }  /* G */
  34.     virtual int xor_( int a, int b ) { return a ^ b; }  /* H */
  35. };
  36.  
  37. int main( int argc, char* argv[] ) {
  38.     typedef int (Cpu::*Memfun)( int, int );
  39.  
  40.     union {
  41.         Memfun fn;
  42.         unsigned char ptr[6];
  43.     } u;
  44.  
  45.     Cpu    cpu;
  46.  
  47.     u.fn = &Cpu::dummy;
  48.  
  49.     assert( argc == 4 );
  50.  
  51.     int p1 = atoi( argv[ 1 ] );
  52.     int p2 = atoi( argv[ 3 ] );
  53.     char op = argv[2][0];
  54.  
  55.     assert( op >= 'A' && op <= 'H' );
  56.  
  57.     u.ptr[0] = 1 + 4 * ( op - 'A' + 1 );  // Don't look here!
  58.  
  59.     std::cout << "The answer is " << ( (cpu.*(u.fn))( p1, p2 ) ) << std::endl;
  60. }
  61.  
  62. Third paraphrasing:
  63.  
  64. #include <cassert>
  65. #include <cstdlib>
  66. #include <iostream>
  67.  
  68. class Cpu {
  69.   public:
  70.     virtual int dummy( int, int ) {}
  71.   private:
  72.     virtual int add_( int a, int b ) { return a + b; }  /* A */
  73.     virtual int sub_( int a, int b ) { return a - b; }  /* B */
  74.     virtual int mul_( int a, int b ) { return a * b; }  /* C */
  75.     virtual int div_( int a, int b ) { return a / b; }  /* D */
  76.     virtual int mod_( int a, int b ) { return a % b; }  /* E */
  77.     virtual int and_( int a, int b ) { return a & b; }  /* F */
  78.     virtual int or_( int a, int b )  { return a | b; }  /* G */
  79.     virtual int xor_( int a, int b ) { return a ^ b; }  /* H */
  80. };
  81.  
  82. int main( int argc, char* argv[] ) {
  83.     typedef int (Cpu::*Memfun)( int, int );
  84.  
  85.     union {
  86.         Memfun fn;
  87.         unsigned char ptr[6];
  88.     } u;
  89.  
  90.     Cpu    cpu;
  91.  
  92.     u.fn = &Cpu::dummy;
  93.  
  94.     assert( argc == 4 );
  95.  
  96.     int p1 = atoi( argv[ 1 ] );
  97.     int p2 = atoi( argv[ 3 ] );
  98.     char op = argv[2][0];
  99.  
  100.     assert( op >= 'A' && op <= 'H' );
  101.  
  102.     u.ptr[0] = 1 + 4 * ( op - 'A' + 1 );  // Don't look here!
  103.  
  104.     std::cout << "The answer is " << ( (cpu.*(u.fn))( p1, p2 ) ) << std::endl;
  105. }
  106.  
  107.  
  108. Header:
  109.  
  110. int main () {
  111.   int line = 1; // set the line (y coordinate) to 1 (first line)
  112.   int p = 0; // set the position in the line (x coordinate) to 0.
  113.   DIR dcur = EAST; // set the current direction to EAST... DIR is a int typedef
  114.   /* ======== PROGRAM VARS ======== */
  115.     stack <int> svar; // the program stack
  116.   /* ============================== */
  117.     if(isblank(getVarStr(file)[0]) || isnull(getVarStr(file)[0])) // if line[0] is empty or '\0'
  118.       err("No initial insructions: Execution failed"); // throw error... err(const char*)
  119.     bool string_mode = false; // not in string mode...
  120.     while(true) { // program loop
  121.       randSeed(); // invokes random seed: srand(time(NULL));
  122.          char curp = seek(line, p); // char current cursor position
  123.          if(!string_mode)
  124.              setdir(&dcur, line, p); // set the direction based on curp... ^^^
  125.            if(istrampoline(curp)) // if # symbol (means skip next call):
  126.              jumpp(dcur, &line, &p); // *p+=2;
  127.            else // if 'curp' is normal (not '#')
  128.              nextp(dcur, &line, &p); //  ++*p
  129.          trypush(seek(line, p), &svar); // if 'curp' is number 0-9: svar.push(curp-'0');
  130.     /* ========================= parse 'curp' =============== */
  131.    /* ... */
RAW Paste Data