Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [programming-puzzle]

A programming puzzle includes a goal, a partially completed program, and rules outlining how the program can be modified. The program is specifically designed to make achieving the goal difficult. An answer to a programming puzzle takes the program and modifies it only in ways specified in the rules, so that the goal is achieved.

Filter by
Sorted by
Tagged with
5 votes
2 answers
546 views

Results here will be actually be useful for me, I am looking to use them in teaching statistics/information theory. The words "as, at, is, it" match ...
Hamish Todd's user avatar
12 votes
3 answers
1k views

In this programming-puzzle, your goal is to write the following function in JavaScript, using (essentially) point-free (tacit) programming: (f) => void(f()) ...
rydwolf's user avatar
  • 19.3k
8 votes
1 answer
562 views

Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only. Answers meeting this extra ...
Shuri2060's user avatar
  • 191
9 votes
2 answers
435 views

Al wanted to use my computer to do some simple calculations, so I lent him the use of my R terminal for a bit. He complained though, saying it wasn't set up how he liked it. I said "No problem Al,...
JDL's user avatar
  • 1,773
3 votes
2 answers
521 views

Print the following text and nothing else: ...
user's user avatar
  • 457
11 votes
1 answer
274 views

This is a program I wrote in JavaScript to validate some inputted credentials, with an intentional vulnerability. The credentials_validator function takes an object ...
rydwolf's user avatar
  • 19.3k
1 vote
2 answers
621 views

Pipe a short stream to the following Java program run with accompanying command line options, such that it prints true. ...
Tom Hawtin - tackline's user avatar
2 votes
1 answer
206 views

Have you been shooting gallery? We are recently. In our shooting gallery cans and aluminum cans from under various drinks hang and stand. More precisely, they hung and stood. From our shots, banks ...
mobdevkun's user avatar
  • 121
4 votes
0 answers
131 views

Not exactly sure if it belongs in this site, but I always have trouble thinking of all the certain edge cases in any kind of competitive programming or puzzles. For example, take this kind of problem ...
bleh's user avatar
  • 181
6 votes
1 answer
439 views

Your task is to modify the original Plan 9 cat tool for UNIX, in order to make it a fully turing complete language interpreter. You may make use of ANSI escape codes and the backspace character (\x08) ...
Sabrina Jewson's user avatar
4 votes
3 answers
2k views

Below Python code generates memory leak. Challenge: Fix the memory leak with minimal changes to the code as measured by Levenshtein distance to the original code. You may only change the code before ...
Shital Shah's user avatar
3 votes
2 answers
360 views

For example, how many adjacent swaps are at least needed to convert some string such as BVVKCV to one without any instances of VK...
Justin Case's user avatar
1 vote
2 answers
328 views

Introduction I have some JavaScript code that uses Array.prototype.map to map an array of functions fns to their return values: ...
Rory O'Kane's user avatar
1 vote
0 answers
184 views

Circa 1976. With the success of the Tiny BASIC Design Note, a variety of Tiny BASIC IL implementations now span a range of microcomputers. The time has come to expand the Tiny BASIC standard. Grammar ...
Jeffrey Henning's user avatar
13 votes
5 answers
1k views

Given the following Python 3 script: def greet(): print("Hello, world!") greet() Prepend some lines to this text file so that it can be both executed as a ...
Leon's user avatar
  • 327
11 votes
4 answers
1k views

This programming puzzle is inspired by another question which has been asked here yesterday but which was deleted by the author... The challenge: Create an executable binary (Windows .EXE or Linux ...
Martin Rosenau's user avatar
1 vote
1 answer
232 views

In the following markup without changing it or using JS, implement the behavior to show only the ul element of div which name is ...
snowfinch27's user avatar
21 votes
2 answers
2k views

Challenge Given the following C# method: ...
a-ctor's user avatar
  • 337
26 votes
11 answers
2k views

If you think this could be fun, but too much work, consider participating in this much smaller challenge. A bit of fun (and possibly frustration!) for 2016... Dyalog's "puzzle of the year". ...
Adám's user avatar
  • 31.8k
15 votes
2 answers
914 views

Introduction For the ones wondering what Befunge exactly is, it is a two-dimensional stack based language made in 1993 by Chris Pressy. I made 7 brain teasers that need to be solved in Befunge-93. ...
Adnan's user avatar
  • 44.7k
8 votes
1 answer
647 views

This is a challenge for the people using Swift 2.0 beta 6, it's not code golf, but it's a programming puzzle so I'm pretty sure this belongs here. The basic idea is: Make it compile. There are more ...
Kametrixom's user avatar
5 votes
0 answers
717 views

I found an old post on Jon Skeet's blog that pointed out a puzzle from a tweet by Vladimir Reshetnikov: C# quiz: write a valid C# program containing a sequence of three tokens ...
Sabre's user avatar
  • 167
9 votes
7 answers
2k views

Write a few lines of Python code, X, that does not reference any global variables, such that ...
Owen's user avatar
  • 367
8 votes
0 answers
896 views

A friend of mine got this question during an interview. The interview ended with no luck for him, but still, we're very curious to hear the solution. The question is as follows: Modify the code below ...
ofirbt's user avatar
  • 181
-1 votes
2 answers
508 views

Without changing the actual function, call it in such a way that it prints "True" ...
dav's user avatar
  • 25
3 votes
0 answers
275 views

There's the old, well hashed version of the question that uses Dynamic Programming to calculate the minimum number of coins to reach a target value, but what if the coins you're given can't reach the ...
S. J.'s user avatar
  • 131
32 votes
22 answers
3k views

I find it deeply weird that this is possible in Ruby (I won't immediately say how): ...
histocrat's user avatar
  • 22.3k
19 votes
6 answers
2k views

This is limited to Java and C# by the syntax I guess. In this programming puzzle, you are to produce Exceptions that can be caught but are thrown again at the end ...
user21634's user avatar
  • 225
104 votes
159 answers
17k views

Your task is to reverse the order in which some prints get executed. Specs: Your code will be in this form: ...
Vereos's user avatar
  • 4,491
4 votes
1 answer
3k views

Isolated prime definition from Wikipedia: An isolated prime is a prime number p such that neither p − 2 nor p + 2 is prime. In other words, p is not part of a twin prime pair. For example, 23 is an ...
n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳'s user avatar
3 votes
10 answers
4k views

The following code will produce a run-time error, stackoverflow exception. ...
kiss my armpit's user avatar
16 votes
6 answers
7k views

Given the following C# program outputting False, inject a 'malicious' line of code such that the program outputs True. ...
Kendall Frey's user avatar
  • 2,473
4 votes
1 answer
345 views

Given an arbitrary contiguous range of positive integers, find the decomposition in the minimum number of sub-ranges of size L = 2^n, with the constraint that each range must be aligned, that is the ...
Lorenzo Pistone's user avatar
2 votes
2 answers
2k views

The class System.Globalization.EastAsianLunisolarCalendar of the mscorlib.dll assembly is non-nested ...
Jeppe Stig Nielsen's user avatar
24 votes
1 answer
2k views

I hope this kind of "riddle" is ontopic in Programming Puzzles & Code Golf. Give an example of a situation where the C# method below returns false: ...
Jeppe Stig Nielsen's user avatar
2 votes
1 answer
834 views

Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible. ...
istepaniuk's user avatar
11 votes
5 answers
3k views

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 ...
Bogdan Alexandru's user avatar
5 votes
3 answers
907 views

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 ...
Bogdan Alexandru's user avatar
27 votes
17 answers
4k views

This is the first of a series of C++ puzzles for you. Hope you will enjoy. So, puzzle no.1: Given the following program: ...
Bogdan Alexandru's user avatar
3 votes
2 answers
797 views

Background As described here http://www.ericharshbarger.org/dice/#gofirst_4d12, "Go First" Dice is a set of four dice, each with unique numbering, so that: There will never be a tie. Each die has a ...
i_desire_the_dice's user avatar
11 votes
2 answers
807 views

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); }
ugoren's user avatar
  • 17.6k
3 votes
13 answers
16k views

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 find ...
RHPT's user avatar
  • 149
6 votes
3 answers
672 views

Some time ago, I found this unused hash function (written in Java) in our codebase: ...
zneak's user avatar
  • 193