puzzle

The “pattern-filling with tiles” puzzle

不问归期 提交于 2019-12-03 03:17:27
问题 I've encountered an interesting problem while programming a random level generator for a tile-based game. I've implemented a brute-force solver for it but it is exponentially slow and definitely unfit for my use case. I'm not necessarily looking for a perfect solution, I'll be satisfied with a “good enough” solution that performs well. Problem Statement: Say you have all or a subset of the following tiles available (this is the combination of all possible 4-bit patterns mapped to the right,

Solving Nonograms (Picross)

梦想与她 提交于 2019-12-03 02:46:34
问题 it's Friday afternoon, let's have a fun puzzle/algorithm problem to solve. One of my favorite Nintendo DS games is Picross DS. The game is quite simple, it involves solving puzzles called Nonograms. You can try a simple online Picross clone here: TylerK's Picross. Nonograms are a grid, with sequences of numbers defined for every row and column of the grid. The numbers define blocks of "filled in" squares for that row/column, but the unfilled areas on either sides of the blocks are not defined

Optimally picking one element from each list

会有一股神秘感。 提交于 2019-12-03 02:11:42
I came across an old problem that you Mathematica/StackOverflow folks will probably like and that seems valuable to have on StackOverflow for posterity. Suppose you have a list of lists and you want to pick one element from each and put them in a new list so that the number of elements that are identical to their next neighbor is maximized. In other words, for the resulting list l, minimize Length@Split[l]. In yet other words, we want the list with the fewest interruptions of identical contiguous elements. For example: pick[{ {1,2,3}, {2,3}, {1}, {1,3,4}, {4,1} }] --> { 2, 2, 1, 1, 1 } (Or {3

How to programmatically solve the 15 (moving numbers) puzzle?

烂漫一生 提交于 2019-12-02 23:16:15
all of you have probably seen the moving number/picture puzzle. The one where you have numbers from 1 to 15 in a 4x4 grid, and are trying to get them from random starting position to 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 My girlfriend or some of my non-programmer friends can solve this with some mumbo-jumbo magic, that they can't explain to me. I can't solve the puzzle. The most promising approach I have found out is to solve first row, then I'd get 1 2 3 4 X X X X X X X X X X X then first column without touching solved cells 1 2 3 4 5 X X X 9 X X X 13 X X then second row to 1 2 3 4 5 6 7 8 9 X

C Code: How does these even work?

爱⌒轻易说出口 提交于 2019-12-02 22:16:06
I just saw this here #include <stdio.h> int main(int argc, char *argv[printf("Hello, world!\n")]) {} What this does is print "Hello World!" But what's actually going on here? The best I can guess is that it gets compiled and thrown at the top of the execution stack, but the syntax doesn't even look legal to me ... The code makes use of C99's variable-length array feature, which lets you declare arrays whose size is known only at run-time. printf returns an integer equal to the number of characters that were actually printed, so the code prints "Hello, world!" first and uses the return value as

Why does (x += x += 1) evaluate differently in C and Javascript?

ぐ巨炮叔叔 提交于 2019-12-02 22:01:05
If the value of the variable x is initially 0, the expression x += x += 1 will evaluate to 2 in C, and to 1 in Javascript. The semantics for C seems obvious to me: x += x += 1 is interpreted as x += (x += 1) which is, in turn, equivalent to x += 1 x += x // where x is 1 at this point What is the logic behind Javascript's interpretation? What specification enforces such behaviour? (It should be noted, by the way, that Java agrees with Javascript here). Update: It turns out the expression x += x += 1 has undefined behaviour according to the C standard (thanks ouah , John Bode , DarkDust , Drew

How to check whether the jigsaw puzzle is completed or not?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 18:50:18
问题 i am preparing one small game like jigsaw , for that i am using 9 imageview's with 9 different images in the layout. set the images to imageview at the time of starting those are actual images, after shuffle user will do sliding the images to complete puzzle, i want to check the modified image with actual image's, weather it's equal or not if those are equal popup a message, like gameover. i tried like this 1.by using AND operator between the images(Drawables) but unlucky. 2.Using setLevel()

Bridge crossing puzzle

风流意气都作罢 提交于 2019-12-02 17:46:45
Four men have to cross a bridge at night.Any party who crosses, either one or two men, must carry the flashlight with them. The flashlight must be walked back and forth; it cannot be thrown, etc. Each man walks at a different speed. One takes 1 minute to cross, another 2 minutes, another 5, and the last 10 minutes. If two men cross together, they must walk at the slower man's pace. There are no tricks--the men all start on the same side, the flashlight cannot shine a long distance, no one can be carried, etc. And the question is What's the fastest they can all get across. I am basically

The “pattern-filling with tiles” puzzle

一笑奈何 提交于 2019-12-02 16:48:35
I've encountered an interesting problem while programming a random level generator for a tile-based game. I've implemented a brute-force solver for it but it is exponentially slow and definitely unfit for my use case. I'm not necessarily looking for a perfect solution, I'll be satisfied with a “good enough” solution that performs well. Problem Statement: Say you have all or a subset of the following tiles available (this is the combination of all possible 4-bit patterns mapped to the right, up, left and down directions): alt text http://img189.imageshack.us/img189/3713/basetileset.png You are

Solving Nonograms (Picross)

南楼画角 提交于 2019-12-02 14:41:59
it's Friday afternoon, let's have a fun puzzle/algorithm problem to solve. One of my favorite Nintendo DS games is Picross DS . The game is quite simple, it involves solving puzzles called Nonograms . You can try a simple online Picross clone here: TylerK's Picross . Nonograms are a grid, with sequences of numbers defined for every row and column of the grid. The numbers define blocks of "filled in" squares for that row/column, but the unfilled areas on either sides of the blocks are not defined. For example, if you have a row that looks like this: (source: steam-punk.net ) Possible solutions