puzzle

Prolog: where to begin solving Minesweeper-like puzzle?

我的未来我决定 提交于 2019-12-11 01:28:10
问题 I need to write something like a minesweeper in prolog. I am able to do that in "normal" language but when i try to start coding with prolog i totally don't know how to start. I need some sort of tips. Input specification: Board size: m × n ( m , n ∈ {1,...,16}), list of triples ( i , j , k ), where i ∈ {1,..., m }, j ∈ {1,..., n }, k ∈ {1,...,8}) describing fields with numbers. For example: 5 5 [(1,1,1), (2,3,3), (2,5,2), (3,2,2), (3,4,4), (4,1,1), (4,3,1), (5,5,2)]. Output: list of digits

Timeout on a php Peg Puzzle solver

陌路散爱 提交于 2019-12-10 22:46:33
问题 first time here. I'm working on a Peg Puzzle php solver, using recursion. For small and simple boards, I get the desired results (the script solves the puzzle correctly), but for larger and full boards (i.e. all slots but one occupied) I get a php timeout. I need to get it to work with a 7x7 board, with the following layout: x x 1 1 1 x x x x 1 1 1 x x 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 x x 1 1 1 x x x x 1 1 1 x x Where 'x' is unusable, '1' is a slot with a peg and '0' is a free slot.

Jigsaw Puzzle, cutting pieces from image

风格不统一 提交于 2019-12-10 20:41:07
问题 I'm trying to make an application that cuts image into jigsaw puzzles. My problem is that I don't know how to do this (any kind of algorithm). I do want to have male and female endings of puzzles, but not in the same place all the time (like in the middle of puzzle border) so this: https://stackoverflow.com/questions/2755389/how-to-create-jigsaw-image-puzzle-using-c solution doesn't fit me. Is there any kind of "smart" algorithm to make this happens. I was thinking about using bezier curves,

Puzzled over palindromic product problem

浪尽此生 提交于 2019-12-09 13:11:35
问题 I've been learning Ruby, so I thought I'd try my hand at some of the project Euler puzzles. Embarrassingly, I only made it to problem 4... Problem 4 goes as follows: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. So I figured I would loop down from 999 to 100 in a nested for loop and do a test for the palindrome and then break out of

Puzzle: Need an example of a “complicated” equivalence relation / partitioning that disallows sorting and/or hashing

扶醉桌前 提交于 2019-12-09 11:59:36
问题 From the question "Is partitioning easier than sorting?": Suppose I have a list of items and an equivalence relation on them, and comparing two items takes constant time. I want to return a partition of the items, e.g. a list of linked lists, each containing all equivalent items. One way of doing this is to extend the equivalence to an ordering on the items and order them (with a sorting algorithm); then all equivalent items will be adjacent. (Keep in mind the distinction between equality and

Unique methods to generate sudoku puzzle [duplicate]

a 夏天 提交于 2019-12-09 10:31:07
问题 This question already has answers here : How to generate Sudoku boards with unique solutions (9 answers) Closed 5 years ago . 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

Factorial in C without conditionals, loops and arithmetic operators

泄露秘密 提交于 2019-12-09 10:06:42
问题 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. 回答1: 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

Programmer Puzzle: Encoding a chess board state throughout a game

旧时模样 提交于 2019-12-09 04:00:39
问题 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

How can this Java code compile?

牧云@^-^@ 提交于 2019-12-08 21:24:38
问题 A colleague came across some code that looked like this and couldn't understand how it could ever compile: class FooClass { public static void bar(String arg) { System.out.println("arg = " + arg); http://www.google.com System.out.println("Done!"); } } Basically, there was a random URL pasted in the middle of a method but javac didn't care. We worked out so I'll post the answer if no-one else finds out but I thought it was interesting enough to post. 回答1: "http:" is interpreted as a label.

Finding Frequency of numbers in a given group of numbers

你说的曾经没有我的故事 提交于 2019-12-08 16:27:34
问题 Suppose we have a vector/array in C++ and we wish to count which of these N elements has maximum repetitive occurrences and output the highest count. Which algorithm is best suited for this job. example: int a = { 2, 456, 34, 3456, 2, 435, 2, 456, 2} the output is 4 because 2 occurs 4 times. That is the maximum number of times 2 occurs. 回答1: Sort the array and then do a quick pass to count each number. The algorithm has O(N*logN) complexity. Alternatively, create a hash table, using the