JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 04:53 22 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Windmills : ChatGPT Lotto Program

Author Message
Regular Member

Joined: 12/10/2014
Location: New Zealand
Posts: 82
Posted: 11:34pm 25 Feb 2023
Copy link to clipboard 
Print this post

Someone had to do it.

Typed the following question into ChatGPT:

"write a program in mmbasic to create an array with integers 1 to 40 and then to select six of them, removing them from the array when they are selected, then print the six numbers"
REM Create an array with integers 1 to 40
DIM nums(40)
FOR i = 1 TO 40
 nums(i) = i

REM Select six numbers
DIM selected(6)
FOR i = 1 TO 6
 REM Pick a random index from the remaining numbers
 index = INT(RND * (40 - i + 1)) + i - 1

 REM Add the selected number to the output array
 selected(i) = nums(index)

 REM Remove the selected number from the input array
 FOR j = index TO 39
   nums(j) = nums(j + 1)

REM Print the selected numbers
PRINT "Selected numbers:"
FOR i = 1 TO 6
 PRINT selected(i)

This program first creates an array called nums with integers 1 to 40 using a FOR loop. Then, it selects six random numbers from the nums array by repeatedly picking a random index from the remaining numbers, adding the selected number to the selected array, and removing the selected number from the nums array using another FOR loop.

Finally, the program prints the selected numbers using another FOR loop and a PRINT statement.

These are the results I got.

Upload completed 1

Saved 586 bytes
Time taken: 1765mS
Selected numbers:

Feel free to use these numbers next week.
Print this page

To reply to this topic, you need to log in.

© JAQ Software 2024