anyone have any idea how you would code this, code would be nice so i could see it but an explanation isnt discouraged

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243`` `````` Write a function "void link(char **tiles)" that given a list of 'tiles' links them together sequentially in the order they are given, and prints out its progress at each step. A tile is a square split into quadrants, where each quadrant has a number from 0 to 9. A tile can connect if at least two of its quadrants match quadrants on adjacent tiles, but all adjacent quadrants have to match. Tiles can be rotated, and the inputs are always designed so there is only one place a tile will fit. Examples: char *tiles1[] = { "11", // 1 "23", "", "44", // 2 "11", "", "16", // 3 "36", "", "51", // 4 "71", "", "46", // 5 "26", "", "14", // 6 "68", 0}; link(tiles1) prints: 6 tiles link 1 11 23 link 2 44 11 11 23 link 3 44 11 1116 2336 link 4 44 5111 711116 2336 link 5 // note this tile had to be rotated 180 degrees clockwise 44 5111 71111662 233664 link 6 // note this tile had to be rotated 270 degrees clockwise 4448 511116 71111662 233664 char *tiles2[] = { "12", // 1 "34", "", "36", // 2 "15", "", "56", // 3 "78", "", "78", // 4 "90", "", "46", // 5 "26", "", "88", // 6 "01", "", "93", // 7 "54", 0}; link(tiles2) prints: 7 tiles link 1 12 34 link 2 // note this tile had to be rotated 180 degrees clockwise 5112 6334 link 3 // note this tile had to be rotated 90 degrees clockwise 755112 866334 link 4 // note this tile had to be rotated 90 degrees clockwise 97755112 08866334 link 5 // note this tile had to be rotated 270 degrees clockwise 97755112 08866334 66 42 link 6 // note this tile had to be rotated 90 degrees clockwise 97755112 08866334 08 66 18 42 link 7 // note this tile had to be rotated 270 degrees clockwise 97755112 08866334 08 66 34 18 42 95 char *tiles3[] = { "11", // 1 "12", "", "12", // 2 "93", "", "93", // 3 "99", "", "39", // 4 "98", "", "95", // 5 "86", "", "57", // 6 "66", "", "77", // 7 "57", "", "13", // 8 "24", "", "45", // 9 "47", "", "24", // 10 "39", 0}; link(tiles3) prints: 10 tiles link 1 11 12 link 2 11 12 12 93 link 3 11 12 12 93 93 99 link 4 11 12 12 93 9339 9998 link 5 11 12 12 93 933995 999886 link 6 11 12 12 93 93399557 99988666 link 7 11 12 12 77 93 57 93399557 99988666 link 8 1113 1224 12 77 93 57 93399557 99988666 link 9 1113 122445 12 4777 93 57 93399557 99988666 link 10 1113 122445 12244777 9339 57 93399557 99988666``````
Last edited on
Sounds more like a homework problem than an interview question :P

Anyway I'd start by making a class for the field. It'd basically be a 2D array that's resizable on any side with a helper function to place new tiles.

To keep it simple I'd brute force the placement. Just go through each open spot on the field (with 2 extra slots on each side) and see if it's a legal place to put the tile. If it is, place it, if not, move on to the next place.

If no places match, rotate the tile, try again.
how would i handle the rotations though ?
by rotating the tile? =P

move the UR number to DR, the DR number to DL, the DL number to UL, and the UL number to UR.
can you provide a small snippet of something similar to what you explained but not exactly the answer so i have an idea of what you mean ?
A right rotation (not the most efficient but it is a snippet that does a rotation):
 ``123456789`` ``````char tile[2][2]; // assume we have the layout // [0][0] [0][1] // [1][0] [1][1] char temp = tile[0][0]; tile[0][0] = tile[1][0]; // DL to UL tile[1][0] = tile[1][1]; // DR to DL tile[1][1] = tile[0][1]; // UR to DR tile[0][1] = temp; // UL to UR ``````

Just move the numbers as Disch said.
alright , now im confused on placement if the isnt a match of the number
Topic archived. No new replies allowed.