summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/options.cpp51
-rw-r--r--src/options.h1
2 files changed, 52 insertions, 0 deletions
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 @@
1#include "options.h" 1#include "options.h"
2 2
3#include "unitnumber.h" 3#include "unitnumber.h"
4#include "number.h"
4 5
6#include <bu/sio.h>
5#include <stdlib.h> 7#include <stdlib.h>
6 8
7Options::Options( int argc, char *argv[] ) 9Options::Options( int argc, char *argv[] )
8{ 10{
9 addOption( Bu::slot(this, &Options::selfTest), "self-test", 11 addOption( Bu::slot(this, &Options::selfTest), "self-test",
10 "Run a series of tests to ensure everything is working correctly."); 12 "Run a series of tests to ensure everything is working correctly.");
13 addOption( Bu::slot(this, &Options::textPrimes), "text-primes",
14 "Generate primes in base 36 that only have digits > 9 in them.");
11 addHelpOption('h', "help", "This help"); 15 addHelpOption('h', "help", "This help");
12 16
13 parse( argc, argv ); 17 parse( argc, argv );
@@ -22,5 +26,52 @@ int Options::selfTest( Bu::StringArray )
22 UnitNumber().run(); 26 UnitNumber().run();
23 27
24 exit( 0 ); 28 exit( 0 );
29 return 0;
30}
31
32bool hasDigits( const Bu::String &s )
33{
34 for( Bu::String::const_iterator i = s.begin(); i; i++ )
35 {
36 if( *i >= '0' && *i <= '9' )
37 return true;
38 }
39 return false;
40}
41
42int Options::textPrimes( Bu::StringArray )
43{
44 Number tst( 0, 36 );
45 Number max( 0, 36 );
46 Number j( 0, 36 );
47 Number one( 0, 36 );
48 Number fact( 0, 36 );
49 one = "1";
50 fact = "2";
51
52 for( tst = "1";; tst = tst + one )
53 {
54 if( hasDigits( tst.toString() ) )
55 continue;
56
57 max = tst / fact;
58 bool bPrime = true;
59 for( j = "2"; j < max; j = j + one )
60 {
61 if( (tst%j).isZero() )
62 {
63 bPrime = false;
64 break;
65 }
66 }
67
68 if( bPrime )
69 {
70 Bu::println("%1").arg( tst );
71 }
72 }
73
74 exit( 0 );
75 return 0;
25} 76}
26 77
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:
11 11
12private: 12private:
13 int selfTest( Bu::StringArray aArgs ); 13 int selfTest( Bu::StringArray aArgs );
14 int textPrimes( Bu::StringArray aArgs );
14}; 15};
15 16
16#endif 17#endif