max-sixty / aoc-gpt

Solve Advent of Code puzzles with GPT-3
440 stars 25 forks source link

Advent of Code, by GPT-3

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.

Table of Contents

How it works

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.

How to use

python3 openai.py --day=2

All flags:

Example:

python3 openai.py --day=2 --year=2019 --runs=10

Installation

Install aoc-cli

All instructions can be found in the aoc-cli repo

Install the aoc-cli library:

cargo install aoc-cli
# or
brew install scarvalhojr/tap/aoc-cli
# or, for Windows
winget install aoc-cli

And add the AOC session cookie.

Install OpenAI API

Install the openai library:

pip install openai

Add an OpenAI API key to the OPENAI_API_KEY environment variable.