I have some cnf files, which are txt files that are in a specific format for conjunctive normal form formulas. I want to take this file, which looks something like this:
c The random seed used to shuffle this instance was seed=1755086696
p cnf 1200 4919
-35 491 -1180 0
479 1074 -949 0
609 1177 -67 0... (etc.)
and turn it into this:
formula=[[(35,0), (491,1),(1180,0)],[(479,1),(1074,1),(949,0)],[(609,1),(1177,1),(67,0)]... ]
Notice that the absolute value of the integer is used, but if it was negative, there is a 0 in the tuple, if it was positive, there is a 1 in the tuple.
Also notice that the 0 at the end of each line doesn't make a difference.
I need to do this as fast as possible because the formulas can get large. Linear time would be great.
Anyone know a good solution?