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?
#1
I want the answer of this expression using python: 2 ** 2 ** 34 (two raised to two that is raised to thirty-four) but I only need the first 12 and last 12 numbers of the result of this expression. How can I solve this problem? It is a homework. The deadline is until December this year.
Reply
#2
What have you done so far?
Likely you will use / (division) and % (mod)
Reply
#3
(Sep-01-2019, 12:14 AM)jefsummers Wrote: What have you done so far?
Likely you will use / (division) and % (mod)


I already ran two codes:
n = 2
for c in range (2, 34+2):
   print("\n", n)
   n = n * n
The code above will show all thirty-four terms. But when I execute it, Pycharm crashes

and

n = str(2 ** 2 ** 34)
print(str(n[:12]))
The code above will show the last number (which is in the thirty-fourth term) but only the first 12 digits will appear on the screen. When I run it, Pycharm crashes

should I run them on a computer that has more memory?
Reply
#4
So I understand the problem, is it (2**2)**34 or 2**(2**34)? The way written it would be the former which would be 4**34 as a first step
Reply
#5
If it was as easy as calculating the number and converting it to a string, I expect your professor would not have given you until December to solve it. Especially not if it's crashing Pycharm. Note that if you only care about the last 12 digits, you only need to keep the last 12 digits. You could keep trimming off the extra digits, and use a loop to calculate the right number of multiplications. You will probably need to break down the number to keep the number of loops you need to do down.

The higher end would be trickier, since the lower digits still multiply and can thus bleed up into the higher digits. I would look at the higher powers of 2 that you can calculate and see if there are any patterns you can use to solve the problem.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
(Sep-01-2019, 02:15 AM)jefsummers Wrote: So I understand the problem, is it (2**2)**34 or 2**(2**34)? The way written it would be the former which would be 4**34 as a first step

It's 2**(2**34)

(Sep-01-2019, 03:41 AM)ichabod801 Wrote: If it was as easy as calculating the number and converting it to a string, I expect your professor would not have given you until December to solve it. Especially not if it's crashing Pycharm. Note that if you only care about the last 12 digits, you only need to keep the last 12 digits. You could keep trimming off the extra digits, and use a loop to calculate the right number of multiplications. You will probably need to break down the number to keep the number of loops you need to do down.

The higher end would be trickier, since the lower digits still multiply and can thus bleed up into the higher digits. I would look at the higher powers of 2 that you can calculate and see if there are any patterns you can use to solve the problem.

I need the first 12 digits and the last 12 digits. How would you solve this problem with code?
Reply
#7
(Sep-01-2019, 12:56 PM)anabeatriz Wrote: How would you solve this problem with code?

We're not going to write your code for you. We'd be happy to help you fix problems with your code, but before we can do that, you need to write some code.

I'm not even sure what the solution is, I just posted the direction I would take.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
(Sep-01-2019, 01:09 PM)ichabod801 Wrote:
(Sep-01-2019, 12:56 PM)anabeatriz Wrote: How would you solve this problem with code?

We're not going to write your code for you. We'd be happy to help you fix problems with your code, but before we can do that, you need to write some code.

I'm not even sure what the solution is, I just posted the direction I would take.


I already ran two codes:
n = 2
for c in range (2, 34+2):
   print("\n", n)
   n = n * n
and

n = str(2 ** 2 ** 34)
print(str(n[:12]))
but both take a long time to show the answer. Should I run them on a computer that has more memory?
Reply
#9
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?
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
#10
actually the result of 2**2**34, (2**2)**34 and 2**(2**34) is the same
ups Rolleyes Blush

>>> 2**2**3
256
>>> (2**2)**3
64
>>> 2**(2**3)
256
>>> 
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


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,022 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