This content originally appeared on DEV Community and was authored by rishisingh007
For years, people believed that writing a perfect prompt was the key to getting value out of AI tools like ChatGPT or Claude. But today’s reality is very different, with everyday advances in AI capabilities.
Modern AI models are much more capable, and we get to know this once we start using them. Even basic prompts often return production-quality results. Let us use two different approaches to reach to desired results. First we will start with a basic prompt and then refine it with next prompt, and record the result. In second approach we will provide full requirement details in the first prompt itself and take the results. Then compare the results of two approaches.
Let us start with our first approach.
First Approach
GPT Prompt: Write a function to check if a number is prime.
The result code in Python:
def is_prime(n: int) -> bool:
"""Check if a number is prime."""
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
# Check divisibility up to sqrt(n)
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
Look at the code is is already optimized code without ever mentioning in the prompt. Now let us ask GPT to give code for very large numbers in the next prompt to refine our result.
GPT Prompt: Make it efficient for very large numbers and suggest if I should use probabilistic methods.
The result code below:
import random
def is_probable_prime(n: int, k: int = 20) -> bool:
"""Miller-Rabin primality test with k iterations."""
if n < 2:
return False
# Small primes
for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]:
if n % p == 0:
return n == p
# Write n-1 as d*2^s
s, d = 0, n - 1
while d % 2 == 0:
s += 1
d //= 2
# Witness loop
for _ in range(k):
a = random.randrange(2, n - 1)
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for _ in range(s - 1):
x = pow(x, 2, n)
if x == n - 1:
break
else:
return False
return True
Second approach
Now let us combine above two prompts into one, thus making it a complex prompt first time.
GPT Prompt: Write a function to check if a number is prime. Make it efficient for very large numbers and suggest if I should use probabilistic methods.
The result code below:
import random
def is_prime_miller_rabin(n: int, k: int = 10) -> bool:
"""Miller-Rabin primality test.
k = number of rounds (higher = more accuracy)."""
if n < 2:
return False
if n in (2, 3):
return True
if n % 2 == 0:
return False
# Write n-1 as 2^r * d
r, d = 0, n - 1
while d % 2 == 0:
r += 1
d //= 2
# Witness loop
for _ in range(k):
a = random.randrange(2, n - 1)
x = pow(a, d, n) # a^d % n
if x == 1 or x == n - 1:
continue
for _ in range(r - 1):
x = pow(x, 2, n)
if x == n - 1:
break
else:
return False
return True
Observation: Look at the result that we got when started with basic prompt and refined the result to suit our expectations and when we sent a complex two sentence prompt, the final output is identical (except for function name).
Takeaway
Old belief: You must write perfect prompts, always with relevant context.
New reality: AI is smarter by default. Even basic prompts are solid, and you can add context iteratively to get desired results.
True superpower: Iterating like you would with a human team mate — refine, adjust, collaborate.
So do not stress too much over “prompt hacks.” Start simple, then iterate.
This content originally appeared on DEV Community and was authored by rishisingh007