Skip to content

Instantly share code, notes, and snippets.

@cyphunk
Last active May 26, 2023 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyphunk/112d89f38b2bce2a4317117aafb26806 to your computer and use it in GitHub Desktop.
Save cyphunk/112d89f38b2bce2a4317117aafb26806 to your computer and use it in GitHub Desktop.
chatgpt basic math test
# Ask chatgtp following prompted questions in order
# and then compare with the results with code herein
# 1. Create a list of 50 random float point numbers
# between 50 and 100 with a maximum of 1 decimal place.
# 2. Sort the list
# 3. Calculate the gap between each number
# 4. Sort the results by gap, with largest gap first
#
# for questions email nathan at squimp.com
#
# Lets walk through the above prompts:
#
# 1. Create a list of 50 random float point numbers...
# Replace the following number list with the list given by
# ChatGTP in response to prompt 1 above:
l=[51.9, 52.8, 53.7, 54.4, 55.3, 56.7, 57.2, 58.4, 58.8, 59.6, 60.8, 61.2, 62.6, 63.7, 64.3, 65.8, 66.4, 66.9, 67.5, 68.9, 69.3, 70.6, 71.8, 72.2, 73.7, 74.8, 75.5, 76.1, 77.4, 78.3, 79.6, 80.1, 81.2, 82.9, 83.7, 84.3, 85.2, 86.9, 87.0, 87.5, 88.4, 89.3, 89.7, 91.5, 92.0, 92.5, 93.4, 94.6, 95.1, 96.7, 97.3, 98.9, 99.7]
# 2. Sort
l.sort()
# 3. Calculate the gap between each number
num=l[0]
ll=[]
for next in l:
ll.append([num,round(next-num,1),next])
print ([num,round(next-num,1),next])
num=next
# 4. Sort the results by gap, with largest gap first
ll.sort(key=lambda x: x[1],reverse=True)
for res in ll:
print (res)
# Our local results:
# [89.7, 1.8, 91.5]
# [81.2, 1.7, 82.9]
# [85.2, 1.7, 86.9]
# [95.1, 1.6, 96.7]
# [97.3, 1.6, 98.9]
# [64.3, 1.5, 65.8]
# [72.2, 1.5, 73.7]
# [55.3, 1.4, 56.7]
# ...
# Now compare results with what ChatGPT gave for prompt 4
# Snippet below of results ChatGTP gave me, with my own notes added in [[]]:
"""
Sure! Here's the list with the gaps between each number and the next number printed one result per line:
81.2 - Gap: 1.7 - Next number: 82.9
85.2 - Gap: 1.7 - Next number: 86.9
89.7 - Gap: 1.8 - Next number: 91.5 [[notice this is out of order]]
96.7 - Gap: 1.6 - Next number: 97.3 [[math fail, is gap 0.6]]
97.3 - Gap: 1.6 - Next number: 98.9
62.6 - Gap: 1.5 - Next number: 63.7 [[false math, gap 1.1]]
64.3 - Gap: 1.5 - Next number: 65.8
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment