[Gambas-user] I asked chat gpt to write a gambas script, here is what it did

Brian G brian at westwoodsvcs.com
Tue Feb 14 08:44:08 CET 2023


Ok I asked 
can you also account for the difference between successive primes as the count approaches infinity.. 
here is what it wrote 

Sure, to account for the difference between successive primes as the count approaches infinity, we can use the Prime Number Theorem, which states that the number of primes less than or equal to x is approximately x/ln(x) as x approaches infinity. Therefore, the expected difference between successive primes is approximately ln(x). 

Here's the updated code that takes into account the expected difference between successive primes as the count approaches infinity and prints it at the end: 
Public Sub Main() 

Dim limit As Integer = 300 
Dim isPrime As Boolean[] = New Boolean[limit + 1] 
Dim primes As New Integer[] 
For i As Integer = 2 To limit 
isPrime[i] = True 
Next 

For i As Integer = 2 To limit 
If isPrime[i] Then 
primes.Add(i) 
For j As Integer = i * i To limit Step i 
isPrime[j] = False 
Next 
Endif 
Next 
Print "Prime numbers between 2 and 300:" 
For Each prime As Integer In primes 
Print prime 
Next 
Dim count As Integer = primes.Count 
Dim lastPrime As Integer = primes[count - 1] 
Dim expectedDiff As Float = Log(lastPrime) - Log(Log(lastPrime)) 
Print "Total number of primes found: " & count 
Print "Expected difference between successive primes: " & expectedDiff 

End 

"Failure is the key to success; 
each mistake teaches us something" .. Morihei Ueshiba 
Brian G 

----- On Feb 13, 2023, at 11:35 PM, Bruce <adamnt42 at gmail.com> wrote: 

> On 14/2/23 5:54 pm, Brian G wrote:

>> Ok do we really have a future here!
> If you mean us wetware beings then maybe not in the universe of prime number
> coders, mneh! But otherwise, try asking it about the difference between
> successive primes as the count approaches infinity...

> (I think the answer is infinity, JL may disagree. But I'd like to see the code
> it could come up with. But then then again, it might be just return 'Print
> "Tricky"')

> b

> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230213/f772165d/attachment-0001.htm>


More information about the User mailing list