From 722e0ef0ea2624c1cd9bd5ca69833e37dc09f97f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 8 May 2013 15:26:41 -0600 Subject: Added a funny option to generate primes. ...But primes in base 36 and it skips all numbers with digits in the range 0-9 --- src/options.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/options.h | 1 + 2 files changed, 52 insertions(+) diff --git a/src/options.cpp b/src/options.cpp index 4fcf1e2..7f66028 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -1,13 +1,17 @@ #include "options.h" #include "unitnumber.h" +#include "number.h" +#include #include Options::Options( int argc, char *argv[] ) { addOption( Bu::slot(this, &Options::selfTest), "self-test", "Run a series of tests to ensure everything is working correctly."); + addOption( Bu::slot(this, &Options::textPrimes), "text-primes", + "Generate primes in base 36 that only have digits > 9 in them."); addHelpOption('h', "help", "This help"); parse( argc, argv ); @@ -22,5 +26,52 @@ int Options::selfTest( Bu::StringArray ) UnitNumber().run(); exit( 0 ); + return 0; +} + +bool hasDigits( const Bu::String &s ) +{ + for( Bu::String::const_iterator i = s.begin(); i; i++ ) + { + if( *i >= '0' && *i <= '9' ) + return true; + } + return false; +} + +int Options::textPrimes( Bu::StringArray ) +{ + Number tst( 0, 36 ); + Number max( 0, 36 ); + Number j( 0, 36 ); + Number one( 0, 36 ); + Number fact( 0, 36 ); + one = "1"; + fact = "2"; + + for( tst = "1";; tst = tst + one ) + { + if( hasDigits( tst.toString() ) ) + continue; + + max = tst / fact; + bool bPrime = true; + for( j = "2"; j < max; j = j + one ) + { + if( (tst%j).isZero() ) + { + bPrime = false; + break; + } + } + + if( bPrime ) + { + Bu::println("%1").arg( tst ); + } + } + + exit( 0 ); + return 0; } diff --git a/src/options.h b/src/options.h index 667e486..11bf896 100644 --- a/src/options.h +++ b/src/options.h @@ -11,6 +11,7 @@ public: private: int selfTest( Bu::StringArray aArgs ); + int textPrimes( Bu::StringArray aArgs ); }; #endif -- cgit v1.2.3