I asked ChatGPT to write a Ruby (the programming language doesn't really matter) function to add up all the integers from 1 to N. I wanted to see how it wrote it.
It actually used a loop to iterate through all the integers to get the sum. I'm sure many human programmers would do it that way, but the efficient way is to realize that you don't need a loop because, in math, the sum of 1 to N integers is N * (N+1) / 2.
So, for example, the sum of 1 through 10 is 10 * 11 / 2 = 55.
I was hoping that ChatGPT would know all the math tricks and use them.