comp.lang.ada
 help / color / mirror / Atom feed
From: Francesc Rocher <francesc.rocher@gmail.com>
Subject: Re: project euler 29
Date: Mon, 18 Sep 2023 06:04:21 -0700 (PDT)	[thread overview]
Message-ID: <7a98a430-a01d-41e7-80fe-bc2e1e1592d3n@googlegroups.com> (raw)
In-Reply-To: <87wmwnk9a9.fsf@bsb.me.uk>

> > But Francesc's program doesn't use that method. It only suggests it in 
> > a comment. The program actually works by building a list, sorting it, 
> > and counting the groups.

> I only looked briefly and thought it used the factor method to decide if 
> the power is one that occurs earlier in the sequence. Two trivial 
> things, starting with Answer as the full NxN count and then decrementing 
> Answer made me think that was what it was doing. 

Exactly, that's the point: to find if for a given base+exponent a**b there is an
equivalent x**y with  2 <= a < x <= 100  and  2 <= y <= 100, first a and b are
factored as a product of prime numbers. In case a has multiple times the same
factor, e.g. 27 = 3*3*3 = 3**3, then the exponent 3 is used as a new factor of the
exponent. Introducing this factor requires that the list of factors of b must be
sorted to find a new base x, a < x. Otherwise you could find x > 100 and consider
that there is no such pair x and y within the limits. That's the only reason the list
of factors is sorted when a new one is introduced.

Example:
   27**100 = (3*3*3)**(2*2*5*5)
           = (3**3)**(2*2*5*5)
           = 3**(2*2*3*5*5)
           = 9**(2*3*5*5)
           = 81**(3*5*5)
           = 81**75

On the other hand, the algorithm first assumes that all possible combinations of
a**b are unique, and then subtracts 1 each time x and y are found for a and b.

Implementing the equality operator for a**b = x**y is also an alternative algorithm.
Using it would require a loop for a in 2..99, b in 2..100, x in a+1..100  and y in 2..100.
Is this correct? Or are there other constraints?

Anyway, for big numbers, having the equality operator a**b = x**y with the factoring
method is a good idea.

Unfortunately, my Project Euler programs are prepared to be inserted into the new Alice
project, which is a (big) work in progress and cannot be compiled easily (it requires
Alire, Project Euler for Alice and my sources, which depend on the Euler Tools).
If anyone is interested, for performance comparison or whatever reason, I can
provide a stand alone version.


BR,
-- Francesc Rocher

  reply	other threads:[~2023-09-18 13:04 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  9:03 project euler 29 CSYH (QAQ)
2023-09-15  9:50 ` Jeffrey R.Carter
2023-09-15 18:04   ` Keith Thompson
2023-09-15 15:42 ` Ben Bacarisse
2023-09-16 10:07   ` Francesc Rocher
2023-09-16 20:59     ` Ben Bacarisse
2023-09-16 21:56       ` Ben Bacarisse
2023-09-17 18:56         ` Francesc Rocher
2023-09-17 22:54           ` Paul Rubin
2023-09-17 23:08           ` Ben Bacarisse
2023-09-18  0:09             ` Paul Rubin
2023-09-18  0:16               ` Ben Bacarisse
2023-09-18  5:16                 ` Paul Rubin
2023-09-18 11:31                   ` Ben Bacarisse
2023-09-18 13:04                     ` Francesc Rocher [this message]
2023-09-18 14:20                       ` Ben Bacarisse
2023-09-18 16:55                         ` Francesc Rocher
2023-09-18 19:22                           ` Ben Bacarisse
2023-09-18 19:38                             ` Paul Rubin
2023-09-18 19:52                               ` comp.lang.ada
2023-09-18 19:56                                 ` comp.lang.ada
2023-09-18 20:01                               ` Ben Bacarisse
2023-09-15 16:34 ` Jeffrey R.Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox