Python Forum
Can someone help me optimize this game for large number of strings
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone help me optimize this game for large number of strings
#9
(Jun-27-2020, 07:56 PM)GOTO10 Wrote: From your test case using "BANANA", you know that Stuart's score (count of substrings beginning with a consonant) is 12. Note that there are 6 substrings that begin with B (B, BA, BAN, BANA, BANAN, BANANA), 4 substrings that start with the first N (N, NA, NAN, NANA), and 2 that start with the final N (N, NA). That adds up to 12.
My code is okay for the banana test case. Where it fails is where the string input is very long, like 100,000 characters. I want something that would scale to a string that is unknown of such a length. I followed your recommendation and what you described above is what I have done. See the last code above. I have removed the inner loop and counted the strings directly. But still, it doesn't scale to high string lengths.

(Jun-27-2020, 07:28 PM)deanhystad Wrote: Why do you test if the letter is in vowels and then test if it is not in vowels?
That is the essence of the game. Given a string, count the number of substrings that start with a vowel, then count the number of substrings that start with a consonant. Then, print out the higher score, and if a draw, print out that it is the same score. My code scales for medium number of string lengths, but for high number of string lengths, like lengths of 100,000 characters, it fails to run to completion within the set time. I am looking for how to make it scale to such high string lengths.
Reply


Messages In This Thread
RE: Can someone help me optimize this game for large number of strings - by Emekadavid - Jun-27-2020, 08:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help - random number/letter guessing game juin22 1 3,210 Aug-16-2020, 06:36 AM
Last Post: DPaul
  Dynamically chosing number of players in a "game" nsadams87xx 5 4,189 Jul-17-2020, 02:00 PM
Last Post: deanhystad
  making a guessing number game blacklight 1 2,210 Jul-02-2020, 12:21 AM
Last Post: GOTO10
  Guess the number game jackthechampion 5 3,206 Mar-07-2020, 02:58 AM
Last Post: AKNL
  Asking for help in my code for a "Guess the number" game. Domz 5 3,829 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Guess a number game Drone4four 4 5,285 Nov-16-2018, 03:56 AM
Last Post: Drone4four
  Strings inside other strings - substrings OmarSinno 2 3,691 Oct-06-2017, 09:58 AM
Last Post: gruntfutuk
  trying to get my random number guessing game to work! NEED HELP RaZrInSaNiTy 4 6,906 Oct-06-2016, 12:49 AM
Last Post: tinabina22

Forum Jump:

User Panel Messages

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