entry #1
written by JJRubes
submitted at
1 like
guesses
- JJRubes (by LyricLy)
- LyricLy (by moshikoi)
- LyricLy (by nurdle)
- moshikoi (by seshoumara)
comments 0
3sp.py ASCII text
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # python3 3sp.py -h | | | esolangin' on the lone desert highway import argparse ; # def parse_contents(contents ) : instructions = [ ] for line in program : # for instruction in line.split(): try : # instructionValue = int(instruction) instructions . append(instructionValue) except ValueError : # return instructions return instructions ; # def pad(row, size ) : if size > len(row ) : row += [0] * (size - len(row)) def update ( instruction, row): pad (row , instruction + 1) pad (row , row[instruction] + 1) pad (row , row[row[instruction]] + 1) row [row [ row[instruction ]]] += 1 def do_io(row ) : pad (row , 4) if row[1] % 2 == 1 : print (chr(row[3 ] %256), end="") def run(instructions , max_cycles, io): row = [ ] cycles = 0 ; while True : # if max_cycles != None and cycles > max_cycles: if io : # print ("" ) ; return row ; # index = cycles % len(instructions) update (instructions [ index], row) if index == len ( instructions) - 1 and io: do_io (row ) ; cycles += 1 ; return row ; # def repl( ) : print ( "3 Star Programmer REPL") instructions = [ ] row = [ ] while True : # try : # instructionValue = int(input(">>> ")) instructions . append(instructionValue) update ( instructionValue, row) print (row ) ; except ValueError : # return ; # if __name__ == '__main__' : # parser = argparse . ArgumentParser(description="Three Star Programmer interpreter. https://esolangs.org/wiki/Three_Star_Programmer") parser .add_argument ( "filename", help="Leave empty to use as a REPL. Options have no effect on the REPL.", nargs="?") parser .add_argument ( "-s", "--max_steps", type=int, help="Limits the number of steps the program takes.") parser .add_argument ( "-o", "--output", action="store_true", help="Outputs according to the output extension.") parser .add_argument ( "-p", "--print_tape", action="store_true", help="Prints the memory each step.") args = parser . parse_args() if args . filename == None: repl ( ) ; else : # with open(args . filename, "r") as f: program = f . readlines() if args.print_tape : # print (run ( parse_contents(program), args.max_steps, args.output)) else : # run (parse_contents ( program), args.max_steps, args.output) |
post a comment