I began making a sudoku game in go, and I have made it so that it puts random numbers from 1 to 9 in each cell in a sudoku board. But in sudoku, you can't have a duplicate cell horizontally and vertically from the cell.
I have seen ways of removing duplicates from a regular array, but the sudoku board is a 2D array.
(P.S: please don't include type inferring in the answers, I find it hard to read)
Related
We have an array with values [2,1,5,3,7] and we have to find number of ways to form a spiral array by deleting one element at a time. Lets say when we remove 2 we can have [1,5,3,7] and when we remove 1 then we have [2,5,3,7]. There is no more possibility. so we should return 2. Do you have any idea how can i solve this problem in Java?
I'm trying to make a brick shooter game, where you have a board (2D array of int) and a set of bricks on each side. For example, I have bricks of 3 colors represented by numbers 1, 2, 3 and I put them in random locations on the board. When player shoots one brick from a side of the board it goes straight to the first brick it meets on the board or to the edge.
The problem is when 3 or more bricks of the same color are adjacent, they have to be deleted. I don't quite know how to implement that... Programming language you choose doesn't matter if it's possible to see the logic behind that code for a beginner like me.
...and also it is my first question on the site, so don't attack me if something's wrong.
I think what you are looking for, is an adjacency matrix, in which you will tell every block, which color has the adjacent block.
In that way will be easy for you to know if the blocks have the same color. If you don't know what an adjacency matrix is, I will put a link for you, in order to learn how they work.
https://www.sciencedirect.com/topics/computer-science/adjacency-matrix
This should help you, to overcome your problem.
One possible solution is to implement a flood fill algorithm. This will find all blocks attached to the hit block, and all the blocks attached to those, and all... etc.
Here, a cell is a discrete space in the array, e.g. position [n, m] in the array.
Insert into active, the seed cell (hit block)
Select any cell c from active
Insert c into closed, and remove from active
Insert into active the matching-value adjacent neighbours of c NOT in closed or active
If active has cells, move to step 2, else continue
All values in closed can be deleted
Say I have a 2D array and I want to take the first row, repeat it two times and stack it to the front of the 2D array. My way to do this would be as follows:
test = np.array([[1,2],
[3,4]])
np.hstack((np.repeat(np.atleast_2d(test[:,0]).T, 2, axis=1), test))
This looks rather complicated. Is there any simpler way to do it? I looked at np.tile, however this seems to keep the shape.
I am looking for ideas of how to write an algorithm that is going to populate 2d array with predefined set of blocks/arrays.
Let's say you have 2d array 5x5 (so 25 fields), and have 6 elements you want to randomly fit into it (accordingly 5, 5, 4, 4, 4, 3 piece straight blocks). What is important - I want to put those randomly either horizontally or vertically, but no cell can be left with nothing.
The end effect should look like this (given the blocks of X elements on the left side)
This is somewhat related to packaging algorithms, although here the idea is that I specify the container dimensions (2d array) let's say 8x4, and randomize X amount of stripes length 3-5 that will be fit into array. The sum of all lengths of stripes will be equal to array size (so no cell is left empty).
On top of that, I think, I could add a fail-safe feature, meaning that after putting most stripes into Array and last one cant fit, algorithm could find any empty cells and fill it with neighbouring element so that the stripes are longer, but not longer than 5 elements
The correct words are not coming to my mouth as yet so please tell what I should have asked to make the question clear.
I have a cell array (1x12) with each cell having the size (65536x1). I want to have a matrix which has the dimensions (65536x12). In short, I want to convert (1x12) cell, with each cell having (65536x1) values, to a matrix with (65536x12) values.
example
I want to do above programmatically using Matlab but couldn't find any solution. (probably because I am not searching using correct words).
Try cell2mat
output = cell2mat(inputImagesCell)
You also misunderstood what a "cell array" is, edited your question, maybe it is clearer now. A cell array is an array of cells. inputImagesCell is a cell array containing 12 cells, consisting of a 65536x1 numeric matrix each. And you want to concatenate all cells to one matrix.