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

Two questions.

  1. How do you solve this now? The answer leads to you coding that process.
  2. Why did your question vanish at https://stackoverflow.com/questions/57684251/optimizing-string-with-least-number-of-ones+&cd=1&hl=en&ct=clnk&gl=us I wonder if you were asked to restate or expand.
Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.