diff --git a/.gitignore b/.gitignore index 9b42106485049667ad1636a80422ad1c7f3cdf64..cdf0ac60f1c55708d3b46a9d7248c9510fbba5b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .direnv/ +.env diff --git a/challenge-i/base.py b/challenge-i/base.py index 267d2282acd2b4a896fc65ad9862a57f2737be9d..b180cac630a843cd4600fd01ac5f319e6cde6baa 100644 --- a/challenge-i/base.py +++ b/challenge-i/base.py @@ -10,7 +10,7 @@ if target.endswith("@soton.ac.uk"): with requests.get(f"https://www.ecs.soton.ac.uk/people/{target}") as request: if request.status_code != 200: print("Invalid email ID.") - exit() + exit(1) name = REGEX.search(request.text) if name: diff --git a/challenge-ii/gpt.py b/challenge-ii/gpt.py new file mode 100644 index 0000000000000000000000000000000000000000..a32b193e23ff0fc2e45a2e9310907d198b5d5954 --- /dev/null +++ b/challenge-ii/gpt.py @@ -0,0 +1,49 @@ +import sys +from pydantic import BaseModel +from openai import OpenAI + +client = OpenAI() + +class Variable(BaseModel): + name: str + value: int + +class ResponseFormat(BaseModel): + variables: list[Variable] + +with open(sys.argv[1], 'r') as file: + code = file.read() + +completion = client.beta.chat.completions.parse( + model="gpt-4o-mini", + messages=[ + { + "role": "system", + "content": '''You are an interpreter for the programming language barebones. Bare Bones is the simple language that Brookshear uses in his book, 'Computer Science: an Overview', to illustrate the power of Turing complete machines and investigate the halting problem. + +Bare Bones has three simple commands for manipulating a variable: + +clear name; +incr name; +decr name; +...which respectively sets variable name to zero, increments it by one and decrements it by one. + +The language also contains one control sequence, a simple loop: + +while name not 0 do; +... +... +end; +... where name is a variable. Note that variables need not be declared before they are used and must be non-negative integers. Statements are delimited by the ; character. + +Note that while loops must be terminated by an end statement, but that they can be nested.''', + }, + { + "role": "user", + "content": code, + }, + ], + response_format=ResponseFormat, +) + +print(completion.choices[0].message.parsed) diff --git a/challenge-ii/program.txt b/challenge-ii/program.txt new file mode 100644 index 0000000000000000000000000000000000000000..7b542fedafe35d813af263473db92de397d74c93 --- /dev/null +++ b/challenge-ii/program.txt @@ -0,0 +1,21 @@ +clear X; +incr X; +incr X; +clear Y; +incr Y; +incr Y; +incr Y; +clear Z; +while X not 0 do; + clear W; + while Y not 0 do; + incr Z; + incr W; + decr Y; + end; + while W not 0 do; + incr Y; + decr W; + end; + decr X; +end; \ No newline at end of file diff --git a/flake.nix b/flake.nix index 92c33458423508477cd3a46950eceaaf975cb0eb..345ef1d2d9b80e8326da02038f2ed081f5f4c920 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ with pkgs; { devShells.default = mkShellNoCC { buildInputs = [ - (python3.withPackages (pyPkgs: [ pyPkgs.requests ])) + (python3.withPackages (pyPkgs: [ pyPkgs.requests pyPkgs.pydantic pyPkgs.openai ])) ]; }; }