Calculate line lengths
Working version of the miner script