# SPUG: FW: Help..Any Math GENIUS out there?

Thu Jul 25 16:01:56 CDT 2002

```At first I thought you were attempting to convert a base 10 number into base
36.  The general solution for that type of problem is to repeatedly divide
your source number by the base (in this case 36) and collect the remainders.
Something like:

my \$n = 2_307_012;
my @r = ( );

print "start:           \$n\n";

while (\$n)
{
push @r, \$n % 36;
\$n = int(\$n / 36);
}

my  \$i = ord('A');
my  \$d = 1;

map {
printf "%c=%2d x %7d = %7d\n", \$i++, \$_, \$d, \$_ * \$d;
\$n += \$_ * \$d;
\$d *= 36;
} @r;

print "total:           \$n\n";

Then I looked at it again and that's not in fact what you're doing.  There
is a pattern to the numbers, but it's not multiplying by 36 each time.  So I
modified the general solution to use a list to represent the multipliers:

my  \$n = 2_307_012;
my  @r = ( );
my  @z = ( 36, 10, 10, 36 );

print "start:           \$n\n";

map {
push @r, \$n % \$_;
\$n = int(\$n / \$_);
} @z;

push @r, \$n;
\$n = 0;

my  \$a = ord('A');
my  \$d = 1;

for (my \$i = 0; \$i < @r; \$i++)
{
printf "%c=%2d x %7d = %7d\n", \$a + \$i, \$r[\$i], \$d, \$r[\$i] * \$d;
\$n += \$r[\$i] * \$d;
\$d *= \$z[\$i];
}

printf "total:           %7d\n", \$n;

which seems to work on my system (W2K using Perl 5.8).  Caveat:  I didn't do
a lot of testing.

mma

> -----Original Message-----
> From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org]On Behalf Of
> Orr, Chuck (NOC)
> Sent: Thursday, July 25, 2002 10:51 AM
> To: 'spug-list at pm.org'
> Subject: SPUG: FW: Help..Any Math GENIUS out there?
>
>
>
>
> > Hello,
> >
> > I am hoping to use Perl to solve an equation like the below:
> >
> > A + (36*B) + (360*C) + (3600*D) + (129600*E) = 2,307,012
> >
> > I know that each of the variables A - E is a whole number in the range
> > 1-36.
> >
> > Could I load those numbers (1 -36) in an array and substitute
> each number
> > for each variable until this is solved?
> >
> > Any ideas would be greatly appreciated.
> >
> >
> > Thanks,
> > Chuck Orr
> > AT&T Wireless Services
> > 425 288 2386
> > chuck.orr at attws.com
>
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>
>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL