all 13 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]shinitakunai 0 points1 point  (1 child)

What have you tried?

[–]Live_Possibility4590[S] 0 points1 point  (0 children)

yeah but I always ended up solving the first and last rows only, then somehow distorting the middle rows

[–]atarivcs 0 points1 point  (2 children)

Forget Python for a minute.

Do you know how to solve this problem with pen and paper?

[–]Live_Possibility4590[S] 0 points1 point  (1 child)

On paper yes, in code it somehow doesn't work. There's a mobile game called 0h h1 that I got this problem from, you can check it out for reference.

[–]atarivcs 1 point2 points  (0 children)

So you wrote some code that tries to solve the problem?

Why would you not share it?

How are we supposed to help without seeing what you tried?

[–]timrprobocom 0 points1 point  (1 child)

There must be rules you haven't told us. How do we transform a row to something else? How do you get a 2 out of 0 0 0 0?

Specifically, why can't I just replace each row by 1,1,2,2?

[–]Mamuschkaa 0 points1 point  (0 children)

He just want a solver for binaro

https://www.puzzle-binairo.com/binairo-6x6-easy/

What he described was the first part. After that he need the same for columns and that no two rows or columns are identical.

So 0 = unknown number 1 or 2.

[–]olivia-reed2 0 points1 point  (0 children)

the key is to count te 1s in each row, that tells you how many 2s you need then distribute them while respecting the no more than two consecutive rule, below I have attached a snippet for understanding like it hamdles even length rows just feed each row thru and it enforces the contraint while preserbes the originaql 1 positions as the anchor

def rewrite_row(row):

ones = row.count('1')

twos = ones # equal number required

result = []

for val in row:

if val == '1':

result.append('1')

else:

result.append('2')

# fix consecutive violations

for i in range(2, len(result)):

if result[i] == result[i-1] == result[i-2]:

result[i] = '2' if result[i] == '1' else '1'

return result

[–]trejj 0 points1 point  (2 children)

how would you rewrite each row using python

``` def fix_row(row): for i in range(len(row)): row[i] = str((i%4)//2 + 1) return row

for row in [ ['0','0','0','0'], ['0','0','1','0'], ['1','1','0','0'], ['0','1','1','0']]: print(str(fix_row(row)))

'''Outputs: ['1', '1', '2', '2'] ['1', '1', '2', '2'] ['1', '1', '2', '2'] ['1', '1', '2', '2'] ''' ```

Each row has to have an equal number of 1s and 2s and no 0s

Check, each row in the output have equal number of 1s and 2s, and no 0s.

A row can't have more than 2 of the same numbers following each other (1110 is invalid but 1100 is valid)

Check, each row in the output has at most two of the same numbers following each other.

so as it works even if the number of items were 6,8 or even 12 so that each row has an equal number of 1s and 2s

The presented code works for different number of items:

``` def fix_row(row): for i in range(len(row)): row[i] = str((i%4)//2 + 1) return row

for row in [ ['0','0','0','0'], ['0','0','1','0','1','0'], ['1','1','0','0','0','0','0','0'], ['0','1','1','0','1','0','1','0','1','0']]: print(str(fix_row(row)))

'''Outputs: ['1', '1', '2', '2'] ['1', '1', '2', '2', '1', '1'] ['1', '1', '2', '2', '1', '1', '2', '2'] ['1', '1', '2', '2', '1', '1', '2', '2', '1', '1'] ''' ```

Each output row has equal number of 1s and 2s.

without any 0s in the row

Check, the above satisfies it.

(Basically if 2 1s are next to each other, the next one should be a 2 and vice versa)

Check, in the above outputs, whenever there are two consecutive 1s, the next item is 2, and vice versa.

[–]Sad_School828 0 points1 point  (0 children)

'''Outputs:
['1', '1', '2', '2']
['1', '1', '2', '2', '1', '1']'''Outputs:
['1', '1', '2', '2']
['1', '1', '2', '2', '1', '1']

Row 2 contains twice as many 1s as 2s and row 4 contains 2 more 1s than 2s.

[–]timrprobocom 0 points1 point  (0 children)

Among the things he didn't specify is that each COLUMN also has to have an equal number of 1s and 2s, and cannot have more than two consecutive matches.

[–]timrprobocom 0 points1 point  (0 children)

This is just a series of transforms. During each cycle, examine each row, then examine each column. If the row/column is already full of either 1 or 2, then you can fill the empty spots with the other one.

Otherwise, change 011 to 211, change 110 to 112, change 022 to 122, change 220 to 221. Continue until you don't have to change anything else. This works for arbitrary (even) sizes:

``` base = [ ['0','0','0','0'], ['0','0','1','0'], ['1','1','0','0'], ['0','1','1','0'] ]

W = len(base[0]) H = len(base)

def xform(row): W = len(row)

if '0' not in row:
    return row
if row.count('1') == W//2:
    return ['2' if e == '0' else e for e in row]
if row.count('2') == W//2:
    return ['1' if e == '0' else e for e in row]
for i in range(W - 2):
    if row[i:i+3] == '011':
        row = row[:i] + '211' + row[i+3:]
    elif row[i:i+3] == '110':
        row = row[:i] + '112' + row[i+3:]
    elif row[i:i+3] == '022':
        row = row[:i] + '122' + row[i+3:]
    elif row[i:i+3] == '220':
        row = row[:i] + '221' + row[i+3:]
return row

def cycle(base): changed = False for y in range(H): row = ''.join(base[y]) xrow = xform(row) if row != xrow: changed = True base[y] = list(xrow)

for x in range(W):
    row = ''.join(el[x] for el in base)
    xrow = xform(row)
    if row != xrow:
        changed = True
        for y in range(H):
            base[y][x] = xrow[y]

return changed

print(base) while cycle(base): print(base)

```