Home > Computer Programming > Towers of Powers – Perfect Base Program!

Towers of Powers – Perfect Base Program!

Hello !

One of the many problems in computer-generated graphics is realistically modeling the "orderly randomness" of things like mountain ranges and city skylines. Using fluctuations in number representations to model height can be used in such case. So in this case we compute several such number representations and show the "skylines" they produce.

Let n be any positive integer, and let b be an integer greater than or equal to 2. The complete base-b expansion of n is obtained as follows. First write the usual base-b expansion of n, which is just a sum of powers of b, each multiplied by a coefficient between 1 and b-1, omitting terms with zero coefficients. For example, if n = 20000 and b = 3, the base-3 expansion of 20000 is given by

20000 = 3^9 + 3^5 + 2*3^3 + 2

To obtain the complete base-b expansion, we apply the same procedure to the exponents until all numbers are represented in base b. For n = 20000 and b = 3 we would have

20000 = 3^3^2 + 3^(3+2) + 2*3^3 + 2*3^3 + 2

This is a real challenging problem to solve . I solved it once in an In-House competition and once in a Nation wide programming competition. Here is the C++ source code of solution

void perfectBase(unsigned long, unsigned long);
unsigned long calculateMultiple(unsigned long, unsigned long, unsigned long);
void function(unsigned long, const char *);

char * str , * ptr;

unsigned long number = 200000 , base = 64789;
str = new char[500] , ptr = new char[50];
strcpy(ptr,"") , strcpy(str,"");
//ofstream O("d:\\perfbase.txt");
textmode(C80), textcolor(WHITE), clrscr();

//O 1)
function( multiple, "*");
if(power >= base){
function( base,"^");
if( power>base)
function( -1,"(");
perfectBase( power,base);
if( power>base)
function( -1,")");
if( power==1)
function( base,"");
if( power==0)
function( 1,"");
function( base,"^");
function( power,"");
if(remNumber > 0 && remNumber

Categories: Computer Programming
  1. July 21, 2006 at 8:54 am

    Very Very nice information here… Thanks

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: