Question: //translate this code from python to ruby //needs to compile or I will downvote the answer (I asked once before and got a bogus answer
//translate this code from python to ruby
//needs to compile or I will downvote the answer (I asked once before and got a bogus answer - please answer if you can translate and make sure the p]program compiles)
#the 8x8 board board = [[0]*8 for _ in range(0,8)]
def queenSafe(column, row): for i in range(column, -1, -1): if board[row][i]: return False
for j, i, in zip(range(row - 1, -1, -1), range(column - 1, -1, -1)): if board[j][i]: return False
for j, i in zip(range(row + 1, 8), range(column - 1, -1, -1)): if board[j][i]: return False
return True
def solution(column): if column >= 8: for j in board: print(j) return True
for j in range(8): if(queenSafe(column, j)): board[j][column] = 1
if solution(column + 1): return True else: board[j][column] = 0 return False
solution(0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
