> Maybe my data structure has a hash table of items, as well as a direct link to the largest item. When I say: "write the function to insert a new item in the list, and remember to update the largest item if it is larger than the current one", would Copilot do the right thing? Each step is easy in itself (adding an element to a hash, comparing an item to another one).
In general it won't solve all your problems, but it's helpful for automating simple things like this (but you still need to test edge cases). With this prompt in Python (which I'm more familiar with):
from dataclasses import dataclass
from typing import TypeVar
T = TypeVar('T')
@dataclass
class MaxDict:
items: dict[T, float]
max_value_item: T
def add_item(
It completed: def add_item(self, item: T, value: float):
if value > self.items[self.max_value_item]:
self.max_value_item = item
self.items[item] = value
This was my second attempt; first I called it `max_item` and the completion did something about comparing the key.I (surprisingly) could not get it to generate a Fibonacci function that skips 5.
Re:Coping with Copilot
by thewebcount on Saturday August 20, 2022 @03:10PM
(#32534431)
As a human, I’m having trouble understanding the problem description. What does it mean to “skip 5”? I’ve always understood the definition of a Fibonacci sequence to be, starting with 2 numbers (usually 1 and 1) the next number in the sequence is the sum of the previous 2.
So starting with 1 and 1, we get 2. 2 and 1 is three. 3 and 2 is five. What do we do from here? Do I not add 5 and 3? If not, then what do I add? 3 and 2 again? Do I repeat 3 and get 6? What does it mean to “skip 5”?
You compute the Fibonacci sequence first. Then you use that as the input for another function that produces the modified sequence by dropping 5.
I understood it to mean don’t print “5” but keep computing as if 5 were in it.
With the prompt
// Print the fibonnaci sequence, except the number 5.
int main() {
I got the result: int a = 0;
int b = 1;
int c = 0;
while (c < 100) {
c = a + b;
a = b;
b = c;
if (c != 5) {
cout << c << endl;
}
}
return 0;
What I don't know (I can't try the 'free' Copilot without providing a credit card), is how well it understands unusual constraints and separate pieces of C++ classes that make the real programs we write.
For instance, a simple test would be: "write a fibonacci function but skip the number 5". Does it do the right thing?
Another challenge would be a C++ class with several fields. That's what our real programs look like: composite data objects, mixing several different algorithms together to implement complex behavior.
Maybe my data structure has a hash table of items, as well as a direct link to the largest item. When I say: "write the function to insert a new item in the list, and remember to update the largest item if it is larger than the current one", would Copilot do the right thing? Each step is easy in itself (adding an element to a hash, comparing an item to another one).