This tag is in the process of being replaced with [programming-puzzle] and [puzzle-solver]. Please don't use it on new questions.

learn more… | top users | synonyms

1
vote
19answers
717 views

Count how many characters are in the program's source

Write a program that counts and prints the number of characters in it's own source code to standard output. The number must be generated from counting the characters. This Ruby solution would not be ...
15
votes
1answer
667 views

Android Lock Screen

Intro You are sitting in a board room at the end of a long table. You look around and see Tim Cook, the Apple Board of Directors, the ghost of Steve Jobs, and Jack Donaghy. Apple has called this ...
29
votes
9answers
3k views

Kolmogorov-mania

The Kolmogorov complexity of a string s is defined as the length of the shortest program P that outputs s. If the length of P is shorter than the length of s, then s is said to be compressible, ...
5
votes
6answers
494 views

Finding n'th character in a Lucky String

Lucky numbers are those numbers which contain only "4" and/or "5". For example 4, 5, 44, 54,55,444 are lucky numbers while 457, 987 ,154 are not. Lucky number sequence is one in which all lucky ...
3
votes
4answers
475 views

Obtaining ordering of cards [closed]

You are given a deck containing n cards. While holding the deck: Take the top card off the deck and set it on the table Take the next card off the top and put it on the bottom of the deck in your ...
-11
votes
3answers
421 views

Swapping numbers, the shortest code wins [closed]

The goal is to swap 2 numbers. The shortest code wins. Temporary variables are not allowed You can manipulate only one variable at a time One of the variables may be 0
4
votes
3answers
202 views

Update All with O(1) [closed]

Create a data structure to represent an array. It must implement those function in O(1) get(index); // return the data at @index update(index, value); // update the data at @index to ...
0
votes
3answers
158 views

Permutable functions [closed]

In your favourite programming language, write two functions f and g such as f(g) gives the same (not trivial) result as g(f), but f and g are different (signifiant changes, not only trivial ...
8
votes
4answers
841 views

No branching please

Anyone who is moderately into low level code optimization know about the perils of branching, be it implemented as if-statements, loops or select-statements the possibility of a branch misprediction ...
3
votes
5answers
544 views

(Python) Implementing incrementation

Challenge: Implement incrementation without addition, multiplication, exponentiation, and any higher binary operators (and their opposites) in Python. Winner is the person who can do it in the least ...
-3
votes
2answers
391 views

Strings: Microsoft interview

You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ...
16
votes
0answers
946 views

Build a working game of Tetris in Conway's Game of Life

Here is a theoretical question - one that doesn't afford an easy answer in any case, not even the trivial one. In Conway's Game of Life, there exist constructs such as the metapixel which allow the ...
1
vote
2answers
385 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
1k views

Rail fence cipher

Write a program which reads a string and a key and encodes the string into a rail-fence cipher using that key. Similarly, write a program for reverse function, ie, deciphering a rail fence using a ...
10
votes
4answers
402 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 ...
3
votes
0answers
385 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
300 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
1k 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 ...
9
votes
1answer
635 views

What is the minimum set of characters with which you can write any valid python program?

The proof of the set of characters is that there is a translator which takes any ascii python program as input and produces a limited character set version of the program. The limited character set ...
6
votes
2answers
360 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 ...
-5
votes
1answer
288 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. ...
9
votes
0answers
722 views

Minimal Sudoku Generator [closed]

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 ...
13
votes
2answers
709 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 ...
6
votes
2answers
445 views

Which Numbers Would Crash this Function?

Which values of x and y will cause a crash with some C compilers? int f(int x, int y) { return (y==0) ? 0 : (x/y); }
85
votes
37answers
11k 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
265 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
328 views

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

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 ...
3
votes
13answers
1k 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 ...
4
votes
3answers
955 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
4k 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 ...
6
votes
3answers
726 views

Compose a Vim quine!

Goal: Create and save file in Vim containing at least 25 ASCII characters. The exact keystrokes used during the creation and saving of this file must also produce identical contents in Windows ...
6
votes
2answers
438 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 ...
8
votes
13answers
2k 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 ...
4
votes
5answers
405 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 ...