Skip to content

Instantly share code, notes, and snippets.

@seeinglogic
seeinglogic / evaluate.py
Created November 5, 2024 16:45
LLM-Generated Arithmetic Expression Evaluator in Python
# Generated by ChatGPT's o1-preview model Sep 2024
# Prompt: """Write a Python function that takes a mathematical expression as a
# string evaluates it. The function should handle basic arithmetic operators and
# precedence but does not need to handle parentheses. The function must not use
# Python’s eval function."""
# WARNING: this code contains at least one bug, see associated post for info:
# https://seeinglogic.com/posts/checking-on-chatgpt/
from typing import Tuple, List
# x, y
Pos = Tuple[int, int]
dir_deltas = [
(-1, -1),
(-1, 0),
(-1, 1),
(0, -1),