scilab - Completing a list of possible binary sequences give a binary sequence with gaps -


so, working on program in scilab solves binary puzzle. have come across problem however. can explain me logic behind solving binary sequence gaps (like [1 0 -1 0 -1 1 -1] -1 means empty cell. want possible solutions of given sequence. far have:

function p = mogelijkecombos(v) i=1:size(v,1)     if(v(i) == -1)         aantalleeg = aantalleeg +1     end end i=1:2^aantalleeg      //creating combos here end endfunction 

sorry words in dutch aantalleeg means amountempty mean amount of empty cells hope gave guys enough info. don't need code written, i'd ideas of how can make every possible rendition stuck atm.

btw school assignment, assignment way bigger , it's tiny part need ideas on

ty in advance

short answer

you create combos extending code , create possible binary words of length "amountempty" , replacing them bit-for-bit in empty cells of v.

step-by-step description

  • find empty cell positions
  • count number of positions you've found (which equals number of empty cells)
  • create possible binary numbers length of count
  • for each binary number generate, place bits in empty cells
  • print out / store possible sequence filled in bits

example

find empty cell positions

you example check left-to-right starting @ 1 , if cell empty add position position list.

v = [1 0 -1 0 -1 1 -1]            ^    ^    ^           |    |    |       1 2  3 4  5 6  7  // result positions = [3 5 7] 

count number of positions you've found

//result  amountempty = 3; 

create possible binary numbers length amountempty

you create possible numbers or words dec2bin function in scilab. number of possible words easy determine because know how separate values can represented word of amountempty bits long.

// create binary word of amountempty bits long binaryword = dec2bin( i, amountempty ); 

the binaryword generated string, have split it separate bits , convert numbers.

for each binaryword generate

now create possible solution starting original v , fill in every empty cell @ position position list bit binarywordperbit

possiblesequence = v;  j=1:amountempty     possiblesequence( positions(j) ) = binarywordperbit(j);               end 

i wish "veel succes met je opdracht"


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -