Questions tagged [puzzle]

DO NOT USE - prefer constructive questions, or use more descriptive tags. Otherwise, your question might be appropriate for codegolf.stackexchange.com.

DO NOT USE - prefer constructive questions, or use more descriptive tags. Otherwise, your question might be appropriate for CodeGolf.


The questions tagged "puzzle" are essentially programming questions, that are as good as solving puzzles. These can be contrasted to the real-life problems, which are comparatively easy to solve.

859 questions
23
votes
7 answers

Single Number II from leetcode

The question about Single Number II from leetcode is: Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without…
CSnerd
  • 2,129
  • 8
  • 22
  • 45
21
votes
3 answers

Construct the largest possible rectangle out of line segments of given lengths

I recently participated in a competition where I was asked this question. Given an array with lengths what is the area of the biggest rectangle that can be made using ALL the lengths. The lengths can be added but not broken in between. Example: […
johne
  • 391
  • 3
  • 8
21
votes
4 answers

C Code: How does these even work?

I just saw this here #include int main(int argc, char *argv[printf("Hello, world!\n")]) {} What this does is print "Hello World!" But what's actually going on here? The best I can guess is that it gets compiled and thrown at the top of…
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77
21
votes
5 answers

SQL: how to get all the distinct characters in a column, across all rows

Is there an elegant way in SQL Server to find all the distinct characters in a single varchar(50) column, across all rows? Bonus points if it can be done without cursors :) For example, say my data contains 3…
frankadelic
  • 20,543
  • 37
  • 111
  • 164
19
votes
10 answers

Check if a number is divisible by 3

Write code to determine if a number is divisible by 3. The input to the function is a single bit, 0 or 1, and the output should be 1 if the number received so far is the binary representation of a number divisible by 3, otherwise…
Eyal
  • 5,728
  • 7
  • 43
  • 70
19
votes
14 answers

Code Golf: Automata

I made the ultimate laugh generator using these rules. Can you implement it in your favorite language in a clever manner? Rules: On every iteration, the following transformations occur. H -> AH A -> HA AA -> HA HH -> AH AAH -> HA HAA -> AH n…
Unknown
  • 45,913
  • 27
  • 138
  • 182
19
votes
6 answers

Print number of 1s in a sequence up to a number, without actually counting 1s

An interview question: Make a program which takes input 'N'(unsigned long) and prints two columns, 1st column prints numbers from 1 to N (in hexadecimal format) and second column prints the number of 1s in the binary representation of the number in…
Manish Baphna
  • 422
  • 2
  • 13
19
votes
2 answers

Programming two trains to intersect without positional data or communication (logic puzzle)

A helicopter drops two trains, each on a parachute, onto a straight infinite railway line. There is an undefined distance between the two trains. Each faces the same direction, and upon landing, the parachute attached to each train falls to the…
siva
  • 1,693
  • 2
  • 21
  • 29
19
votes
4 answers

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…
Luiscencio
  • 3,855
  • 13
  • 43
  • 74
19
votes
15 answers

C# Potential Interview Question…Too hard?

Without running this code, identify which Foo method will be called: class A { public void Foo( int n ) { Console.WriteLine( "A::Foo" ); } } class B : A { /* note that A::Foo and B::Foo are not related at all */ public void…
FlySwat
  • 172,459
  • 74
  • 246
  • 311
19
votes
6 answers

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

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…
Ravindra S
  • 6,302
  • 12
  • 70
  • 108
19
votes
9 answers

Solving Puzzle in Python

I got one puzzle and I want to solve it using Python. Puzzle: A merchant has a 40 kg weight which he used in his shop. Once, it fell from his hands and was broken into 4 pieces. But surprisingly, now he can weigh any weight between 1 kg to 40…
Abid Rahman K
  • 51,886
  • 31
  • 146
  • 157
18
votes
37 answers

Programming Riddle: Counting down without subtracting

Ok, goal by example : a command-line app that does this: Countdown.exe 7 prints 7 6 5 4 3 2 1 No form of subtracting (including use of the minus sign) or string reverse what so ever is allowed. waaaaay too easy apparently :-) An overview of the…
Peter
  • 47,963
  • 46
  • 132
  • 181
18
votes
4 answers

Designing a twenty questions algorithm

I am interested in writing a twenty questions algorithm similar to what akinator and, to a lesser extent, 20q.net uses. The latter seems to focus more on objects, explicitly telling you not to think of persons or places. One could say that akinator…
IVlad
  • 43,099
  • 13
  • 111
  • 179
1 2
3
57 58