Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:55 02 Aug 2025 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 : Microcontroller and PC projects : ChatGPT Lotto Number generator program

Author Message
Glen0
Regular Member

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

Someone had to do it..

Typed the following 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"

Got the following answer:

REM Create an array with integers 1 to 40
DIM nums(40)
FOR i = 1 TO 40
nums(i) = i
NEXT

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)
NEXT
NEXT

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

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.
==============================================================================

Ran the program and got this result:

AUTOSAVE

Upload completed 1

Saved 586 bytes
>
Time taken: 1765mS
RUN
Selected numbers:
27
20
25
24
17
14
>

Feel free to use these numbers anytime.

I accidentally posted this thread on the Windmill forum. Could someone kindly delete it from there.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 10:07am 26 Feb 2023
Copy link to clipboard 
Print this post

Tried to use chatGPT to write code for a mipi interface for arduino pro. It came with very simple code that used 2 libraries....that i could not find on the internet. And when asked chatGTP, it suggested different libraries that where not related to video or mipi.
Duh....

As long as you don't need it it is entertaining to see what AI can come up with. But don't expect anything usefull.

You are better off asking the best numbers to win the lotto. Or roulette, or whatever is based on little chance of profit.

Volhout
Edited 2023-02-26 20:09 by Volhout
PicomiteVGA PETSCII ROBOTS
 
grroel.tech
Newbie

Joined: 09/12/2021
Location: Spain
Posts: 18
Posted: 11:56am 26 Feb 2023
Copy link to clipboard 
Print this post

Hello,

If these numbers are winners in the lotto?
Just in case, I've already cast a spanish "Loteria Primitiva" with the numbers.

Good luck!!!
 
LucV

Regular Member

Joined: 19/02/2023
Location: Netherlands
Posts: 62
Posted: 12:37pm 26 Feb 2023
Copy link to clipboard 
Print this post

I never tried it with Basic but I did ask ChatGPT to write a program in MicroPython for the Raspberry Pico that produced tones. It did really well. A complete program with the libraries I needed and the pins defined.

It even mentioned I would probably need a low-pass filter. So I asked how to build a low pass filter for the Pico and there it was complete with a formula to calculate resistor and capacitor values.

Next step I asked it if it could rewrite the program to produce a toone scale. Yes it did and it worked. And then to rewrite the program to play Old MacDonalds and presto.

All the programs it produced worked direct.

I also tested it with Javascript and was amazed at how well that worked. I am using ChatGPT now to help me write my book on Javascript.
I asked ChatGPT to explain to me like I was 5 years old how the map function in Javascript worked: right on the nose.

And trivial:
I asked it to write a short fantasy story about a young prince that had to go treasure hunting. It came up with the knight talking to a sorcerer. When I asked it to give more details about the sorcerer it came up with a life story.

I think it is amazing.

Luc
Luc's tech Blog
 
pwillard
Guru

Joined: 07/06/2022
Location: United States
Posts: 313
Posted: 01:15pm 26 Feb 2023
Copy link to clipboard 
Print this post

My experience with Chatgpt is pretty much 50/50 hit and miss.  For example, I asked for help with an Arduino program and it said I should use two libraries that absolutely did not exist anywhere except in CHATGPT's imagination.  I called the chatbot out on making stuff up and that these libraries probably didn't exist and it responded "You are right,  you should probably write these libraries yourself."

For Python code though, it gets it right nearly every time.
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 420
Posted: 10:24pm 26 Feb 2023
Copy link to clipboard 
Print this post

My (education based) experience has been pretty awesome - like living in an episode of Black Mirror:

(We have a new curriculum in Wales and schools need to produce "progression maps" to demonstrate that they have designed an appropriate curriculum)

Me:
Help me to design a progression map for science from ages 4 to 16 detailing the knowledge that we would expect learners of ages 4, 7, 11,13 and 16 to know about biology.

Give detailed examples of the specific knowledge at each age.

When you write this, call age 4, Progression Step 1, age 7, Progression Step 2, age 11, Progression Step 3, age 13, Progression Step 4, age 16, Progression Step 5.

Then remove all references to the age of learners, just leave Progression Steps.


Produces (for Progression Step 3)
Progression Step 3
At this stage, learners are expected to deepen their understanding of biology and explore more advanced concepts such as genetics and ecosystems. They are also expected to understand the impact of human activity on the environment. Some examples of specific knowledge at this progression step include:

* Understanding the basic principles of genetics, such as dominant and recessive traits, and the role of DNA in inheritance.
* Identifying and describing different ecosystems and the organisms that inhabit them, and understanding the interactions between living and non-living components of an ecosystem.
* Recognizing the importance of biodiversity and the impact of human activity on the environment, such as deforestation, pollution, and the conservation of endangered species.
* Understanding the basic principles of adaptation and evolution, and how these processes contribute to the diversity of life on Earth.
* Identifying and describing the basic functions of major organs and organ systems, including the heart, lungs, and brain.
* Understanding the basic principles of nutrition and digestion, including the roles of enzymes and the digestive system in breaking down food.
* Identifying and describing the basic functions of the immune system, including the body's response to pathogens and the role of vaccines in preventing disease.
* Understanding the basic principles of energy flow and nutrient cycling in ecosystems, including the roles of producers, consumers, and decomposers.
* Identifying and describing the basic functions of the endocrine system, including the role of hormones in regulating body processes.
* Understanding the basic principles of biotechnology, including genetic engineering and cloning.


Which is fairly spot on for age 11-12 ish - corresponding to Year7/8 ish in secondary school.

I then asked it to produce a Bullsh*tBingo card for education (granted the formatting is off):

| "Student-centered" | "Differentiated Instruction" | "Active learning" | "Engagement" | "21st Century Skills" |
| "Project-based learning" | "Flipped classroom" | "Personalized learning" | "Assessment for Learning" | "Collaboration" |
| "Inquiry-based learning" | "Authentic Assessment" | "Critical thinking" | "Blended learning" | "Technology Integration" |
| "Metacognition" | "Scaffolding" | "Student voice and choice" | "Culturally responsive teaching" | "Formative assessment" |
| "Gamification" | "Social and emotional learning" | "Universal Design for Learning" | "Higher order thinking" | "Teacher efficacy" |



Then finally I asked it to create some code:

Write some code in Python to search through the first 1000000 numbers and display those that meet all the following criteria:

1. Is a palindrome
2. Is a Harshad number
3. Is a cyclops number

When you write the code, use as many techniques as you can to make the code as quick as possible.  Please explain how the code works


Produces:

def is_palindrome(N_STR):
   return N_STR == N_STR[::-1]

def is_cyclops(N_STR):
   if len(N_STR) % 2 == 0:
       return False
   middle = len(N_STR) // 2
   return N_STR[middle] == '0'

def is_harshad(n):
   digit_sum = 0
   nsum = n
   while nsum > 0:
       digit_sum += nsum % 10
       nsum //= 10
   return n % digit_sum == 0

for n in range(1, 1000000):
   if n % 10 == 0:
       continue  # no need to check multiples of 10
   N_STR = str(n)
   if is_palindrome(N_STR) and is_cyclops(N_STR) and is_harshad(n):
       print(n)


With the following explanation:
This code searches through the integers from 1 to 999999 and checks if they are palindrome, cyclops, and Harshad numbers. Here is how each function works:

is_palindrome(N_STR): This function checks whether a given string N_STR is a palindrome. It returns True if the string is the same forwards and backwards (i.e., a palindrome), and False otherwise. This is achieved by checking if N_STR is equal to its reverse, which is done by slicing the string with [::-1].

is_cyclops(N_STR): This function checks if a given string N_STR is a cyclops number. A cyclops number is a positive odd number that has exactly one zero in the middle. The function first checks if N_STR has an odd number of digits, and if it does not, returns False. If N_STR has an odd number of digits, it finds the middle index and checks if the character at that index is '0'.

is_harshad(n): This function checks whether a given integer n is a Harshad number. A Harshad number is a positive integer that is divisible by the sum of its digits. The function calculates the sum of the digits of n using a loop and stores it in digit_sum. It then returns True if n is divisible by digit_sum, and False otherwise.

The code then iterates through the integers from 1 to 999999, skipping multiples of 10 as they are not palindromic. For each integer, it converts it to a string N_STR and checks if it is a palindrome, a cyclops number, and a Harshad number using the three functions. If all three checks pass, it prints the integer.


Granted a contrived use case, but essentially the homework I set my group today.
Edited 2023-02-27 08:26 by Nimue
Entropy is not what it used to be
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 420
Posted: 10:29pm 26 Feb 2023
Copy link to clipboard 
Print this post

What "interesting" is that the code produced for the Harshad check is "better" (ie quicker) than my method.

This method:
def is_harshad(n):
  digit_sum = 0
  nsum = n
  while nsum > 0:
      digit_sum += nsum % 10
      nsum //= 10
  return n % digit_sum == 0


Uses integer math to form the digit_sum.   My method usually iterates over the number as a string and converts each digit to an int.  All that string to int stuff is "slower" and I have learned a new way myself.

N
Entropy is not what it used to be
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 12:21pm 27 Feb 2023
Copy link to clipboard 
Print this post

That's promising.

How is it on the Riemann Hypothesis?

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 01:32pm 27 Feb 2023
Copy link to clipboard 
Print this post

Not impressed so far. I asked it to produce C code to do sinx/x interpolation as used in oscilloscopes. Currently on the 5th iteration and still doesn't work - no protection from divide by zero just one of the errors
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 724
Posted: 08:56pm 01 Mar 2023
Copy link to clipboard 
Print this post

Conclusion,
It can not mess with you
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 724
Posted: 08:56pm 01 Mar 2023
Copy link to clipboard 
Print this post

Conclusion,
It can not mess with you and also not with Geoff
Edited 2023-03-02 07:00 by atmega8
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025