Questions tagged [decision-problem]

For challenges which involve deciding whether or not the input meets certain criteria, and outputting some data, representing that decision.

Filter by
Sorted by
Tagged with
368 votes
1 answer
115k 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, ...
user avatar
227 votes
336 answers
58k 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 ...
user avatar
  • 207k
162 votes
19 answers
27k 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 ...
user avatar
  • 1,161
150 votes
1 answer
5k 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 ...
user avatar
  • 19.6k
115 votes
70 answers
27k 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 ...
user avatar
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, ...
user avatar
95 votes
34 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 ...
user avatar
85 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 (...
user avatar
  • 1,878
82 votes
99 answers
12k 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: mainly because this language ...
user avatar
78 votes
250 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), ...
user avatar
  • 5,281
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, ...
user avatar
  • 6,889
76 votes
37 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-...
user avatar
  • 25.1k
74 votes
63 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 ...
user avatar
  • 1,276
73 votes
47 answers
5k 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 <...
user avatar
  • 137k
72 votes
86 answers
15k 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 ...
user avatar
  • 48.3k
72 votes
49 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 ...
user avatar
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 (...
user avatar
67 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 ...
user avatar
66 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 ...
user avatar
  • 28.5k
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 ...
user avatar
  • 88.8k
63 votes
81 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 ...
user avatar
  • 11.2k
60 votes
43 answers
6k 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 ...
user avatar
  • 57.3k
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 ...
user avatar
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 ...
user avatar
  • 41.4k
56 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^...
user avatar
  • 2,498
56 votes
51 answers
4k 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 ...
user avatar
  • 137k
55 votes
31 answers
8k 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 (...
user avatar
  • 603
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 ...
user avatar
  • 57.3k
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, ...
user avatar
  • 3,583
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 ...
user avatar
  • 88.8k
53 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 ...
user avatar
  • 11.1k
53 votes
57 answers
7k 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: <...
user avatar
  • 5,681
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: ...
user avatar
  • 11.8k
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 ...
user avatar
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: ...
user avatar
  • 11.1k
51 votes
45 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 "...
user avatar
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. ...
user avatar
  • 10.3k
51 votes
62 answers
10k 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 ...
user avatar
  • 6,889
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 ...
user avatar
  • 3,682
50 votes
118 answers
17k 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 ...
user avatar
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 ...
user avatar
  • 2,793
50 votes
73 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 ...
user avatar
  • 35.5k
49 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 ...
user avatar
  • 1,165
48 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 ...
user avatar
  • 4,928
48 votes
88 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) ...
user avatar
  • 7,149
48 votes
53 answers
7k 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 ...
user avatar
  • 8,865
48 votes
45 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 ...
user avatar
  • 66k
48 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 ...
user avatar
47 votes
144 answers
13k views

Will it halt? (Robbers)

This is the robbers' thread. The cops' thread is here. Your challenge is to crack a cop's submission by finding an input that makes it halt. You don't have to find out why, or all inputs that make it ...
user avatar
47 votes
8 answers
5k views

Determine if a coin system is Canonical

The Cashier's Algorithm is an algorithm for making change in the minimal number of coins that works quite well for most currency systems. However like most greedy algorithms it is not without its ...
user avatar
  • 88.8k

1
2 3 4 5
14