I take it you mean (1/2)x + (1/4)x + (1/8)x + (1/16)x + (1/32)x = 1/2. The solution is to parse it into some sort of array or something that holds all the info, and then rearrange the equation I know this doesn't really help, but there's more

. Apparently Perl is brilliant for this sort of thing - look it up.