AI War — Bard vs ChatGPT | Part 2

I posed a coding question to both ChatGPT and Bard and observed how they fared in comparison.

DevOps with AI
4 min readJul 5, 2023

In the previous article, I discussed the notable distinctions and similarities between ChatGPT and Bard, the two most popular Generative AI Models. We explored their respective competitive advantages in different areas. ChatGPT boasts a larger dataset size, housing an impressive 175 billion parameters. However, it’s worth noting that Bard, with its 137 billion parameters, is expected to catch up eventually due to its access to Google’s vast datasets. (Think of parameters as the number of neural connections, resembling those found in the human brain.)

In this article and the upcoming ones, my intention is to compare these models in practical scenarios. I will be posing various questions and prompts to each model and collecting their responses. Since this article focuses on software and DevOps, the prompts will be tailored to subjects related to these topics. It’s important to note that the responses won’t be fine-tuned, meaning I won’t request multiple iterations. Instead, I’ll publish the initial response I receive to test the accuracy and relevance to the given topic.

I decided to throw at both models a typical coding question that often pops up in technical interviews.

The House Robber Problem:

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.

Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.

Example 1:

Input: nums = [2,3,2]
Output: 3
Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.

Example 2:

Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
Total amount you can rob = 1 + 3 = 4.

Example 3:

Input: nums = [1,2,3]
Output: 3

Constraints:

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000
  • Use JavaScript

ChatGPT’s Response:

Remarks:

  • Comments in code makes it easier to understand what’s going on in each line.
  • It checks if there is only one house in the first line and returns the result immediately without needing to run the full function.
  • Gives an example usage on the bottom.
  • Variable names are descriptive

Bard’s Response

Remarks:

  • Comments are there but are not as concise compared to ChatGPT’s response.
  • Variable names are not as descriptive.
  • Shows how to use the code and run it using console or node.
  • Code is more compact.

Both implementations are valid and provide the correct solution to the house robber problem.

The first implementation explicitly defines a helper function (robRange) to handle the dynamic programming updates within a given range of houses. This approach can be useful if you want to separate the logic and make the code more modular. It provides a clearer understanding of the two cases being considered: robbing the current house or not robbing it.

On the other hand, the second implementation directly updates the dynamic programming array within a for loop. It eliminates the need for a separate helper function and may be considered more concise.

In terms of performance, both implementations have a similar time complexity of O(n), where n is the number of houses. They iterate over the houses once and update the dynamic programming array accordingly.

In my assessment, ChatGPT emerges as the preferred choice, although both models showcased commendable performance in generating code. The maturity of ChatGPT gives it an advantageous edge, and it will be intriguing to witness the impact of incorporating Github Copilot data, which is expected to further bolster its capabilities. Nonetheless, credit is due to Bard for its ability to generate code accompanied by explanations, especially considering its relatively recent entry into the field.

If you enjoyed reading my article, I’d greatly appreciate it if you could share and subscribe. Your support encourages me to create more content centered around Code, AI, and all things Cloud-related. Together, let’s continue exploring the exciting possibilities these technologies offer!

References:

--

--

DevOps with AI

Empowering Devs with AI: Bringing the next generation of developer experience platforms and solutions