Skip to content

Instantly share code, notes, and snippets.

@goldsmith
Created August 20, 2013 04:49
Show Gist options
  • Select an option

  • Save goldsmith/6277208 to your computer and use it in GitHub Desktop.

Select an option

Save goldsmith/6277208 to your computer and use it in GitHub Desktop.

Revisions

  1. goldsmith created this gist Aug 20, 2013.
    17 changes: 17 additions & 0 deletions labrinth.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    import os, subprocess

    ITERATIONS = 5

    def transform(line):
    return "ITERATIONS = " + str(int(line.split()[2]) - 1) + "\n" if line.startswith("ITERATIONS") else line

    with open(os.path.abspath(__file__), "r+") as f:
    new = ''.join(map(transform, f.readlines()))
    f.seek(0)
    f.write(new)

    if ITERATIONS > 1:
    print "iterations left: %s" % ITERATIONS
    print subprocess.Popen(["python", os.path.abspath(__file__)], stdout=subprocess.PIPE).communicate()[0],
    else:
    print "final iteration!"