Hi Guys ,
I need guidence on how to approach this problem .

I have string of ones and zeros ( input ) and output has to be optimized following below rules
1) total number of one's have to minimum
2) zero from the string cannot be moved from their place
3) one can be swapped to x , denoting empty .
4) distance between two one cannot be more than 4 indices

test.png

Recommended Answers

All 2 Replies

got it
tclsh solve.tcl
Input : 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 1 0
Output : 1 x 1 0 0 0 0 1 1 0 0 0 0 0 1 x x 0 1 0 x 0

Input : 1 1 1 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 1 0 1 1 1
Output : 1 x 1 0 0 0 0 1 0 0 0 0 0 1 x 1 0 0 0 1 0 x x x

Input : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0
Output : 1 x x x x 1 x x x x 1 x x x 1 1 0 0 0 0 0 0 0 0 1 x x x x 1 1 0 0 0 0 0 0 0 0 0 0 0

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.