diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-23 12:23:42 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-23 12:23:42 +0000 |
| commit | c4bb1dec1a1fb2c69ce19643f4442e9139613d3b (patch) | |
| tree | 8ec9cf254d39e37f5ce9211f9d68add48beba7f1 /challenge-001 | |
| parent | 2fdb31d3b27d4d1809484091e5b36cfefdff5c6c (diff) | |
| download | perlweeklychallenge-club-c4bb1dec1a1fb2c69ce19643f4442e9139613d3b.tar.gz perlweeklychallenge-club-c4bb1dec1a1fb2c69ce19643f4442e9139613d3b.tar.bz2 perlweeklychallenge-club-c4bb1dec1a1fb2c69ce19643f4442e9139613d3b.zip | |
Remove # comments, consider any char not recognized as a comment
Diffstat (limited to 'challenge-001')
| -rw-r--r-- | challenge-001/paulo-custodio/brainfuck.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/challenge-001/paulo-custodio/brainfuck.py b/challenge-001/paulo-custodio/brainfuck.py index e7234692cd..7ef3443113 100644 --- a/challenge-001/paulo-custodio/brainfuck.py +++ b/challenge-001/paulo-custodio/brainfuck.py @@ -1,14 +1,13 @@ #!/usr/bin/python3 # Run brainfuck from input -# Addition to the language: # - comment, ignore rest of the line # Option: -t - trace execution import sys import getopt import re -TAPE_SIZE = 3000 +TAPE_SIZE = 30000 do_trace = False class TuringMachine: @@ -19,8 +18,7 @@ class TuringMachine: self.ip = 0 def parse(self, prog): - prog = re.sub(r"#[^\n]*", "", prog) # remove comments - prog = re.sub(r"\s*", "", prog) # remove blanks + prog = re.sub(r"[^-+<>,.\[\]]+", "", prog) # remove non-brainfuck operations return prog def done(self): @@ -61,8 +59,7 @@ class TuringMachine: if self.tape[self.ptr]!=0: self.find_open() else: - print("operation not supported:", op) - sys.exit(1) + pass # ignore other characters if do_trace: print(op, end=" ") |
