Search   Memberlist   Usergroups
 Page 1 of 1 [1 Post]
Author Message
Risto Lankinen
science forum beginner

Joined: 02 Jun 2005
Posts: 28

Posted: Wed Jun 22, 2005 9:38 am    Post subject: Novel factorizations, episode IV

Hi!

 Quote: Begin Factors.cpp

#include <iostream.h>

// Rudimentary code! Number-to-factorize is hard-coded as 'N':
#define N 3*5*7*11*13 // 3*3*3*3*3*3*3*3*3*3 // 1001 // 1009

int Expand( int n )
{
int bit = 1;

while( n > 4*bit )
{
bit = bit * 2;
}

return bit * n;
}

int Oddify( int n )
{
while( (n&1) == 0 )
{
n = n/2;
}

return n;
}

void FindFactors( int x,int y,int b )
{
if( Expand(N)/y <= x || Expand(N)/(y+2*b) > (x+6*b) || b == 0 || x > 2*y )
{
if( Expand(N) == x*y )
{
cout << N << " = " << Oddify(x) << " * " << Oddify(y) << endl;

// Throw anything here to quit at first successful factorization
// Comment out or remove the line below to find all factorizations
throw "Done.";
}
return;
}

FindFactors( x,y,b/2 );
FindFactors( x+b,y,b/2 );
FindFactors( x+b/2,y+b/2,b/2 );
FindFactors( x+3*b/2,y+b/2,b/2 );
}

int main()
{
int n;

for( n=0x00008000;n!=0;n=n/2 )
{
if( n*n < Expand(N) )
{
try
{
FindFactors( n,n,n );
}
catch( ... )
{
break;
}
}
}

return 0;
}

 Quote: End Factors.cpp

Loosely based on the idea presented in...

Go ahead, try it out, analyze, get ideas, enjoy!

- Risto -

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Page 1 of 1 [1 Post]
 The time now is Sat Dec 15, 2018 11:01 am | All times are GMT
 Jump to: Select a forum-------------------Forum index|___Science and Technology    |___Math    |   |___Research    |   |___num-analysis    |   |___Symbolic    |   |___Combinatorics    |   |___Probability    |   |   |___Prediction    |   |       |   |___Undergraduate    |   |___Recreational    |       |___Physics    |   |___Research    |   |___New Theories    |   |___Acoustics    |   |___Electromagnetics    |   |___Strings    |   |___Particle    |   |___Fusion    |   |___Relativity    |       |___Chem    |   |___Analytical    |   |___Electrochem    |   |   |___Battery    |   |       |   |___Coatings    |       |___Engineering        |___Control        |___Mechanics        |___Chemical

 Topic Author Forum Replies Last Post Similar Topics *unique* prime factorizations; the fundamental theorem of... DGoncz@aol.com Math 5 Sun Jul 16, 2006 9:53 am The grumble beast - sign of life? - Star Trek episode gb6724 New Theories 8 Sat Mar 04, 2006 2:16 pm old NOVA episode "Race for the Top Quark" fred11 Particle 0 Tue Aug 16, 2005 7:42 pm Factorizations of deterministic automata Jerry Swan Research 0 Tue Apr 05, 2005 10:42 am