Posts: 16
Threads: 1
Joined: Aug 2019
(Sep-03-2019, 01:36 AM)jefsummers Wrote: I don't think finding on a site is the point. If the prof wants you to show your work showing a web search will get you a worse grade then answering in base 2.
What is this project aiming to teach? That is where you need to go.
No matter the source, the teacher just wants the first 12 digits and the last 12 digits. He was explaining to us how many bytes are generated per day. (or per day, or per year, I don't remember exactly)
Posts: 4,803
Threads: 77
Joined: Jan 2018
Sep-03-2019, 04:06 PM
(This post was last modified: Sep-03-2019, 04:06 PM by Gribouillis.)
anabeatriz Wrote:No matter the source, the teacher just wants the first 12 digits and the last 12 digits. Are you sure he is a teacher? You could hire a freelance programmer to do the job, your teacher would probably be delighted! All this is not serious.
Posts: 16
Threads: 1
Joined: Aug 2019
(Sep-03-2019, 04:06 PM)Gribouillis Wrote: anabeatriz Wrote:No matter the source, the teacher just wants the first 12 digits and the last 12 digits. Are you sure he is a teacher? You could hire a freelance programmer to do the job, your teacher would probably be delighted! All this is not serious.
calm down, it's just a challenge!
Posts: 1,358
Threads: 2
Joined: May 2019
As an aside, although modular math and abstract algebra can be useful for this problem, the difficulties he is having suggests this is a 100 level course. When I took abstract algebra, back in the paleozoic age, it was a 300 level course. I would not expect the 100 level course to have a 300 as a prerequisite, so the teacher is likely thinking about other solutions.
At this point I am in the postgraduate education biz. When I am teaching (not anything related to math anymore) I am recommending the student look at the problem from the point of view of "what is my instructor trying to get me to learn from this". Having extra info is always nice, but not necessarily what is being looked for.
When I took assembler we were assigned to create a function that would return successive numbers in the fibonacci sequence. Extra credit for doing it in 10 instructions or less. I did it in 4, but used some special knowledge. Prof was impressed but did not recommend that approach to the rest of the class.
Just sayin'
Posts: 16
Threads: 1
Joined: Aug 2019
Now I just need a way to find the first 12 digits! (The first 12 digits I found on a website are wrong) Please help me.
Posts: 2,128
Threads: 11
Joined: May 2017
Sep-10-2019, 07:20 AM
(This post was last modified: Sep-10-2019, 07:20 AM by DeaD_EyE.)
I have to look in my Math-book. Maybe there is a solution: http://weitz.de/KMFI/
The book is good, but it's only in German. He uses Python to explain math.
With modular arithmetic you get the last x digits of the solution.
The built-in function pow supports it.
The equation is: 2 ** (2 ** 34)
pow(2, 2**34, 10**12) This should calculate the last 12 digits of 2 ** (2**34)
The other solution to get the first x digits can may be done with iteration.
def ipow(x, y, digits):
for _ in range(y - 1):
x *= x
# do something to truncate x?
# maybe working with math.log10 By the way, this question is very old: https://stackoverflow.com/questions/6351...e-required
Another solution is the usage of math.log10: https://stackoverflow.com/questions/3873...nentiation
def get_first_digits(a, b, n):
x = b * math.log10(a)
y = math.floor(pow(10, x - math.floor(x) + n - 1))
return int(y) Output: In [65]: get_first_digits(2,2**34,12)
Out[65]: 927436539881
Posts: 1,358
Threads: 2
Joined: May 2019
BTW - for "fun" I did my method of treating each digit as an element in a list, ran it in IDLE, Python 3.7, on a core i7 3.4GHz 16gig machine over the weekend. In 72 hours it got to about the 3.5 millionth power. Unfortunately it needs to get to the 17 billionth. Since by necessity it runs progressively slower (more digits to multiply) this method would not be done by December!
Again for fun I'm running overnight using iPython and numpy to see if that speeds things up, same computer.
J
Posts: 16
Threads: 1
Joined: Aug 2019
(Sep-10-2019, 11:22 AM)jefsummers Wrote: BTW - for "fun" I did my method of treating each digit as an element in a list, ran it in IDLE, Python 3.7, on a core i7 3.4GHz 16gig machine over the weekend. In 72 hours it got to about the 3.5 millionth power. Unfortunately it needs to get to the 17 billionth. Since by necessity it runs progressively slower (more digits to multiply) this method would not be done by December!
Again for fun I'm running overnight using iPython and numpy to see if that speeds things up, same computer.
J What code did you use for this?
Posts: 1,358
Threads: 2
Joined: May 2019
This is the homework board so can't give you the code, but if you look back a few posts I gave you the layout of how I would write it. It was kind of like elementary school math - multiply the first digit/list element by 2, if greater than 10 subtract 10 and carry the 1. Proceed through all the digits. Oh, and important to test with a shorter loop, like calculating 2**16 before tackling 2**(2**34).
Posts: 16
Threads: 1
Joined: Aug 2019
(Sep-10-2019, 07:20 AM)DeaD_EyE Wrote: I have to look in my Math-book. Maybe there is a solution: http://weitz.de/KMFI/ The book is good, but it's only in German. He uses Python to explain math. With modular arithmetic you get the last x digits of the solution. The built-in function pow supports it. The equation is: 2 ** (2 ** 34) pow(2, 2**34, 10**12) This should calculate the last 12 digits of 2 ** (2**34) The other solution to get the first x digits can may be done with iteration. def ipow(x, y, digits): for _ in range(y - 1): x *= x # do something to truncate x? # maybe working with math.log10 By the way, this question is very old: https://stackoverflow.com/questions/6351...e-required Another solution is the usage of math.log10: https://stackoverflow.com/questions/3873...nentiation def get_first_digits(a, b, n): x = b * math.log10(a) y = math.floor(pow(10, x - math.floor(x) + n - 1)) return int(y) Output: In [65]: get_first_digits(2,2**34,12) Out[65]: 927436539881
Thank you, I will show 927436539881 to my teacher and then you will know his answer
|