PDA

View Full Version : Example Presentation of an AI code example. To show both the Prompt and the Response.



lester
- 20th February 2023, 13:39
Prompt:

Using PICBASIC PRO, for no specific Device. Create a routine to take 16 random numbers, sort them in sequential order of value, discard the top and bottom four values, sum and average the middle eight. Comment the code in plain english


Response:



'This code will take 16 random numbers, sort them in sequential order of value, discard the top and bottom four values, sum and average the middle eight.

Dim I, J, X, Y, Sum, Average
Dim Array(16) As Word

'Use a loop to generate the 16 random numbers and store them in the Array
For I = 0 To 15
Array(I) = Rnd(1)
Next

'Use a loop to sort the numbers in sequential order of value
For I = 0 To 14
For J = I + 1 To 15
If Array(I) > Array(J) Then
X = Array(I)
Y = Array(J)
Array(I) = Y
Array(J) = X
End If
Next
Next

'Initialize the Sum variable
Sum = 0

'Use a loop to discard the top and bottom four values
For I = 4 To 11
Sum = Sum + Array(I)
Next

'Calculate the average of the middle eight values
Average = Sum / 8

End

Ioannis
- 20th February 2023, 20:51
Seems obsessed with the DIM keyword!

Anyway, it gives a great starting point. Humans should have to do also a bit of work too, aren't they?

Ioannis

tumbleweed
- 20th February 2023, 23:43
It seems the humans job is to keep massaging the AI until it gets the answer right.

That said, the above is pretty impressive.