puzzle

Unique methods to generate sudoku puzzle [duplicate]

送分小仙女□ 提交于 2019-12-03 12:42:21
This question already has an answer here: How to generate Sudoku boards with unique solutions 9 answers How many possible unique ways are there to generate a Sudoku Puzzle?? I can think of only two possible ways 1) Take a solved Sudoku puzzle and shuffle the rows and columns 2) Generate a random number and check if it violates any Sudoku constraints, repeat untill number does not violate any Sudoku constraint for every square(theoretically possible but normally it leads to deadlocking ) Are there any other ways? Here is a 20-page PDF, titled "Sudoku Puzzles Generating: from Easy to Evil", that

Factorial in C without conditionals, loops and arithmetic operators

蹲街弑〆低调 提交于 2019-12-03 12:07:00
How can I find the factorial of a number (from 1 to 10) in C, without using: loop statements like for, while, and do while; conditional operators like if and case; and arithmetic operators like + , − , * , % , /, ++, −−? FYI: I found this question in C aptitude. Brian R. Bondy Since it is only 1 to 10, simply precompute it and store it in a simple int array of size 11. For the first element in the array put 1. It is not a valid input range for your problem but might as well be correct. We need to store 11 elements instead of the 10 we need because otherwise we'd need to use operation "-" to

Optimally picking one element from each list

余生长醉 提交于 2019-12-03 11:43:10
问题 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

i = ++i + ++i; in C++

拥有回忆 提交于 2019-12-03 10:18:07
Can someone explain to me why this code prints 14? I was just asked by another student and couldn't figure it out. int i = 5; i = ++i + ++i; cout<<i; The order of side effects is undefined in C++. Additionally, modifying a variable twice in a single expression has no defined behavior (See the C++ standard , §5.0.4, physical page 87 / logical page 73). Solution: Don't use side effects in complex expression, don't use more than one in simple ones. And it does not hurt to enable all the warnings the compiler can give you: Adding -Wall (gcc) or /Wall /W4 (Visual C++) to the command line yields a

Algorithm: Max Counters

冷暖自知 提交于 2019-12-03 09:10:59
问题 I have the following problem: You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max_counter − all counters are set to the maximum value of any counter. A non-empty zero-indexed array A of M integers is given. This array represents consecutive operations: if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X), if A[K] = N + 1 then operation K is max_counter. For example, given integer N = 5 and

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

老子叫甜甜 提交于 2019-12-03 09:06:19
问题 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

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

陌路散爱 提交于 2019-12-03 08:19:44
问题 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 +=

What can be the efficient approach to solve the 8 puzzle problem?

只愿长相守 提交于 2019-12-03 04:43:53
问题 The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary configuration of tiles, and move them so as to get the numbered tiles arranged in ascending order either running around the perimeter of the board or ordered from

Bridge crossing puzzle

折月煮酒 提交于 2019-12-03 04:22:27
问题 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

Find the smallest set of overlapping jobs

╄→гoц情女王★ 提交于 2019-12-03 03:39:45
A friend gave me a puzzle that he says can be solved in better than O(n^3) time. Given a set of n jobs that each have a set start time and end time (overlaps are very possible), find the smallest subset that for every job either includes that job or includes a job that has overlap with that job. I'm pretty sure that the optimal solution is to pick the job with the most unmarked overlap, add it to the solution set, then mark it, and its overlap. And repeat until all jobs are marked. Figuring out which job has the most unmarked overlappers is a simple adjacency matrix (O(n^2)), and this has to