Python Forum
how do I show 12 numbers from a huge number?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do I show 12 numbers from a huge number?
#11
Not necessarily.
>>> 2**3**2
512
>>> (2**3)**2
64
>>> 2**(3**2)
512
>>> 
In selected cases it may be the same but not always.

Anyway, I tried using Decimal, other ideas and other than brute force slow I am at some loss. The answer, of course, is a binary expression of all zeros except for a 1 in the 1.717... billionth place.

Since the professor did not specify that it has to be in base 10 you could express this in base 2 and be done, but I think that will get you an F, or maybe a C- for cleverness.
Reply
#12
you also get the same result (512) for first and third case:-) Note - I corrected myself immediately
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#13
(Sep-02-2019, 11:45 AM)perfringo Wrote: At the beginning there is "2 ** 2 ** 34 (two raised to two that is raised to thirty-four)" but later of it's changed to "It's 2**(2**34)". Which is correct?

[Image: oFWug5s]

(Sep-02-2019, 12:46 PM)jefsummers Wrote: Not necessarily.
>>> 2**3**2 512 >>> (2**3)**2 64 >>> 2**(3**2) 512 >>> 
In selected cases it may be the same but not always. Anyway, I tried using Decimal, other ideas and other than brute force slow I am at some loss. The answer, of course, is a binary expression of all zeros except for a 1 in the 1.717... billionth place. Since the professor did not specify that it has to be in base 10 you could express this in base 2 and be done, but I think that will get you an F, or maybe a C- for cleverness.

thanks for your help but i really need the first 12 digits and the last 12 digits. I don't want the number represented in any base. do you think it is impossible to get the result?
Reply
#14
It can certainly be done. I've been trying to figure an easier way than this, but here is one certain way:
1. create a list. The elements of this list will reflect the individual digits of your number. Initialize this list to 2.
2. Calculate 2**34.
3. Create a loop 1 to 2**34. In that loop you will multiply the current value (represented by the list) by 2. You will perform the multiplication the way you did in 3rd grade - multiply by the first digit, if greater than 10 then subtract 10 to keep the digit in range and carry the 1. Then multiply the next digit and add the carry until you have multiplied by all the digits. If there is a carry on the last digit add an element with the value of the carry (1).
4. Test this with a short loop to make sure it is working properly. Looping to 4 should give you a list of (6,1). Looping to 8 should give a list of (8,2,1).
5. Once this process is debugged, run it for the full loop overnight. It will take that long no matter how much memory you have. A fast processor will help.
6. 12 largest digits are the last 12 elements of the list, 12 smallest are the first 12.

That is -A- way to do it. I bet there are better, but I have not found one.
Reply
#15
jefsummers Wrote:I bet there are better, but I have not found one.
Some knowledge of modular arithmetic may help for this task.
Reply
#16
(Sep-02-2019, 02:50 PM)jefsummers Wrote: It can certainly be done. I've been trying to figure an easier way than this, but here is one certain way:
1. create a list. The elements of this list will reflect the individual digits of your number. Initialize this list to 2.
2. Calculate 2**34.
3. Create a loop 1 to 2**34. In that loop you will multiply the current value (represented by the list) by 2. You will perform the multiplication the way you did in 3rd grade - multiply by the first digit, if greater than 10 then subtract 10 to keep the digit in range and carry the 1. Then multiply the next digit and add the carry until you have multiplied by all the digits. If there is a carry on the last digit add an element with the value of the carry (1).
4. Test this with a short loop to make sure it is working properly. Looping to 4 should give you a list of (6,1). Looping to 8 should give a list of (8,2,1).
5. Once this process is debugged, run it for the full loop overnight. It will take that long no matter how much memory you have. A fast processor will help.
6. 12 largest digits are the last 12 elements of the list, 12 smallest are the first 12.

That is -A- way to do it. I bet there are better, but I have not found one.

I will try to create some code based on your comment. Maybe I'll ask you for help with step three
Reply
#17
Guys, I found the first 12 digits on a site, now I just need to know how to display the numbers within e+
[Image: SPDDNjx]
Reply
#18
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.
Reply
#19
I believe that applying principles laid out in How to Find the Last Digits of a Positive Power of Two and Patterns in the Last Digits of the Positive Powers of Two could make solving this task much less resource hog.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#20
You have to understand the math to solve this task.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,428 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  Convert list of numbers to string of numbers kam_uk 5 3,021 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Divide a number - Multiple levels - Sum of all numbers equal to input number pythoneer 17 8,835 Apr-20-2018, 04:07 AM
Last Post: pythoneer
  Trying to get the week number from a string of numbers fad3r 2 3,213 Apr-15-2018, 06:52 PM
Last Post: ljmetzger
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,115 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020