puzzle

What's the worst-case valid sudoku puzzle for simple backtracking brute force algorithm?

那年仲夏 提交于 2021-02-07 09:48:59
问题 The " simple/naive backtracking brute force algorithm", "Straightforward Depth-First Search" for sudoku is commonly known and implemented. and no different implementation seems to exist. (when i first wrote this question.. i wanted to mean we could completely standardize it, but the wording is bad..) This guy has described the algorithm well i think: https://stackoverflow.com/a/2075498/3547717 Edit: So let me have it more specified with pseudo code... var field[9][9] set the givens in 'field'

Rock, Paper, Scissors. Determine win/loss/tie using math?

允我心安 提交于 2020-06-14 06:22:05
问题 So I was writing a rock paper scissors game when I came to writing this function: a is player one's move, b is player two's move. All I need to figure out is if player one won, lost, or tied. //rock=0, paper=1, scissors=2 processMove(a, b) { if(a == b) ties++; else { if(a==0 && b==2) wins++; else if(a==0 && b==1) losses++; else if(a==1 && b==2) losses++; else if(a==1 && b==0) wins++; else if(a==2 && b==1) wins++; else if(a==2 && b==0) losses++; } } My question is: What's the most elegant way

what is wrong with this thread-safe byte sequence generator?

时光总嘲笑我的痴心妄想 提交于 2020-03-18 12:08:12
问题 I need a byte generator that would generate values from Byte.MIN_VALUE to Byte.MAX_VALUE. When it reaches MAX_VALUE, it should start over again from MIN_VALUE. I have written the code using AtomicInteger (see below); however, the code does not seem to behave properly if accessed concurrently and if made artificially slow with Thread.sleep() (if no sleeping, it runs fine; however, I suspect it is just too fast for concurrency problems to show up). The code (with some added debug code): public

Given N marbles and M floors, find the algorithm to find the lowest floor from which marble would break

≡放荡痞女 提交于 2020-02-04 01:26:26
问题 It is related to this questioN : Two marbles and a 100 story building BUT it is not the same ... We are to figure out best algorithm to figure out, strategy to minimize maximum drops required to find lowest floor .. Here is what I have on top of my mind The last marble has to be dropped in stepwise fashion Rest of the marbles will choose a hop (say hop-n) e.g.. So when N = 2, M = 100, We know that maximum drops=14 and hop-1 = the floor from which first marble will be dropped for very first

How to store sets, to find similar patterns fast?

喜夏-厌秋 提交于 2020-01-16 10:09:34
问题 (This is no homework and no work issue. It's just my personal interest/occupation and completly fictional. But I am interested in a good algorithm or data structure.) Let's assume, that I would run a dating site. And my special feature would be that the singles were matched by movie taste . (Why not?) In that case I would need a way to store the movie ratings for each user. (So far no problem.) And I would need a data structure to find the best fitting user. The distance between two taste

What causes the array in the following code not to be printed?

半腔热情 提交于 2020-01-15 12:27:29
问题 There is something wrong with the code below... Could someone explain to me whats the problem and why? #include<stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d=-1;d <= (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]); return 0; } 回答1: The sizeof operator: ... "The value of the result is implementation-defined, and its type (an unsigned integer type) is size_t, defined in < stddef.h > (and other headers)." - C99

Routing “paths” through a rectangular array

别说谁变了你拦得住时间么 提交于 2020-01-13 17:06:51
问题 I'm trying to create my own implementation of a puzzle game. To create my game board, I need to traverse each square in my array once and only once. The traversal needs to be linked to an adjacent neighbor (horizontal, vertical or diagonal). I'm using an array structure of the form: board[n,m] = byte Each bit of the byte represents a direction 0..7 and exactly 2 bits are always set Directions are numbered clockwise 0 1 2 7 . 3 6 5 4 Board[0,0] must have some combination of bits 3,4,5 set My

Routing “paths” through a rectangular array

匆匆过客 提交于 2020-01-13 17:02:56
问题 I'm trying to create my own implementation of a puzzle game. To create my game board, I need to traverse each square in my array once and only once. The traversal needs to be linked to an adjacent neighbor (horizontal, vertical or diagonal). I'm using an array structure of the form: board[n,m] = byte Each bit of the byte represents a direction 0..7 and exactly 2 bits are always set Directions are numbered clockwise 0 1 2 7 . 3 6 5 4 Board[0,0] must have some combination of bits 3,4,5 set My

Find the smallest set of overlapping jobs

懵懂的女人 提交于 2020-01-12 03:28:44
问题 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

Knight's Tour backtracking infinite loop

巧了我就是萌 提交于 2020-01-11 06:50:33
问题 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