Questions tagged [puzzles]

The puzzles tag is for discussing algorithms and design approaches for solving programming puzzles. Puzzle competitions or contests should be asked at Programming Puzzles & Code Golf.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
200 views

What does the 4th line of this pseudocode mean? [closed]

https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/untangle.html Untangle is a game where you must "untangle" the line so they don't cross. It requires a planar graph, meaning a graph ...
  • 2,266
-4 votes
4 answers
2k views

Time efficient way to count pairs in an array whose sum is divisible by a specific number?

Given an array of integers, we want to find how many explicit pairs can be made such that their sum is divisible by 60. The pairs are not necessarily non-unique. For example, let's say the input into ...
  • 1,359
-2 votes
2 answers
74 views

How do I model all the different states of a widget for testing?

Say I am a QA person so I have no control over the complexity of the code in the following example. I have a datatable widget with many different filtering and searching options. All the columns on ...
  • 1,145
1 vote
1 answer
223 views

What is the right algorithm to solve this problem?

The problem is - We have a series of boxes (A, B, C, D, ...). Each box contains bricks of different colours. For eg. Box A - red, blue Box B - blue, red, green ... and so on... and there are ...
0 votes
1 answer
268 views

Find two horizontal lines to minimize distance to scattered points

I am having trouble with a coding question that I found practicing for a interview: A scatter graph of points on a page, draw two horizontal lines (these lines are parallel) across the page such that ...
2 votes
2 answers
394 views

Algorithm to solve this "treefarm" puzzle

How would I go about writing a program to solve this kind of puzzle: The green squares represent trees, and you have to plant them in such a way, so that: Trees do not touch each other at all (not ...
  • 123
3 votes
3 answers
2k views

Find a line that is closest to scattered points

I came across the below interview question on Glassdoor: A scatter graph of points on a page, draw a horizontal line across the page such the the perpendicular y distance to the line from all ...
2 votes
1 answer
467 views

Solving a Sudoku variant with an unknown element

I recently stumbled upon a special Sudoku variant and am now struggling to effectively solve it programatically. Consider the following initial 6x6 grid: The rules The red question mark is supposed ...
  • 129
1 vote
2 answers
465 views

What is a O(n) algorithm to solve this puzzle?

We are going to hold a meeting where everybody will speak in clockwise direction around a table. There are n people with n spots. Each person has a position preference (e.g. some want to go first, ...
0 votes
1 answer
4k views

Puzzle solving: Minimum number of steps to achieve a goal

I have been doing some programming contest problems, and I have noticed that many of them involve something along the lines of "get the minimum number of steps necessary to achieve a certain goal&...
  • 3,879
-2 votes
1 answer
296 views

How does one generate challenging different puzzles like the one in AirLock android game [closed]

here's the link of the app: https://play.google.com/store/apps/details?id=com.iatll.airlock I had studied AI in the final year of b.tech cs programme, and i do remember some algorithm of ...
30 votes
5 answers
7k views

Champaign Fountain Puzzle

Empty glasses of water are arranged in the following order: When you pour liquid into the 1st glass if it's full, then the extra liquid would be flown into the glasses 2 and 3 in equal quantities. ...
1 vote
1 answer
1k views

Reading graph inputs for a programming puzzle and then solving it

I just took a programming competition question and I absolutely bombed it. I had trouble right at the beginning itself from reading the input set. The question was basically a variant of this puzzle ...
1 vote
3 answers
2k views

Backtracking with Killer Sudoku

I'm developing a Killer Sudoku solver for a school project. I've programmed 10 human strategies showing what they are doing in order to be the most educational possible. It can solve hard Killer ...
  • 389
53 votes
11 answers
19k views

Get 100 highest numbers from an infinite list

One of my friend was asked this interview question - "There is a constant flow of numbers coming in from some infinite list of numbers out of which you need to maintain a datastructure as to ...
10 votes
4 answers
1k views

Are Quines useful as anything more than a programming puzzle?

Quines, which are programs that generate their own code as part or all of their output are a neat idea for a programming puzzle. However, do they have any use beyond that?
user avatar
10 votes
7 answers
6k views

N queens, X by Y board decision problem interview question

I was asked the following question in an interview today and I've been thinking about it ever since. I was not able to answer it and haven't been able to find a solution online. Given a chess board ...
91 votes
15 answers
63k views

Tricky logic puzzles - Are they really useful in assessing programming skills? [closed]

In the last interview I attended, I was asked to solve a puzzle where I was expected to measure exactly blah liters of water given two buckets with capacities - blah and blah liters respectively. I ...
4 votes
5 answers
3k views

sets of numbers that sum to a certain number?

I was asked this in an interview, and I'm not sure what the answer is or how to approach the problem. Find a pair of numbers that sum up to zero (or any other number), then find three (and then ...
  • 141
167 votes
1 answer
293k views

Where can I find programming puzzles and challenges? [closed]

I'm trying to find places where I can hone my craft outside the context of school or work. Are there places online, or books available, where I can access lists of programming puzzles or challenges?