for this problem I want to know how to know is there an easy way to store a large number like 100 ** 100, and how do U make a similar function like "set(context)" to delete the duplicated value in a vector.
Now this time, I am facing trouble for problem #29. As I know integer
type is for 32 bits. but for this problem as me to find out the 2 **
100 and even 100 ** 100. I used python to get the answer correctly in
5 minutes.
context = []
for a in range(2,101):
for b in range(2,101):
context.append(a**b)
len(list(set(context)))
I know the algorithm is easy, but I am pretty interesting how to
calculate a large like it.
As I know integer type is for 32 bits. but for this problem as me to find out the 2 ** 100 and even 100 ** 100.
can only be compiled with GNAT. Note that, unlike PragmARC.Unbounded_Numbers.Integers, GNAT's implementation of Ada.Numerics.Big_Numbers.Big_Integers is not truly unbounded. I don't
know if it will hold 101 ** 101 without modification.
"CSYH (QAQ)" <sche...@asu.edu> writes:
Now this time, I am facing trouble for problem #29. As I know integer
type is for 32 bits. but for this problem as me to find out the 2 **
100 and even 100 ** 100. I used python to get the answer correctly in
5 minutes.
Most of the Project Euler problems have solutions that are not always
the obvious one (though sometimes the obvious one is the best). You
can, of course, just use a big number type (or write your own!) but this problem can be solved without having to use any large numbers at all.
El dia divendres, 15 de setembre de 2023 a les 17:42:43 UTC+2, Ben Bacarisse va escriure:
"CSYH (QAQ)" <sche...@asu.edu> writes:
Now this time, I am facing trouble for problem #29. As I know integer
type is for 32 bits. but for this problem as me to find out the 2 **
100 and even 100 ** 100. I used python to get the answer correctly in
5 minutes.
Most of the Project Euler problems have solutions that are not always
the obvious one (though sometimes the obvious one is the best). You
can, of course, just use a big number type (or write your own!) but this
problem can be solved without having to use any large numbers at all.
Please take a look at this solution: https://github.com/rocher/alice-project_euler-rocher/blob/main/src/0001-0100/p0029_distinct_powers.adb
Francesc Rocher <francesc.rocher@gmail.com> writes:
El dia divendres, 15 de setembre de 2023 a les 17:42:43 UTC+2, Ben Bacarisse va escriure:
"CSYH (QAQ)" <sche...@asu.edu> writes:
Now this time, I am facing trouble for problem #29. As I know integer
type is for 32 bits. but for this problem as me to find out the 2 **
100 and even 100 ** 100. I used python to get the answer correctly in
5 minutes.
Most of the Project Euler problems have solutions that are not always
the obvious one (though sometimes the obvious one is the best). You
can, of course, just use a big number type (or write your own!) but this >>> problem can be solved without having to use any large numbers at all.
Please take a look at this solution:
https://github.com/rocher/alice-project_euler-rocher/blob/main/src/0001-0100/p0029_distinct_powers.adb
Why?
Ben Bacarisse <ben.u...@bsb.me.uk> writes:
Francesc Rocher <frances...@gmail.com> writes:
El dia divendres, 15 de setembre de 2023 a les 17:42:43 UTC+2, Ben Bacarisse va escriure:
"CSYH (QAQ)" <sche...@asu.edu> writes:
Now this time, I am facing trouble for problem #29. As I know integer >>> > type is for 32 bits. but for this problem as me to find out the 2 ** >>> > 100 and even 100 ** 100. I used python to get the answer correctly in >>> > 5 minutes.
Most of the Project Euler problems have solutions that are not always
the obvious one (though sometimes the obvious one is the best). You
can, of course, just use a big number type (or write your own!) but this >>> problem can be solved without having to use any large numbers at all.
Please take a look at this solution:
https://github.com/rocher/alice-project_euler-rocher/blob/main/src/0001-0100/p0029_distinct_powers.adb
Why?That came over as rather curt. I meant what is it about the code that
you are drawing my attention to -- its particular use of Ada, its
structure, the algorithm, the performance...? What (and where) is Euler_Tools?
Also, do you have a different approach to solve this 29th problem?
El dia dissabte, 16 de setembre de 2023 a les 23:56:11 UTC+2, Ben Bacarisse va escriure:
Ben Bacarisse <ben.u...@bsb.me.uk> writes:
Francesc Rocher <frances...@gmail.com> writes:That came over as rather curt. I meant what is it about the code that
El dia divendres, 15 de setembre de 2023 a les 17:42:43 UTC+2, Ben Bacarisse va escriure:
"CSYH (QAQ)" <sche...@asu.edu> writes:
Now this time, I am facing trouble for problem #29. As I know integer >> >>> > type is for 32 bits. but for this problem as me to find out the 2 ** >> >>> > 100 and even 100 ** 100. I used python to get the answer correctly in >> >>> > 5 minutes.
Most of the Project Euler problems have solutions that are not always
the obvious one (though sometimes the obvious one is the best). You
can, of course, just use a big number type (or write your own!) but this >> >>> problem can be solved without having to use any large numbers at all.
Please take a look at this solution:
https://github.com/rocher/alice-project_euler-rocher/blob/main/src/0001-0100/p0029_distinct_powers.adb
Why?
you are drawing my attention to -- its particular use of Ada, its
structure, the algorithm, the performance...? What (and where) is
Euler_Tools?
Well, I was sending the answer to the thread, not to anyone in
particular.
I simply thought that, since you mention that this can be solved
without having to use big numbers, people in this group could be
interested in seeing how. My solution to this problem dates back to
earlier this year, when I solved the first 30 problems of Project
Euler.
Euler_Tools is a repository of functions that I'm collecting while
solving new problems of Project Euler. In case you want to take a
look, https://github.com/rocher/euler_tools
Also, do you have a different approach to solve this 29th problem?
Also, do you have a different approach to solve this 29th problem?
Yes, but it's not in Ada. I implemented an equality test for a^b ==
c^d.
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
Also, do you have a different approach to solve this 29th problem?
Yes, but it's not in Ada. I implemented an equality test for a^b ==
c^d.
Oh interesting, based on a comment in Francesc's code, I think I see a
method to do it without the auxiliary array, at a small increase in
runtime cost. Basically given a and b, you can find their prime factors
and easily enumerate the combinations x,y with a**b==x**y and
1 <= x,y <= 100. You can label each "equivalence class" by the (a,b)
with the smallest possible a.
So you just loop through 1 <= a,b <= 100 and count only the a,b pairs
where a is the smallest a for its equivalence class. I might see if I
can code this, which should also let me describe it more concisely.
So you just loop through 1 <= a,b <= 100 and count only the a,b pairsThis is likely to be fast which is why I wanted to compile Francesc's to
where a is the smallest a for its equivalence class.
try it out. Mind you, a naive a^b == c^d test gives pretty good
performance for the kind of range requested.
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
So you just loop through 1 <= a,b <= 100 and count only the a,b pairsThis is likely to be fast which is why I wanted to compile Francesc's to
where a is the smallest a for its equivalence class.
try it out. Mind you, a naive a^b == c^d test gives pretty good
performance for the kind of range requested.
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.
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.
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,
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?
If anyone is interested, for performance comparison or whatever reason, I can provide a stand alone version.
I am curious, but only if it's not too much work.
$ git clone git@github.com/rocher/euler_tools
fatal: repository 'git@github.com/rocher/euler_tools' does not exist
Typo: it should be g...@github.com:rocher/euler_tools
$ git clone g...@github.com/rocher/euler_tools
fatal: repository 'g...@github.com/rocher/euler_tools' does not exist
I am curious, but only if it's not too much work.
Pre-condition: alr must be installed in your system.
Then, three simple steps:
1. this: git clone git@github.com/rocher/euler_tools
or: git clone https://github.com/rocher/euler_tools
2. cd euler_tools/examples
3. alr build
Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
$ git clone git@github.com/rocher/euler_tools
fatal: repository 'git@github.com/rocher/euler_tools' does not exist
Try the https link instead.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:31:47 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,858,054 |