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.
43 questions
5
votes
2
answers
546
views
2^N different words with N characters matching a regex of the form [ab][cd] [closed]
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 ...
12
votes
3
answers
1k
views
Point-free JavaScript: write a function runner
In this programming-puzzle, your goal is to write the following function in JavaScript, using (essentially) point-free (tacit) programming:
(f) => void(f())
...
8
votes
1
answer
562
views
Self-referencing tuple in python
Goal: create a self-referencing tuple satisfying x == (x,) in any version of Python. Standard libraries, matplotlib, numpy, pandas only.
Answers meeting this extra ...
9
votes
2
answers
435
views
Setting up Al's R session
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,...
3
votes
2
answers
521
views
Print this text in Scala
Print the following text and nothing else:
...
11
votes
1
answer
274
views
Circumvent this credentials validator
This is a program I wrote in JavaScript to validate some inputted credentials, with an intentional vulnerability. The credentials_validator function takes an object ...
1
vote
2
answers
621
views
Hash bomb filtrate
Pipe a short stream to the following Java program run with accompanying command line options, such that it prints true.
...
2
votes
1
answer
206
views
Shooting gallery Puzzle!
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 ...
4
votes
0
answers
131
views
Generating edge cases in programming puzzles [closed]
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
...
6
votes
1
answer
439
views
Make Plan 9 Cat Turing Complete in as Few Bytes as Possible [closed]
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) ...
4
votes
3
answers
2k
views
A nasty little memory leak
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 ...
3
votes
2
answers
360
views
Algorithm to print the Minimum number of adjacent character swaps necessary to remove all instances of "VK" in a given string?
For example, how many adjacent swaps are at least needed to convert some string such as BVVKCV to one without any instances of VK...
1
vote
2
answers
328
views
Map an array of functions to their return values in point-free style
Introduction
I have some JavaScript code that uses Array.prototype.map to map an array of functions fns to their return values:
...
1
vote
0
answers
184
views
Rewrite the Tiny BASIC IL program to support 7 changes to BASIC [closed]
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 ...
13
votes
5
answers
1k
views
Add comments to a Python script and make it a bilingual Python/C++ “program”
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 ...
11
votes
4
answers
1k
views
C# is the Main problem
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 ...
1
vote
1
answer
232
views
Hiding elements with CSS only [closed]
In the following markup without changing it or using JS, implement the behavior to show only the ul element of div which name is ...
21
votes
2
answers
2k
views
A little bool magic
Challenge
Given the following C# method:
...
26
votes
11
answers
2k
views
Official Dyalog APL 2016 Year Game
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". ...
15
votes
2
answers
914
views
Befunge Brain Teasers
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. ...
8
votes
1
answer
647
views
The Swift Make-It-Compile Challenge #4 [closed]
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 ...
5
votes
0
answers
717
views
C# program containing `? null :` that is still valid without `null` [closed]
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 ...
9
votes
7
answers
2k
views
Non-idempotent Python [closed]
Write a few lines of Python code, X, that does not reference any global variables, such that
...
8
votes
0
answers
896
views
Tricky interview puzzle: get longest sequence by flipping 1 bit [closed]
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 ...
-1
votes
2
answers
508
views
Make the function comparing two variables with different value print True [closed]
Without changing the actual function, call it in such a way that it prints "True"
...
3
votes
0
answers
275
views
Minimum number of coins to get -closest- to target value? [closed]
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 ...
32
votes
22
answers
3k
views
Create an object whose state changes on assignment
I find it deeply weird that this is possible in Ruby (I won't immediately say how):
...
19
votes
6
answers
2k
views
reach catch when everything in the try block is caught already
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 ...
104
votes
159
answers
17k
views
Execute prints backwards
Your task is to reverse the order in which some prints get executed.
Specs:
Your code will be in this form:
...
4
votes
1
answer
3k
views
Match strings whose length is isolated prime [closed]
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 ...
3
votes
10
answers
4k
views
Can you cancel the stackoverflow exception in the following code? [closed]
The following code will produce a run-time error, stackoverflow exception.
...
16
votes
6
answers
7k
views
Code Injection works in C# too!
Given the following C# program outputting False, inject a 'malicious' line of code such that the program outputs True.
...
4
votes
1
answer
345
views
Decompose a range in aligned blocks of size 2^n [closed]
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 ...
2
votes
2
answers
2k
views
Inherit from class with inaccessible abstract members and all constructors inaccessible
The class System.Globalization.EastAsianLunisolarCalendar of the mscorlib.dll assembly is non-nested ...
24
votes
1
answer
2k
views
When is a giraffe not a giraffe? [closed]
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:
...
2
votes
1
answer
834
views
Write the implementation to pass this test
Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible.
...
11
votes
5
answers
3k
views
m3ph1st0s's programming puzzle 3 (C): “Easy bug” [closed]
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 ...
5
votes
3
answers
907
views
m3ph1st0s's programming puzzle 2 (C++): "Call hard!" [closed]
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 ...
27
votes
17
answers
4k
views
m3ph1st0s's programming puzzle 1 (C++) [closed]
This is the first of a series of C++ puzzles for you. Hope you will enjoy.
So, puzzle no.1:
Given the following program:
...
3
votes
2
answers
797
views
Generate N number of "Go First" dice [closed]
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 ...
11
votes
2
answers
807
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);
}
3
votes
13
answers
16k
views
Count the number of times a function runs [closed]
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 ...
6
votes
3
answers
672
views
Break the broken hash [closed]
Some time ago, I found this unused hash function (written in Java) in our codebase:
...