Python Forum
this weekend's python class assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
this weekend's python class assignment
#3
i was interested in seeing how people would address or solve or deal with extremely large numbers and what algorithmic optimization they might use, if any, like finding how big the number is. one method for base 2 is to just call bin() and let it do all the hard work, no matter how big the number is. this is basically the same problem of converting a number to a sequence of digits as your solution shows.

if someone asks for code to find the next power of 2 after a number n you can simply do:
print('2**'+str(len(bin(n))-2))
is this cheating? of course not. it's finding the quickest solution, quickly, and moving on to the next task.

if Python had a function to do that in any base (surely there is one somewhere) that would be the one to use for the any-base case. i have implemented one, but it's a mess right now. maybe i'll clean it up this weekend if i have time.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: this weekend's python class assignment - by Skaperen - Apr-20-2019, 08:09 AM

Forum Jump:

User Panel Messages

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