1713210742

Code challenge for you programmer


Here's a programming challenge for you - A Lottery Picker. 1) Must not repeat the same number in one pick. 2) Picks cannot be identical in a batch of games. 3) User must control what the max. number will be, 1=< is not valid. 4) User must control how many numbers per game.4< is not valid. 5) User must control how many games per run, 1< is not valid. 6) Extra points if you put in a Special Number as most lotteries have. Good Luck !

To comment this publication you need to be logged in.
fschmidt
fschmidt
0

Cyberat, The "repeat" loops prevent duplicates.


Cyberat
Cyberat
0

Fschmidt, to be more clear, you build a program for a machine printing custom lottery picks on a screen. Any lottery, so the input is user input not preset numbers not yours not anyone else's. You must have an input and verification process of such.

exterminator
exterminator
1717597729

as far as i can tell, i don't think anyone completed their task successfully! [@fschmidt's](https://chat-to.dev/profile?u=fschmidt) solution was the right one


Cyberat
Cyberat
0

Fschmidt, explain where and how, I don't see it at all.


fschmidt
fschmidt
0

Cyberat, My code prevents duplicates.


Cyberat
Cyberat
0

FSchmidt you did not follow the challenge, you followed Java Juggler's choice of 49, 6, 10. Must have USER INPUT, not your choice. Must validate input.


Cyberat
Cyberat
0

I can say Luan language has very weird For/Next loops.


Cyberat
Cyberat
0

Fschmidt, well done and complete code, but no Duplicate Checks. Must have duplicate check per game and per set of games. Best random(timer) will create duplicate numbers & duplicate games also. Maybe there is a language problem here let's say I have 5 numbers: 2, 34, 12, 44, 2. This pick is not desired. Also a game set should not repeat, same way. Run your program & test against it, run 10 games, run 20 games.


JavaJuggler
JavaJuggler
0

I'm in the middle of two programs and couldn't pay much attention to the code ­čĄö


JavaJuggler
JavaJuggler
0

>Took me about 3 days, take your time. Do run it and test it. Rule of thumb, run with 6 numbers per game and 10-12 games to look for duplicates. Don't trust the randomizer, correct it. `@Cyberat` said here ­čĹć that it took 3 days to solve and I did a few minutes and got some errors


fschmidt
fschmidt
0

JavaJuggler, Arrive at what result? My program? I read the requirements, looked at your code for variable names, and wrote my code. It took about 15 minutes.


JavaJuggler
JavaJuggler
0

I'm slowly starting to like this language, Mr. fschmidt. And by the way, how did you arrive at this result?


fschmidt
fschmidt
0

In my programming language [Luan](http://www.luan.software/): local Luan = require "luan:Luan.luan" local error = Luan.error local range = Luan.range or error() local ipairs = Luan.ipairs or error() local stringify = Luan.stringify or error() local Math = require "luan:Math.luan" local random = Math.random or error() local Table = require "luan:Table.luan" local sort = Table.sort or error() local concat = Table.concat or error() local Io = require "luan:Io.luan" local print = Io.print or error() local function lottery_picker( max_number, numbers_per_game, games_per_run ) max_number >= 1 or error "max_number must be at least 1" numbers_per_game >= 4 or error "numbers_per_game must be at least 4" max_number >= numbers_per_game or error "max_number must be at least numbers_per_game" games_per_run >= 1 or error "games_per_run must be at least 1" local games = {} local picks = {} for _ in range(1,games_per_run) do local game, pick repeat game = {} local used = {} for _ in range(1,numbers_per_game) do local number repeat number = random(1,max_number) until used[number] == nil used[number] = true game[#game+1] = number end sort(game) pick = concat( game, ":" ) until picks[pick] == nil picks[pick] = true games[#games+1] = game end return games end local games = lottery_picker( 49, 6, 10 ) print("Lottery Games:") for _, game in ipairs(games) do print( concat( game, " " ) ) end


JavaJuggler
JavaJuggler
0

Ok. thanks for the tip. as soon as I've finished I'll post it here in the comments.(y)


Cyberat
Cyberat
0

Took me about 3 days, take your time. Do run it and test it. Rule of thumb, run with 6 numbers per game and 10-12 games to look for duplicates. Don't trust the randomizer, correct it.


JavaJuggler
JavaJuggler
0

I'm trying to make something better organized and compressible. I'll post the result soon.


Cyberat
Cyberat
0

Hint, requires at least 3 nested loops for duplicate checks.


Cyberat
Cyberat
0

Input still faulty, since I hate Java and not that familiar, let me write your input in C# best I remember: Input ("What is the maximum number to have in a game ? :", max_number); While max_number =< 1 Print ("Invalid Number, must be greater than 1, try again."); Do Would need a set for each input.


Cyberat
Cyberat
0

Now you removed the check for duplicate numbers and have no check for duplicate games. This is the entire brain & core of the exercise.


Cyberat
Cyberat
0

I specified user picks amount of games and all that input, not programmer. Let me be clearer, I walk up to a machine that runs your program, the machine will ask me three questions: What is the max. number in the game, how many numbers to get for a game, how many games to get for this session. Runs the process and returns to main menu on key press. RUN YOUR OWN PROGRAM, test it, not just "I wrote this, how is it now ?".


JavaJuggler
JavaJuggler
0

see now `Mr Cyberat` ```py import random def lottery_picker(max_number, numbers_per_game, games_per_run): """ Generates a batch of lottery games with unique numbers and a bonus number. Parameters: max_number (int): The maximum number that can be picked. numbers_per_game (int): The number of unique numbers per game. games_per_run (int): The number of games per run. Returns: list: A list of games, where each game is a list of unique numbers with a bonus number. """ # Check if inputs are valid if not all(isinstance(param, int) for param in [max_number, numbers_per_game, games_per_run]) or max_number < 1 or numbers_per_game < 4 or games_per_run < 1: return "Invalid input. Please ensure all inputs are positive integers." # Initialize an empty list to store the games games = [] # Generate the games for _ in range(games_per_run): game = set() while len(game) < numbers_per_game: number = random.randint(1, max_number) game.add(number) games.append(sorted(list(game))) return games # Example usage games = lottery_picker(max_number=49, numbers_per_game=6, games_per_run=10) print("Lottery Games:") print("Number 1 Number 2 Number 3 Number 4 Number 5 Bonus Number") for game in games: print("{:8}".format(" ".join(map(str, game[:-1]))) + " " + str(game[-1])) ```


Cyberat
Cyberat
0

Make it simpler, list the last number as "bonus number", just a header text print marking the column.


JavaJuggler
JavaJuggler
0

The truth is that what sometimes seems simple becomes more complex in implementation. But I'm paying more attention and I'll get better results.


Cyberat
Cyberat
0

First of all put in the proper code for inputs and verification, you got it, just not in there. Also you don't want to invalidate ALL inputs for 1 wrong input, very annoying. Deprecate verification after each input.


Cyberat
Cyberat
0

Yes, it was a trick, sounds simple right, lottery picker ? I did it in C# and I ran into trouble seeing the results. Then I added the bonus as extra, when I solved it. I used Arrays and nested loops - hint.


JavaJuggler
JavaJuggler
0

the challenge is really complex and requires a great deal of thought. but i believe i've got to the bottom of the solution. if there's anything missing, let's try and come up with another solution.


Cyberat
Cyberat
0

I also asked for verification that games do not repeat in a batch. Yes, randomizer can do that in a set of 10+ games.


Cyberat
Cyberat
0

Does it run and perform ? I want the printed results. Cheap & easy way out, no text input or verification. Deprecate "Number not in game". It's almost like pseudo code. Nope you don't have it, incomplete work.


JavaJuggler
JavaJuggler
0

for this challenge I basically arrived at this result ```py import random def lottery_picker(max_number, numbers_per_game, games_per_run, special_number): """ Generates a batch of lottery games with unique numbers and a special number. Parameters: max_number (int): The maximum number that can be picked. numbers_per_game (int): The number of unique numbers per game. games_per_run (int): The number of games per run. special_number (int): The special number that must be included in every game. Returns: list: A list of games, where each game is a list of unique numbers including the special number. """ # Check if inputs are valid if max_number < 1 or numbers_per_game < 4 or games_per_run < 1 or special_number < 1 or special_number > max_number: return "Invalid input. Please ensure all inputs are positive integers and the special number is within the range." # Initialize an empty list to store the games games = [] # Generate the games for _ in range(games_per_run): game = set() while len(game) < numbers_per_game: number = random.randint(1, max_number) if number != special_number and number not in game: game.add(number) game.add(special_number) games.append(list(game)) return games # Example usage games = lottery_picker(max_number=49, numbers_per_game=6, games_per_run=10, special_number=7) for game in games: print(game) ``` This code defines a function lottery_picker that takes four arguments: max_number, numbers_per_game, games_per_run, and special_number. It generates a batch of lottery games with unique numbers and a special number, and returns a list of games. The function checks if the inputs are valid, and if not, it returns an error message. The example usage at the end of the code generates 10 games with 6 unique numbers each, where the maximum number is 49 and the special number is 7. the challenge has been launched, whoever has a better answer than mine, let's have it