A puzzle is a problem or enigma that tests the ingenuity of the solver Puzzles are often contrived as a form of entertainment, but they can also stem from serious mathematical or logistical problems. Solutions to puzzles may require recognizing patterns and creating a particular order

learn more… | top users | synonyms

1
vote
2answers
270 views

solve puzzle with a tweet? javascript (fun challenge)

the question is "complete this subtraction by replacing the asterisks with digits so the numbers 1-9 only appear once each" 9** -*4* ____ **1 my code tries random numbers until it works, and ...
2
votes
2answers
343 views

Rail fence cipher- Is there any better solution?

I have coded Rail Fence Cipher in Python. I was wondering if there could be a better solution. For those who don't know what rail fence cipher is, it is basically a method of writing plain text in a ...
5
votes
3answers
491 views

Build a Killer Sudoku Solver

You thought regular sudoku was hard, now try Killer Sudoku! In the game of Killer Sudoku, you aren't given any numbers at all. Instead, you're given regions that are said to add up to a certain ...
10
votes
4answers
324 views

Build a readability index

The Flesch-Kincaid readability algorithm depends on the measures of word count and syllable count, neither of which is entirely objective, or easily automatable using a computer. For example, does ...
0
votes
0answers
179 views

Problem: How many shops are open at a certain time? [closed]

I was posed this question at an interview and never really came up with a great solution. Does anyone have an "optimum" solution? Where the target is efficiency and being able to deal with large ...
3
votes
4answers
479 views

A programming challenge. Number Cross Puzzle

This is from a programming challenge website. The cross problem states that you can place the numbers 1 through N inside the cross such that no two adjacent cells in any direction (up, down, left ...
7
votes
2answers
441 views

m3ph1st0s's programming puzzle 3 (C): “Easy bug”

This is the 3rd of my series of C/C++ puzzles; in case you missed the first 2 they are here: (1) m3ph1st0s's programming puzzle 1 (C++) (2) m3ph1st0s's programming puzzle 2 (C++): "Call ...
2
votes
4answers
311 views

m3ph1st0s's programming puzzle 2 (C++): “Call hard!”

I am back with a brand new puzzle for C/C++ addicts. Following the feedback received on the 1st puzzle, this time I will try to make the requirements crystal clear and to provide a perfectly valid ...
1
vote
0answers
245 views

Splitting goods among people so that everyone feels happy

A favorite puzzle of mine: There are n people and k goods. The goods can be arbitrarily split (let's imagine they're different raw metals, for example). Your task is to split them among those n people ...
2
votes
1answer
217 views

Minimum number of transactions so everyone has paid the same

On a road trip, N people pay for fuel. Each pays a different amount. At the end of the trip, calculate the minimum number of transactions so that each person has paid the same amount. e.g. on the ...
5
votes
4answers
641 views

A simple Knight's problem

How many ways are there to place a black and a white knight on an N * M chessboard such that they do not attack each other? A knight can move two squares horizontally and one square vertically, or ...
1
vote
1answer
186 views

does this matrix represent some string [closed]

One of my friends asked me this.. What does this represent? Some string? A B C D A = > < > B < = < < C > > = > D < > < = the only thing I have been able ...
12
votes
1answer
1k views

Solve the 15 Puzzle (the tile-sliding puzzle)

The 15 Puzzle is a famous puzzle involving sliding 15 tiles around on a 4x4 grid. Starting from a random configuration, the goal is to arrange the tiles in the correct order. Here is an example of a ...
5
votes
2answers
270 views

Generate a valid equation using user-specified numbers

This is based on a game one of my math teachers used to play in middle school. He would write 5 random one-digit numbers on the board, and then a random two-digit number. We would try to create an ...
1
vote
3answers
835 views

Code Solution for the Magic Hexagon

A magic hexagon is a hexagon where every row and every diagonal add up to the same value. In this case the value is 38. Each number from 1 to 19 must be used exactly once. This image shows a ...
-5
votes
1answer
227 views

Sort an array with values of integer

There is an array of integer values to be sorted.During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. ...
4
votes
0answers
454 views

Minimal Sudoku Generator

Ask questions if you need to, I'll elaborate on anything that needs clarified. My challenge is to unsolve a sudoku to a minimal state. Basically take a supplied, solved, sudoku board and unsolve it ...
7
votes
3answers
707 views

Solve the 14-Pegs puzzle

Introduction A common puzzle involves a triangular board with 15 holes for tees/pegs as shown in the image below: Starting with all the pegs in the board except for a hole at the top, the point of ...
11
votes
2answers
425 views

Code golf: Solve a Knights and Knaves logic problem by parsing English

Background There are two people, Bill and John. One of them is a knight, which always tells the truth, and the other is a knave, which always tells a lie. You don't know who is the knight and who is ...
65
votes
37answers
6k views

Write a program that always outputs “2012” - even if it's modified!

This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite ...
1
vote
2answers
239 views

Construct the largest possible rectangle out of line segments of given lengths [closed]

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 ...
-1
votes
3answers
295 views

Programming puzzle to print all numbers from 1 to n of a random system

I have a number system with the symbols {a,b,c,d,...n} I want to print the sequence a b c . . . n aa ab ac .. nn aaa aab aac ... nnn ... and so on. A pseudocode/algorithm is what I am looking ...
2
votes
10answers
706 views

Count the number of times a function runs

This is a teaser a friend of mine sent. It seems straightforward, but I can't seem to get my head around it, probably due to my lack of sleep. You have 16 bits available. Compose a function, and ...
3
votes
3answers
640 views

Lights Out - Find the solution

(This code golf task is related to Code-Golf: Lights Off!. The same puzzle is used, but the task is different.) Introduction "Lights Out" is a puzzle in which you should switch off all lights in a ...
12
votes
7answers
2k views

Compute the CRC32 table at compile-time

The reference implementation of CRC32 computes a lookup table at runtime: /* Table of CRCs of all 8-bit messages. */ unsigned long crc_table[256]; /* Flag: has the table been computed? Initially ...
22
votes
3answers
2k views

Solve the eight queens problem at compile-time

Can you solve the eight queens puzzle at compile-time? Pick any suitable output format. I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have ...
6
votes
2answers
296 views

Program that runs when rows and columns are transposed

I posted this to The Daily WTF coder challenge forum a few years ago but only got one response. I figure CodeGolf stack exchange might generate more interest! Description Write a program that runs ...
7
votes
13answers
1k views

Shuffle a deck without local variables

The object of this puzzle is to take a deck of 52 cards and shuffle it so that each card is in a random position. Given (i.e. assumed to exist already): A length-52 array of integers representing ...
3
votes
5answers
353 views

Stable positive/negative separation

From SO. You are given an array with positive and negative integers. Write a function to change the elements order in the array such that negative integers are at the beginning, the positive integers ...
9
votes
7answers
1k views

Implement a Brute Force Sudoku Solver

Implement the shortest Sudoku solver using guessing. Since I have received a few request I have added this as an alternative question for those wishing to implement a brute force sudoku solver. ...
12
votes
4answers
1k views

Implement a Non-Guessing Sudoku Solver

Implement the shortest Sudoku solver. Sudoku Puzzle: | 1 2 3 | 4 5 6 | 7 8 9 -+----------------------- A| 3 | 1 | B| 6 | | 5 C| 5 | | 9 8 3 -+----------------------- ...
5
votes
1answer
1k views

Nokia mystery puzzle

A friend sent me this puzzle. I'm pretty sure solving it will require some programming. Can anyone crack it? The original is here in case of encoding issues in the past below. Did you know that... ...