This solves Advent of Code puzzles by having GPT-3 write code in response to the puzzle's input.
I placed 1st on Day 4 Part 1 (2022) with this code, and 2nd on Day 3 Part 1 (2022) with a previous version.
The code is written in Python, and uses the OpenAI API to call GPT-3.
It also uses the aoc-cli library to download the puzzle input and submit the answer.
python3 openai.py --day=2All flags:
--day(required) - The day of the puzzle.--year- The year of the puzzle. Defaults to the current year.--part- The part of the puzzle.--n-workers- The number of workers to use. Defaults to 1--runs- The number of runs to make. Defaults to 200--stop-when-submitted- Stop when the answer is submitted. Defaults to False
Example:
python3 openai.py --day=2 --year=2019 --runs=10All instructions can be found here: https://github.com/scarvalhojr/aoc-cli
Install the aoc-cli library:
cargo install aoc-clior
brew install scarvalhojr/tap/aoc-clior
winget install aoc-cliDifferent Advent of Code users get different puzzle input. To download your input and submit your answer, you need an adventofcode.com session cookie. To obtain your session cookie, login to the Advent of Code website and inspect the session value of the cookie that gets stored in your browser. Put the session number (a long hex string) in a file called .adventofcode.session in your home directory. This file should only contain your session number, in a single line.
All instructions can be found here: https://github.com/scarvalhojr/aoc-cli#session-cookie
Install the openai library:
pip install openaiAdd your OpenAI API key to the
OPENAI_API_KEYenvironment variable.
You can get your API key here: https://beta.openai.com/account/api-keys