Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #31  
Old November 9th, 2012, 07:55 PM
KING-OLE KING-OLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Texas
Posts: 24 KING-OLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 45 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
The division part of your program might be faster using divmod. Then again, you might end up storing a bunch of really long unused quotients. Don't know.
Code:
>>> help(divmod)
Help on built-in function divmod in module __builtin__:

divmod(...)
    divmod(x, y) -> (quotient, remainder)
    
    Return the tuple ((x-x%y)/y, x%y).  Invariant: div*y + mod == x.


Thanks for the divmod tip, but in this case it won't help, as I don't want to i/p unless p is a factor of i, in which case there won't be a remainder.

Reply With Quote
  #32  
Old November 10th, 2012, 10:39 AM
KING-OLE KING-OLE is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Location: Texas
Posts: 24 KING-OLE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 45 sec
Reputation Power: 0
Update:

Found a faster way of doing it.

Instead of creating strings and converting them to integers, I multiply the last integer to get the new:
Code:

  oldone=i
  bigone=10**(10**(n-1))

  for cnt in range (1,10):
    i*=bigone
    i+=oldone


Results:

Using the i=str('1'**n) solution takes about 12 minutes for 1 <= n <= 7:
Code:

07:53:01:65 - Start
08:05:00.80 - Finish


New solution, taking the previous i and multiplying it with 10**(10**(n-1)) and adding i back 9 times is a lot faster, taking only about 3 minutes and 5 seconds:
Code:

08:39:47:89 - Start
08:42:52.49 - Finish


Modifying the new solution to div i with the prime factor found, as well as searching the primes reversed (high to low) is about the same, about 1 second faster than the previous:
Code:

08:45:44.06 - Start
08:48:49.00 - Finish

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > String to Int conversion speed

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap