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
11
votes
12 answers

review of a codility test - pair_sum_even_count

I recently took an online test on codility as part of a recruitment process. I was given two simple problems to solve in 1 hour. For those who don't know codility, its an online coding test site where you can solve ACM style problems in many…
geoaxis
  • 1,480
  • 6
  • 25
  • 46
11
votes
2 answers

Find the sum of all numbers between 1 and N divisible by either x or y

Say we have 3 numbers N, x and y which are always >=1. N will be greater than x and y and x will be greater than y. Now we need to find the sum of all number between 1 and N that are divisible by either x or y. I came up with this: sum =…
user545682
  • 119
  • 1
  • 6
11
votes
5 answers

Solving a logic puzzle using Prolog

The criminal is one of A, B, C and D. A says: "It's not me" B says: "It's D" C says: "It's B" D says: "It's not me" And we know that only one of them tells the truth. Who is the one? I want to solve it by using Prolog. It's an interview…
user198729
  • 61,774
  • 108
  • 250
  • 348
11
votes
13 answers

How to find the Largest Difference in an Array

Suppose I have an array of integers: int[] A = { 10, 3, 6, 8, 9, 4, 3 }; My goal is to find the largest difference between A[Q] and A[P] such that Q > P. For example, if P = 2 and Q = 3, then diff = A[Q] - A[P] diff = 8 - 6 diff = 2 If P = 1 and…
Randal Cunanan
  • 2,449
  • 6
  • 29
  • 38
11
votes
8 answers

puzzle: N persons sitting on round table. No of ways of handshakes without crossing any other handshakes

We have n persons sitting on a round table. Any person can do a handshake with any other person. In how many ways these n people can make handshakes so that no two handshakes crosses each other. I found this puzzle in a technical interview forum,…
user2328404
  • 423
  • 1
  • 4
  • 9
11
votes
5 answers

Generalised Two-Egg Puzzle

Here is the Problem Description : Suppose that we wish to know which stories in a N-story building are safe to drop eggs from, and which will cause the eggs to break on landing. We make a few assumptions: An egg that survives a fall can be used…
Amol Sharma
  • 1,521
  • 7
  • 20
  • 40
10
votes
10 answers

C puzzle: how will you print something on console?

/*you cannot change anything from here below*/ main() { exit(0); } /*you cannot change anything from here up*/ This was asked during an interview. I was told to print something on console. anybody?
bakra
  • 387
  • 4
  • 15
10
votes
2 answers

What's the scope of a Javascript variable declared in a for() loop?

Check out the following snippet of HTML/Javascript code: