puzzle

ARM assembly puzzle

First of all, I'm not sure if solution even exists. I spent more than a couple of hours trying to come up with one, so beware. The problem: r1 contains an arbitrary integer, flags are not set according to its value. Set r0 to 1 if r1 is 0x80000000, to 0 otherwise, using only two instructions. It's easy to do that in 3 instructions (th...

Java HashSet and data type Short, incompatibility ?

Running this code: public class SomeSet { public static void main(String[] args) { Set<Short> s = new HashSet<Short>(); for (short i = 0; i < 100; i++) { s.add(i); s.remove(i - 1); } System.out.println(s.size()); } } Will print the value 100. Why does it pri...

create jigsaw puzzle piece from an existing image on iPhone

How would one go about creating jigsaw puzzle pieces from an image on the fly. I want the application to get the images from the library and then create puzzle pieces around that. Any ideas? open source libs? ...

Solution for "crackless wall" problem

Hi all, Here's the problem statement : Consider the problem of building a wall out of 2x1 and 3x1 bricks (horizontal×vertical dimensions) such that, for extra strength, the gaps between horizontally-adjacent bricks never line up in consecutive layers, i.e. never form a "running crack". There are eight ways of forming a crack-free 9x3 w...

XKCD - Labyrinth puzzle

There is a modified labyrinth puzzle on xkcd: http://xkcd.com/246/ After reading it we asked on an interview, "how many questions required to survive and solve this puzzle?" Our best solution requires 5 questions, 1-1-1 question to everyone, and 2 to a chosen one based on the first 3. Can anybody construct a better, or different logic...

Question from Interview, Retrieve alphabetic order from dictionary

My girlfriend got this question in an interview, and I liked it so much I thought I'd share it... Write an algorithm that receives a dictionary (Array of words). The array is sorted lexicographically, but the abc order can be anything. For example, it could be z, y, x, .., c, b, a. Or it could be completely messed up: d, g, w, y, ... It ...

Hint for a C# and also an SQL Puzzle

I was browsing SO careers and came across a job that had a pdf with a couple of puzzles they wanted applicants to send in. Although I'm not interested in the job, I read the questions anyway and had a play in Visual Studio / SMSS. The first question was fairly easy to solve although I couldn't think if any way to optimise it (I solved ...

Computing the colors of the Olympic flag

Let's say you are helping setting up the Olympics on an alien planet. You are in charge of making the Olympic flag. The Olympic flag would have 6 colors. The flags of every country on the planet must have one of the six colors on the Olympic flag. You already know the colors on a flag. How would you compute the colors on the Olympic flag...

How can I reduce this problem to the Tower of Hanoi (or solve it in the least number of iterations)?

Suppose there are 2n+1 holes and 2 sets of n sticks, one set white and another black. The sticks are initially organized so that the white sticks are left, there is a hole in the middle and the black sticks are right. A stick can move by either: 1) being placed on the hole next to it, if empty 2) jump the neighboring stick iff the neig...

Algorithm to find minimum number of weightings required to find defective ball from a set of n balls

Okay here is a puzzle I come across a lot of times- Given a set of 12 balls , one of which is defective (it weighs either less or more) . You are allow to weigh 3 times to find the defective and also tell which weighs less or more. The solution to this problem exists, but I want to know whether we can algorithmically determine if given ...

Generating uniformly random curious binary trees.

A binary tree of N nodes is 'curious' if it is a binary tree whose node values are 1, 2, ..,N and which satisfy the property that Each internal node of the tree has exactly one descendant which is greater than it. Every number in 1,2, ..., N appears in the tree exactly once. Example of a curious binary tree 4 / \ 5 2 / \ ...

One instruction to clear PF (Parity Flag) -- get odd number of bits in result register

In X86 assembly, is it possible to clear the Parity Flag in one and only one instruction, working under ANY initial register configuration? This is equivalent to creating a result register with an ODD number of bits, with any operation that sets flags (expressly excluding "mov"). For contrast, setting the parity flag can be done in o...

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

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 th...

Not able to solve the puzzle regarding this code.....

int i,n=20; for(i=0;i<n;i--) printf("-"); I have been rattling my brain but have not been able to solve this. Delete any single character or operator from above code and the program should print "-" 20 times Please help! ...

Puzzle that defies the brute force approach?

I bought a blank DVD to record my favorite TV show. It came with 20 digit stickers. 2 of each of '0'-'9'. I thought it would be a good idea to numerically label my new DVD collection. I taped the '1' sticker on my first recorded DVD and put the 19 leftover stickers in a drawer. The next day I bought another blank DVD (receiving 20 new st...

Permutation/Algorithm to Solve Conditional Fill Puzzle

I've been digging around to see if something similar has been done previously, but have not seen anything with the mirrored conditions. To make swallowing the problem a little easier to understand, I'm going to apply it in the context of filling a baseball team roster. The given roster structure is organized as such: C, 1B, 2B, 3B, SS...

The “pattern-filling with tiles” puzzle

I've encountered an interesting problem while programming a random level generator for a tile-based game. I've implemented a brute-force solver for it but it is exponentially slow and definitely unfit for my use case. I'm not necessarily looking for a perfect solution, I'll be satisfied with a “good enough” solution that performs well. ...

How do I compute the cartesian product of n sequences in F#?

I was given a puzzle as a present. It consists of 4 cubes, arranged side by side. The faces of each cube are one of four colours. To solve the puzzle, the cubes must be orientated so that all four cubes' tops are different, all their fronts are different, all their backs are different and all their bottom's are different. The left and r...

How can I create a threshold for similar strings using Levenshtein distance and account for typos?

We recently encountered an interesting problem at work where we discovered duplicate user submitted data in our database. We realized that the Levenshtein distance between most of this data was simply the difference between the 2 strings in question. That indicates that if we simply add characters from one string into the other then we e...

What is your solution to the "Escape from Zurg" puzzle in C#?

found this puzzle HERE... I made a brute force solution and I would like to know how you woul solve it... Buzz, Woody, Rex, and Hamm have to escape from Zurg(a) They merely have to cross one last bridge before they are free. However, the bridge is fragile and can hold at most two of them at the same time. Moreover, to cross the bridge a...