Nп/п : 8 из 100
 От   : Paul Rubin                          2:5075/128        17 сен 23 15:54:12
 К    : Francesc Rocher                                       17 сен 23 01:59:02
 Тема : Re: project euler 29
----------------------------------------------------------------------------------
                                                                                 
@MSGID: <874jjsquln.fsf@nightsong.com> acdb2e78
@REPLY:
<715fe49a-47bc-46be-ae26-9ed89b38bcb5n@googlegroups.com> 6604d745
@REPLYADDR Paul Rubin <no.email@nospam.invalid>
@REPLYTO 2:5075/128 Paul Rubin
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: <874jjsquln.fsf@nightsong.com>
<beaa0494-5783-4130-b96f-1a5271466678n@googlegroups.com><874jjvmoi9.fsf@bsb.me.u
k><a10a258f-8a3a-4017-bb30-8fe5629089ffn@googlegroups.com><87sf7dltq0.fsf@bsb.me
.uk><87jzsplr49.fsf@bsb.me.uk><715fe49a-47bc-46be-ae26-9ed89b38bcb5n@googlegroups.co
m>
@TZUTC: -0700
@PID: Gnus/5.13 (Gnus v5.13) Emacs/27.1
(gnu/linux)
@TID: FIDOGATE-5.12-ge4e8b94
Francesc Rocher <francesc.rocher@gmail.com> writes:
> Also, do you have a different approach to solve this 29th problem?

I see two natural approaches: 1) use bignums--it didn`t occur to me to
not use them until this discussion.  2) Notice that a**b == c**d exactly
when the two sides have the same prime factorization, and the factors
of a**b are just the factors of a repeated b times, so you can count up
the distinct tuples of factors.

Method #2 is efficient (since a,b,c,d are all < 100) and doesn`t use
bignums, but it is a fair amount of code to write unless you have
convenient libraries at hand for factorization and can easily count sets
of distinct tuples.  I guess there are fancier approaches possible too,
that avoid searching 100**2 combinations, but 100**2 is just 10000 which
is small.

Certainly both are easier to do if your language or libraries has
convenient features for dealing with variable sized objects like
bignums, or sets of tuples.  The bignum approach is less efficient but
it is much easier to code.  The Python expression

  len(set(a**b for a in range(2,101) for b in range(2,101))) 

takes around 25 msec to compute on my old slow laptop.

I will look at your Ada solution!  
--- Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх