3 ms·
I tried this prompt: >The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with
by Imnimo 4y ago
I tried this prompt:
>The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line. Find the total number of calories being carried by the elf who is carrying the most calories. Write Python code to solve this problem.
This is the key paragraph from the problem description, plus the sentence asking for the solution.
The code it produced was correct, although it doesn't include reading the input from a file: https://pastebin.com/M00t217u https://pastebin.com/M00t217u
I then asked, "Can you modify the code to read the input from a file?"
Again, the code it produced was correct and it now reads from a file: https://pastebin.com/N6mcZu55 https://pastebin.com/N6mcZu55
I then tried, "Can you make the code more memory efficient?".
It said, "Yes, we can make the code more memory efficient by avoiding the use of the intermediate list of lists that contains the number of calories for each Elf. Instead, we can directly compute the total number of calories for each Elf as we parse the input, and find the maximum value at the end. Here is an example:"
https://pastebin.com/NCtx4KHc https://pastebin.com/NCtx4KHc