Mar
2024
Is it worth driving to Costco for Gas? I asked Gemini – Part 2
To follow up, I probed Gemini further. I will spare you the questions I asked, but show you the result. I asked Gemini to plot the total cost of 8 gallons of gas at the local station, at Costco assuming it is 20 cents a gallon cheaper, and the total cost at Costco including the driving cost and the net difference for price – all ranging from $2.75 per gallon to $3.50. I wanted these plotted in a graph and presented as a table.
The blue line is my local gas station cost, Yellow is the cost at Costco not including the cost of driving to Costco and back and the green is inclusive of 1 gallon of gas to drive back and forth to Costco. The line at the bottom is the savings if I purchased the gas locally (though the per gallon cost at Costco is cheaper). And it grows with the price of gas. Pretty cool, isn’t it? And here. is the table:
Gas Price ($/gallon) | Total Cost at A | Total Cost at B | Total Cost at B (including driving) | Price Difference |
---|---|---|---|---|
2.75 | 22.0 | 20.4 | 22.95 | 0.95 |
2.85 | 22.8 | 21.2 | 23.85 | 1.05 |
2.95 | 23.6 | 22.0 | 24.75 | 1.15 |
3.05 | 24.4 | 22.8 | 25.65 | 1.25 |
3.15 | 25.2 | 23.6 | 26.55 | 1.35 |
3.25 | 26.0 | 24.4 | 27.45 | 1.45 |
3.35 | 26.8 | 25.2 | 28.35 | 1.55 |
3.45 | 27.6 | 26.0 | 29.25 | 1.65 |
Want to explain this a bit. Gemini assumes that the price in first column is the price at the gas station A (local). If it is $2.75, 8*$2.75 = $22, the cost at A. Since it is 20 cents a gallon cheaper in Costco, it is 8*$2.55 which is $20.40. And since I asked Gemini to assume that the driving cost of 1 gallon should be at the price at Costco, the cost including driving is $20.40+$2.55 = $22.95 and the savings if I buy locally is 95 cents. And so on and so forth.
Then I asked Gemini to show the python code it used to generate the graph and the table and hereĀ it is:
import pandas as pd
# Define gas prices at station A
gas_prices = [round(price / 100, 2) for price in range(275, 351, 10)] # Prices from $2.75 to $3.50 in 10 cent increments# Calculate total cost at station A
total_cost_a = [price * 8 for price in gas_prices] # Total cost for 8 gallons# Calculate gas prices at station B (20 cents cheaper than A)
gas_prices_b = [price – 0.2 for price in gas_prices]# Calculate total cost at station B
total_cost_b = [price * 8 for price in gas_prices_b] # Total cost for 8 gallons# Calculate cost of driving to and from B (1 gallon)
cost_driving = gas_prices_b# Calculate total cost including driving to B
total_cost_b_driving = [cost + price * 8 for cost, price in zip(cost_driving, gas_prices_b)]# Calculate price difference
price_difference = [cost_b_driving – cost_a for cost_a, cost_b_driving in zip(total_cost_a, total_cost_b_driving)]# Create a DataFrame
data = pd.DataFrame({
“Gas Price ($/gallon)”: gas_prices,
“Total Cost at A”: total_cost_a,
“Total Cost at B”: total_cost_b,
“Total Cost at B (including driving)”: total_cost_b_driving,
“Price Difference”: price_difference
})# Print the DataFrame
print(data.to_string(index=False))
Pretty good code and pretty good comments. As a software developer, I am very poor at adding comments like this, so I was very impressed.
I will leave it up to you to decide how far we have come with artificial intelligence and imagine the kinds of disruptions it will create. This is a trivial and simple example, but it highlights various capabilities nicely. I have engaged in range of subjects with both Gemini and ChatGPT 4 that are far more complicated than this and they continue to do a remarkable job – mostly accurate, sometimes I have to correct it. But my topics of interest are mostly in the sciences!