Questions tagged [decision-problem]
For challenges which involve deciding whether or not the input meets certain criteria, and outputting some data, representing that decision.
719
questions
371
votes
1
answer
116k
views
Regex that only matches itself
There are some pretty cool challenges out there involving regex (Self-matching regex, Regex validating regex)
This may well be impossible, but is there a regex that will ONLY match itself?
NOTE, ...
231
votes
344
answers
61k
views
Is this number a prime?
Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in ...
162
votes
19
answers
28k
views
Is My Swipe Pattern Legal?
Most Android smartphones allow the user to use a swipe pattern to open their phone:
Certain patterns are legitimate, and others are impossible. Given an input swipe pattern, return a truthy or falsy ...
155
votes
1
answer
7k
views
"KNOT" or "NOT"?
Write a program that processes an ASCII art representation of a tangled string and decides whether or not it can be untangled into a simple loop. The tangle is represented using the characters ...
116
votes
76
answers
28k
views
I'm a palindrome. Are you?
There have been a couple of previous attempts to ask this question, but neither conforms to modern standards on this site. Per discussion on Meta, I'm reposting it in a way that allows for fair ...
100
votes
115
answers
16k
views
Will it halt? (Cops)
This is the cops' thread. The robbers' thread is here.
Your challenge is to make a program that runs forever without halting1, unless it gets a particular input or inputs2. If it receives that input, ...
96
votes
35
answers
7k
views
Would this string work as string?
Write a program that takes a single line string that you can assume will only contain the characters /\_‾. (That's forward and backward slash, underline and ...
91
votes
158
answers
13k
views
Determine whether strings are anagrams
Challenge
Given two strings, work out if they both have exactly the same characters in them.
Example
Input
word, wrdo
This returns true because they are the ...
86
votes
58
answers
13k
views
Detect MS Windows
Challenge
Create a program that returns a truthy value when run on Microsoft Windows (for simplicity we'll stick with Windows 7, 8.1 and 10) and a falsey value when run on any other operating system (...
85
votes
105
answers
13k
views
Count of "a"s and "b"s must be equal. Did you get it computer?
In the popular (and essential) computer science book, An Introduction to Formal Languages and Automata by Peter Linz, the following formal language is frequently stated:
$$\large{L=\{a^n b^n:n\in\...
78
votes
252
answers
24k
views
Is this even or odd?
Note: There is not been a vanilla parity test challenge yet (There is a C/C++ one but that disallows the ability to use languages other than C/C++, and other non-vanilla ones are mostly closed too), ...
78
votes
39
answers
12k
views
Am I a Rude Number?
For a while now, I've been running into a problem when counting on my fingers, specifically, that I can only count to ten. My solution to that problem has been to count in binary on my fingers, ...
77
votes
94
answers
16k
views
Golf all the 16 logic gates with 2 inputs and 1 output!
For example, the gate A and B is a logic gate with 2 inputs and 1 output.
There are exactly 16 of them, because:
each logic gate takes two inputs, which can be ...
77
votes
38
answers
12k
views
Non-discriminating Programming
We say a string is non-discriminating if each of the string's characters appears the same number of times and at least twice.
Examples
"aa!1 1 !a !1" is non-...
77
votes
58
answers
8k
views
Is it a Cyclops number? "Nobody" knows!
Task:
Given an integer input, figure out whether or not it is a Cyclops Number.
What is a Cyclops number, you may ask? Well, it's a number whose binary representation only has one ...
76
votes
65
answers
14k
views
Is this relationship creepy?
According to this XKCD comic, there is a formula to determine whether or not the age gap in a relationship is "creepy". This formula is defined as:
(Age/2) + 7
...
72
votes
47
answers
6k
views
Check if words are isomorphs
Two words are isomorphs if they have the same pattern of letter repetitions. For example, both ESTATE and DUELED have pattern <...
71
votes
47
answers
9k
views
Magic the Gathering: Friends or Foes?
In the card game Magic: the Gathering there are five different colours, which represent loose affiliations of cards, White (W), Blue (...
71
votes
93
answers
7k
views
Is the number binary-heavy?
An integer is binary-heavy if its binary representation contains more 1s than 0s while ignoring leading zeroes. For example 1 is ...
68
votes
7
answers
6k
views
Regex Golf: Verify a Sudoku Solution
Write a regex which matches any valid sudoku solution and doesn't match any invalid sudoku solution. The input is an unrolled version of the sudoku, i.e. there are no line delimiters. E.g. the ...
67
votes
43
answers
5k
views
Write the shortest self-identifying program (a quine variant)
Write a program that will generate a "true" output iff the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the ...
66
votes
11
answers
3k
views
Only Even Bytes
The scenario
Lately you have been noticing some strange behavior with your favorite text editor. At first it seemed that it was ignoring random characters in your code when writing to disk. After a ...
60
votes
43
answers
7k
views
Are the brackets fully matched?
You must write a program or function that takes a string of brackets and outputs whether or not that string is fully matched. Your program should print a truthy or falsy value, and IO can be in any ...
59
votes
9
answers
8k
views
Is my prison secure?
Your challenge is given an input of a prison layout to work out whether any of the prisoners can escape.
Input
Input may be in any reasonable format such as a string, array, array of arrays etc. The ...
59
votes
18
answers
4k
views
There are two new sheriffs in town – Identifying DJMcMego pairs!
We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go.
Here's something that has caught my attention ...
58
votes
62
answers
8k
views
Is this number an integer power of -2?
There are clever ways of determining whether a number is a power of 2. That's no longer an interesting problem, so let's determine whether a given integer is an integer power of -2. For example:
<...
58
votes
49
answers
5k
views
Is it a lipogram?
A lipogram is a block of words that omits a particular symbol. Right now, I am avoiding our fifth symbol of 26 that commonly show up. You should know by now what I am omitting. If not, look up "...
57
votes
76
answers
8k
views
Test a number for narcissism
A Narcissistic Number is a number which is the sum of its own digits, each raised to the power of the number of digits.
For example, take \$153\$ (3 digits):
\$1^3 + 5^3 + 3^3 = 153\$
\$1634\$:
\$1^...
57
votes
68
answers
11k
views
Am I a Fibonacci Number?
Your Task:
Write a program or function to check if a number that is inputted is a Fibonacci number. A Fibonacci number is a number contained in the Fibonacci sequence.
The Fibonacci Sequence is ...
56
votes
53
answers
5k
views
Is this a function?
Given a list of (key, value) pairs, determine whether it represents a function, meaning that each key maps to a consistent value. In other words, whenever two ...
55
votes
63
answers
8k
views
Is this string a square?
A string is considered to be square if the following conditions are met:
Each line has the same number of characters
The number of characters on each line is equal to the number of lines.
Your task ...
55
votes
31
answers
9k
views
Check if computer is connected to the internet
Write a program which, according to whether the script has access to the internet, produces an output which is "Truthy/Falsey". You may try and connect to any existing site, at your own discretion (...
55
votes
22
answers
3k
views
Dennis numbers 2.0
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!
This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off ...
54
votes
49
answers
14k
views
Is my OS 32-bit or 64-bit?
It's not too important anymore, but occasionally somebody needs to know.
Here is a simple golf: Taking no user input, tell me if the computer on which the code is run is on a 64-bit operating system, ...
54
votes
32
answers
4k
views
Does it Lead or Follow?
In this challenge you are to write a program or function, that takes a string as input and outputs one of two possible values. We will call one of these values truthy and one falsy. They do not need ...
53
votes
11
answers
3k
views
Surrounded Countries
Countries own a series of territories on a 1D world. Each country is uniquely identified by a number. Ownership of the territories can be represented by a list as follows:
...
53
votes
15
answers
4k
views
Tasteless and other bugs
Some versions of the standard Android calculator app allow you to press a key, like 'sin' and then the 'del' key to make it 'si'. Probably just a bug which they can't be bothered with removing.
The ...
52
votes
94
answers
11k
views
Is it double speak?
In an earlier challenge I asked code golfers to produce strings which copy each character in a string. For example:
TThhiiss iiss ddoouubbllee ssppeeaakk!!
This ...
52
votes
123
answers
18k
views
Is this number evil?
Introduction
In number theory, a number is considered evil if there are an even number of 1's in its binary representation. In today's challenge, you will be identifying whether or not a given number ...
52
votes
17
answers
5k
views
Code (Mini) Golf
Given a side-view of a mini-golf course and the power of the swing, determine if the ball will make it into the hole.
A course will be in this format:
...
51
votes
94
answers
7k
views
Is it a pangram?
Write a function or program that takes as its input a string and prints a truthy value if the string is a pangram (a sequence of letters containing at least one of each letter in the English alphabet) ...
51
votes
79
answers
7k
views
It's Hip to be Square
Challenge
So, um, it seems that, while we have plenty of challenges that work with square numbers or numbers of other shapes, we don't have one that simply asks:
Given an integer ...
51
votes
80
answers
9k
views
Do n and n^3 have the same set of digits?
Given a number n (0 <= n <= 2642245), check if n and n3 have the same set of digits, and output a truthy or falsey value accordingly.
For example, let's check the number 100.
1003 is 1000000.
...
51
votes
18
answers
5k
views
Can my 4-note music box play that song?
I have a crank-operated music box that can play a series of four notes. When I turn the crank, it plucks one of four strings, depending on the position of the crank and the direction of the turn. When ...
50
votes
80
answers
10k
views
Is my triangle right?
Given a, b, c the length of the three sides of a triangle, say if the triangle is right-angled (i.e. has one angle equal to 90 degrees) or not.
Input
Three positive ...
50
votes
6
answers
6k
views
Your car only turns right!
Introduction
You have the misfortune of being stuck in a runaway car on an obstacle course. All of the car's features are non-responsive, save for the steering system, which is damaged. It can ...
49
votes
90
answers
8k
views
Is this number a factorial?
The Task
Given a natural number as input, your task is to output a truthy or falsey value based on whether the input is a factorial of any natural number. You can assume that the input number will ...
49
votes
70
answers
6k
views
An abundance of integers!
An Abundant number is any number where the sum of its proper divisors is greater than the original number. For example, the proper divisors of 12 are:
...
49
votes
46
answers
5k
views
Detect heat waves
Background
The Royal Netherlands Meteorological Institute defines a heat wave* as a series of at least 5 consecutive days of ≥25°C weather (“summery weather”), such that at least 3 of ...
49
votes
15
answers
10k
views
Is this Tic-Tac-Toe board valid?
Challenge
Given a tic-tac-toe board in any format, determine if it is valid or not. If a board can be the result of a tic-tac-toe game, then it is valid. For example, this board is valid:X O X
O X O
...