stats.py
text/x-python
#!/usr/bin/env python import sys first_block = int(sys.argv[1]) last_block = int(sys.argv[2]) nblocks = 0 nruns = 0 nforward = 0 nbackward = 0 prev_block = 0 for line in sys.stdin: b = int(line) if b < first_block or b > last_block: continue nblocks += 1 if b != prev_block: nruns += 1 if b > prev_block and prev_block != 0: nforward += 1 if b < prev_block and prev_block != 0: nbackward += 1 prev_block = b print (nblocks, nruns, nforward, nbackward)