From 590ffe32c096f89067c3f45070c5a4b6c87ea7f8 Mon Sep 17 00:00:00 2001 From: Lukas Baumann Date: Wed, 17 Feb 2021 10:30:30 +0100 Subject: [PATCH] Create final.py --- 15/a/final.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 15/a/final.py diff --git a/15/a/final.py b/15/a/final.py new file mode 100644 index 0000000..8eb6c3e --- /dev/null +++ b/15/a/final.py @@ -0,0 +1,24 @@ +def getBASIC(): + res = [] + x="" + while not "END" in x.split(): + x = input() + res.append(x) + return res + +def findLine(prog, target): + for i in prog: + if i.split()[0] == target: + return prog.index(i) + +def execute(prog): + lines = set() + location = 0 + while True: + lines.add(location) + if location==len(prog)-1: return "success" + location = findLine(prog, prog[location].split()[-1]) + if location in lines: return "infinite loop" + +if __name__ == "__main__": + print(execute(getBASIC()))