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

2
votes
24answers
1k 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
708 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
508 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
522 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 ...
-12
votes
3answers
538 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
212 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
160 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 ...
3
votes
5answers
557 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
403 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
1k 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
397 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 ...
4
votes
0answers
401 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
314 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
652 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
368 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 ...
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
268 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 ...
12
votes
7answers
5k 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 ...
5
votes
5answers
408 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 ...