btatango.blogg.se

Bingo caller 1 75
Bingo caller 1 75













bingo caller 1 75

Instead of the long list of if-statements, you could use the simple relation between the prefix's position in the word "BINGO" and the random number to extract it as: string bingo = "BINGO" // Make it a class field. It will run forever between goto Start and Start: when the list is full. It seems that GetNumber() is missing a stop-condition. Instead you could use a while-loop in a kind of this manner: while (list.Count = 61) it is more readable to write if (item > 60)

bingo caller 1 75

It is considered bad practice to use goto-statements in modern programming because it quickly gets hard to follow the structure, so avoid that. Unfortuantelly the C# 7 version does not work on Codewars but it looks nice too public string GetNumber()Īnd with one local function we could encapsulate the while condition: private int? NextNumber() The HashSet's Add method returns true if a value could be added so we can use it with a while loop until we find the next not yet drawn number.

bingo caller 1 75

The trick is to use a HashSet for tracking drawn numbers that has a lookup of O(n) and to stop drawing new numbers if all 75 numbers has already been drawn because calls to the Next(.) method are expensive and the execution time unnecessarily increases. Pass via the constructor for testing purposes.

bingo caller 1 75

Use System.Random to generate your random numbers. These are the ranges that you must follow:Ī number within range 1 to 15 starts with a 'B'Ī number within range 16 to 30 starts with an 'I'Ī number within range 31 to 45 starts with an 'N'Ī number within range 46 to 60 starts with a 'G'Ī number within range 61 to 75 starts with an 'O' The numbers are returned one by one in Bingo style: If there are no numbers left, return an empty string Return all numbers in the range of 1 until 75 once and in random order I need help optimizing my code so it can run faster. I am dong a competitive programming problem I have passed all the tests.īut my program times out.















Bingo caller 1 75