puzzle

Programmer Puzzle: Encoding a chess board state throughout a game

感情迁移 提交于 2019-12-02 13:46:49
Not strictly a question, more of a puzzle... Over the years, I've been involved in a few technical interviews of new employees. Other than asking the standard "do you know X technology" questions, I've also tried to get a feel for how they approach problems. Typically, I'd send them the question by email the day before the interview, and expect them to come up with a solution by the following day. Often the results would be quite interesting - wrong, but interesting - and the person would still get my recommendation if they could explain why they took a particular approach. So I thought I'd

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

一个人想着一个人 提交于 2019-12-02 10:05:54
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() for the images, compare those setLevel values with getLevel values for images after sliding still

SEHException .net Conundrum

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 10:04:23
问题 Can anyone explain why the below code throws an error. It can easily be fixed by either casting the -1 value to a decimal (-1M), by changing the operator overload to accept an int or by not using a nullable object. I have noticed the error doesnt get thrown in VS2010 only VS2008. class Program { static void Main(string[] args) { var o1 = new MyObject?(new MyObject(2.34M)); o1 *= -1; } } public struct MyObject { public MyObject(Decimal myValue) { this.myValue = myValue; } private Decimal

How to create a magic square in PHP?

◇◆丶佛笑我妖孽 提交于 2019-12-01 22:00:55
问题 I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up

How to create a magic square in PHP?

本秂侑毒 提交于 2019-12-01 21:11:06
I'd like to try my hand at creating a Magic Square in PHP (i.e. a grid of numbers that all add up to the same value), but I really don't know where to start. I know of the many methods that create magic square, such as starting "1" at a fixed position, then moving in a specific direction with each iteration. But that doesn't create a truly randomized Magic Square, which is what I'm aiming for. I want to be able to generate an N-by-N Magic Square of N² numbers where each row and column adds up to N(N²+1)/2 (e.g. a 5x5 square where all rows/columns add up to 65 — the diagonals don't matter). Can

Word Jumble Algorithm

人走茶凉 提交于 2019-12-01 16:27:49
Given a word jumble (i.e. ofbaor), what would be an approach to unscramble the letters to create a real word (i.e. foobar)? I could see this having a couple of approaches, and I think I know how I'd do it in .NET, but I curious to see what some other solutions look like (always happy to see if my solution is optimal or not). This isn't homework or anything like that, I just saw a word jumble in the local comics section of the paper (yes, good ol' fashioned newsprint), and the engineer in me started thinking. edit: please post some pseudo code or real code if you can; it's always nice to try

QCRs vs functional property

ぐ巨炮叔叔 提交于 2019-12-01 14:39:38
I have question based on the topic: SOF - Einstein puzzle in OWL In the owl, all cardinality restrictions are based on functional and inverse functional properties of Object Properties. I have remodeled it using QCRs. Old model (example): man drinks some beverage; drinks -> functional, inferse functional New model /EDITED/ : man drinks exactly 1 beverage; beverage drinkedBy exactly 1 man; drinks -> domain:man, range:beverage drinkedBy -> domain:beverage, range:man drinks inverseOf drinkedBy I replaced all "some" with "exactly 1". I think the first type is equivalent to the second model, but

Merge two arrays and sort the final one

拥有回忆 提交于 2019-12-01 13:46:23
In an interview I was asked the following question. I am given two arrays, both of them are sorted. BUT Array 1 will have few -1's and Array 2 will have total numbers as the total number of -1's in Array 1. So in the below example array1 has three -1's hence array2 has 3 numbers. let say var arrayOne = [3,6,-1,11,15,-1,23,34,-1,42]; var arrayTwo = [1,9,28]; Both of the arrays will be sorted. Now I have to write a program that will merge arrayTwo in arrayOne by replacing -1's, and arrayOne should be in sorted order. So the output will be arrayOne = [ 1,3, 6, 9, 11, 15, 23, 28 ,34, 42 ] Sorting

Which is the best algorithm to provide moves to solve 15 puzzle? [closed]

亡梦爱人 提交于 2019-12-01 11:31:57
i am working to find the solution steps for a randomly generated "15 puzzle". So tell me which is the best algorithm to use to solve it fast. Provide me approach to do so. I am making a tree of nodes containing 4*4 array and traversing through all the node which are not yet processed and when i get the solution i stop the iteration. In viewcontroller i have some code as - (IBAction)getSolution:(id)sender { while (!appDelegate.isResultFound) { TreeNode *node=[self nodeWithLowestCostAndUnproceessedInRootNode]; [node expandNodeToChilds]; //break; } NSLog(@"Result Found"); if([appDelegate.result

Knight's Tour backtracking infinite loop

﹥>﹥吖頭↗ 提交于 2019-12-01 11:21:58
I'm trying to write code for the Knight's Tour : A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. I've been trying to alter someone else's code, but the backtracking seems to not work properly - it never finds the solution. It works perfectly fine when the knight starts at 0, 0 but if it starts at any other spot on the 2D grid, the program goes on forever. Where is the bug in this code? #include <iostream> #include <ctime> using namespace std; const int N = 8; int map[N][N]; /* A utility function to check if i,j are valid