0

How can I write algorithm for tiling a floor

Hello guys idk how to start this code so can u help me pls Alco i can use numpy but how ıdk. I am learning python and ı stuck at this question. def place_tiles( room_length, room_width, tile_dim ): """ Place alternating colored tiles in the specified room and return the layout of the tiling. The length and width of the room are provided by the first two parameters, and tile_dim provides the dimension of each tile, which we will assume to be a square. """ # We can replace each row of tiles as a list. Therefore, the entire placement # can be represented as a list of lists. placement = []

11th Nov 2019, 6:10 AM
can ilgu
can ilgu - avatar
3 Answers
+ 1
i'm not sure if i understood it right but this is how you "could" approach it. First you can take the room length, width and tile length (assuming it's a square) as variables and write a function that takes these 3 variables as arguments and calculates how many tiles (one number for the length and another for the width, if it's not a square room) fill the room. So you'll have to new variables: number of tiles in both directions. As for the tiles of alternating colors: i would think of it as a checkerboard pattern. Formin a 2 dimensional array with the numbers of the tiles in both directions, array[a,b], you can specify which color a given tile has by taking the sum of z=a+b in mod(2). The first tile array[0,0] is z=0+0=0 mod2. Let's say the color of the tike is black if z=0 and white if z=1. So the second tile is array[0,1] and z=0+1=1 mod2. The tile is white. Same in the other direction. Array[1,0] is z=1+0=1 mod2 again white. That is the idea. And you have to implement it. Good luck!
11th Nov 2019, 8:09 AM
storm
storm - avatar
+ 1
by returning the layout of the tiling, what are you trying to say??
11th Nov 2019, 1:28 PM
Choe
Choe - avatar
0
Place  a black tile in the northwest corner. While the floor is not yet filled, repeat the following steps: Repeat this step width / 4 – 1 times: Place a tile east of the previously placed tile. If the previously placed tile was white, pick a black one;otherwise, a white one. Locate the tile at the beginning of the row that you just placed. If there is space to the south, place a tile ofthe opposite color below it. There is is a plan for it but how can I write this in python?
11th Nov 2019, 1:43 PM
can ilgu
can ilgu - avatar