puzzle

Adding one digit (0-9) to the sequence/string creates new 4 digits number

三世轮回 提交于 2019-12-01 09:18:23
I'm trying to find an algorithm which "breaks the safe" by typing the keys 0-9. The code is 4 digits long. The safe will be open where it identifies the code as substring of the typing. meaning, if the code is "3456" so the next typing will open the safe: "123456". (It just means that the safe is not restarting every 4 keys input). Is there an algorithm which every time it add one digit to the sequence, it creates new 4 digits number (new combinations of the last 4 digits of the sequence\string)? thanks, km. Editing (I post it years ago): The question is how to make sure that every time I set

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

别来无恙 提交于 2019-12-01 08:28:11
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . 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

Adding one digit (0-9) to the sequence/string creates new 4 digits number

浪子不回头ぞ 提交于 2019-12-01 06:14:47
问题 I'm trying to find an algorithm which "breaks the safe" by typing the keys 0-9. The code is 4 digits long. The safe will be open where it identifies the code as substring of the typing. meaning, if the code is "3456" so the next typing will open the safe: "123456". (It just means that the safe is not restarting every 4 keys input). Is there an algorithm which every time it add one digit to the sequence, it creates new 4 digits number (new combinations of the last 4 digits of the sequence

Need help solving a C-based programming puzzle

ⅰ亾dé卋堺 提交于 2019-12-01 05:10:41
问题 I came across this puzzle here. I can't figure out why NONE is not printed. Any ideas? #include<stdio.h> int main() { int a=10; switch(a) { case '1': printf("ONE\n"); break; case '2': printf("TWO\n"); break; defa1ut: printf("NONE\n"); } return 0; } 回答1: defa1ut: is a syntactically valid label, e.g. for a goto but not the default of the switch statement. If you compile with gcc with enough warnings it will point this out: ajw@rapunzel:/tmp > gcc -Wall -Wextra test.c test.c: In function ‘main’:

Spotify puzzle problem

穿精又带淫゛_ 提交于 2019-12-01 03:45:06
问题 I'm trying to solve the "best before" Spotify puzzle described on this page. Basically, with an input of three integers separated by slashes (e.g. 11/3/4) you're supposed to generate an output with the earliest possible date in 2011-03-04 format. If no date is possible, it should return the original string followed by "is illegal". The idea for my solution below was borrowed from a Python solution I found for the same problem at github. When I submit this Python code, it is accepted. Not

How can I ensure that when I shuffle my puzzle I still end up with an even permutation?

别说谁变了你拦得住时间么 提交于 2019-11-30 20:27:30
I'm interested making an implementation of the 14-15 puzzle : I'm creating an array with the values 0 - 15 in increasing order: S = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } Now, what I want to do is shuffle them to create a new instance of the puzzle. However, I know that if I create a board with an "odd permutation" than it is unsolvable. Wikipedia says I need to create the puzzle with an even permutation. I believe this means that I simply have to do ensure I do an even number of swaps? How would I modify Fisher-Yates so I ensure I end up with an even permutation at the end?

Why is my simple comparator broken?

好久不见. 提交于 2019-11-30 17:18:45
I have a class, which I have simplified to this: final class Thing { private final int value; public Thing(int value) { this.value = value; } public int getValue() { return value; } @Override public String toString() { return Integer.toString(value); } } I want to sort an array of this thing. So I have created a simple copmarator: private static final Comparator<Thing> reverse = new Comparator<Thing>() { public int compare(Thing a, Thing b) { return a.getValue() - b.getValue(); } }; I then use the two argument form of Arrays.sort . This works fine for my test cases, but sometimes it goes all

KenKen puzzle addends: REDUX A (corrected) non-recursive algorithm

谁都会走 提交于 2019-11-30 16:08:44
问题 This question relates to those parts of the KenKen Latin Square puzzles which ask you to find all possible combinations of ncells numbers with values x such that 1 <= x <= maxval and x(1) + ... + x(ncells) = targetsum. Having tested several of the more promising answers, I'm going to award the answer-prize to Lennart Regebro, because: his routine is as fast as mine (+-5%), and he pointed out that my original routine had a bug somewhere, which led me to see what it was really trying to do.

square puzzle solution

↘锁芯ラ 提交于 2019-11-30 10:20:26
Question: given an integer number n, print the numbers from 1 up to n 2 like this: n = 4 result is: 01 02 03 04 12 13 14 05 11 16 15 06 10 09 08 07 How do you solve it (apart from the solution provided in the link below)? http://www.programmersheaven.com/mb/CandCPP/81986/81986/problem-in-making-ap-c++-program/?S=B20000 I'm looking in another direction. So far, I'm trying to figure out if I could obtain the ordered list of positions I have to fill in. Here's what Im looking into: is there a way to obtain the "fdisp" so as to solve the problem that way, instead of "walk" in the matrix? matrix =

In C bits, multiply by 3 and divide by 16

别等时光非礼了梦想. 提交于 2019-11-30 07:45:56
A buddy of mine had these puzzles and this is one that is eluding me. Here is the problem, you are given a number and you want to return that number times 3 and divided by 16 rounding towards 0. Should be easy. The catch? You can only use the ! ~ & ^ | + << >> operators and of them only a combination of 12. int mult(int x){ //some code here... return y; } My attempt at it has been: int hold = x + x + x; int hold1 = 8; hold1 = hold1 & hold; hold1 = hold1 >> 3; hold = hold >> 4; hold = hold + hold1; return hold; But that doesn't seem to be working. I think I have a problem of losing bits but I