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
21
votes
34answers
4k views

Do the circles overlap?

Given the coordinates of the centres and the radii of 2 circles, output a truthy value of whether they do or do not overlap. Input Input may be taken via STDIN or equivalent, function arguments, but ...
21
votes
23answers
2k views

Is my number a de Polignac number?

A number is a de Polignac number if and only if it is odd and cannot be represented in the form p + 2n where n is a non-negative integer and p is a prime integer. Task Write some code that takes a ...
21
votes
28answers
6k views

Find whether a number is happy or not?

A happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (...
21
votes
27answers
3k views

Visible Dice Faces

A traditional Western die is a cube, on which the integers 1 to 6 are marked on the faces. Pairs that add to 7 are placed on opposite faces. As it is cube, we can only see between 1 and 3 faces (...
21
votes
18answers
3k views

Is this a valid Takuzu board?

Takuzu is a logic game in which you have to complete a grid with cells containing 0s and 1s. The grid must follow 3 rules: No ...
21
votes
27answers
2k views

VEVO User Account Checker

We often see music videos on Youtube. Many Youtube channels that host music videos are "powered by VEVO". Those can be easily identified by both embedding VEVO at their video thumbnails and appending ...
21
votes
23answers
3k views

School moving out (Day 1)

Challenge Taken with permission from my University Code Challenge Contest For some years now, the number of students in my school has been growing steadily. First the number of students was increased ...
21
votes
20answers
5k views

Create a sudoku solution CHECKER

Create a Sudoku solution CHECKER There are oodles of Sudoku SOLVERS here, but I want you to create a solution CHECKER as small as humanly possible (code-golf). A valid entry will be able to either ...
21
votes
13answers
1k views

Is the matrix rank-one?

Given a matrix of integers, test if it's rank-one, meaning that every row is a multiple of the same vector. For example, in ...
21
votes
14answers
2k views

Is this a BST pre-order traversal?

Background A binary tree is a rooted tree whose every node has at most two children. A labelled binary tree is a binary tree whose every node is labelled with a positive integer; moreover, all ...
21
votes
13answers
4k views

Is this a straight flush?

Related: Name the poker hand A straight flush is a poker hand containing five cards of sequential rank, all of the same suit. As part of a straight flush, an ace can rank either above a king or ...
21
votes
21answers
2k views

Determine Superabundance

A superabundant number is an integer n that sets a new upper bound for its ratio with the divisor sum function σ. In other words, n is superabundant if and only if, for all positive integers x ...
21
votes
11answers
3k views

Is it a substring of itself?

Given a string, return whether the string is a substring of the program's source code. Standard quine rules apply, meaning you cannot read your own source code. The length of the input is guaranteed ...
21
votes
9answers
2k views

Is the group cyclic?

Introduction You can skip this part if you already know what a cyclic group is. A group is defined by a set and an associative binary operation $ (that is, ...
21
votes
5answers
768 views

Is my number Unique

In this challenge we learned a way to encode every positive integer using factor trees. Here is how it works: The empty string has value of 1. (S) where ...
21
votes
7answers
988 views

Is this a submatrix?

This is the 2-dimensional generalisation of this challenge. For our purposes, one matrix (or 2D array) A is considered a submatrix of another matrix B, if A can be obtained by completely removing a ...
21
votes
5answers
492 views

Congruent Numbers

Definitions: A triangle is considered a right triangle if one of the inner angles is exactly 90 degrees. A number is considered rational if it can be represented by a ratio of integers, i.e., ...
21
votes
3answers
1k views

2D Collision Detection

This challenge is based on actual collision detection I had to write for a simple game recently. Write a program or function which, given two objects, returns a truthy or falsy value depending on ...
21
votes
4answers
2k views

Determine if a polygon is convex

Write a program to determine if the input polygon is convex. The polygon is specified with one line containing N, the number of vertices, then N lines containing the x and y coordinates of each ...
21
votes
2answers
487 views

Are these trees isomorphic?

Introduction In this challenge, your task is to write a program that decides whether two given trees are isomorphic. A tree means a directed acyclic graph where every node has exactly one outgoing ...
20
votes
45answers
2k views

Determine if an Array contains something other than 2

Take an array which consists of numbers or arrays, output if it only contains 2s. Output should be a truthy or falsey value (Sorry if this destroys answers) ...
20
votes
33answers
3k views

Am I an Automorphic Number?

An Automorphic number is a number which is a suffix of its square in base 10. This is sequence A003226 in the OEIS. Your Task: Write a program or function to determine whether an input is an ...
20
votes
15answers
5k views

One line Keyboard

The Challenge The goal of this challenge is to determine whether a given String can be typed using only one line of a standard UK QWERTY keyboard. This is ...
20
votes
18answers
1k views

Does it repeat?

A string of characters repeats if it contains two consecutive substrings that are equivalent. For example, 2034384538452 repeats as it contains ...
20
votes
28answers
1k views

Are these identifiers equivalent?

In the language Nim, the rules for differentiating identifiers are slightly more relaxed than most other languages. Two identifiers are equivalent or address the same variable if they follow these ...
20
votes
18answers
2k views

Upper or Lower Wythoff?

First, let's talk about Beatty sequences. Given a positive irrational number r, we can construct an infinite sequence by multiplying the positive integers to r in order and taking the floor of each ...
20
votes
23answers
1k views

Are the lists divisible?

Inspired (with the explanation stolen from) this Background Say you have two lists A = [a_1, a_2, ..., a_n] and ...
20
votes
14answers
1k views

Is this a truncated triangular number?

Related OEIS sequence: A008867 Truncated triangular number A common property of triangular numbers is that they can be arranged in a triangle. For instance, take 21 and arrange into a triangle of <...
20
votes
15answers
1k views

Predict a Collision: Will the robber get away?

Think of a road as a number line, starting at 0 and continuing indefinitely: ...
20
votes
11answers
3k views

Can You Spell This Word With These Dice?

Letter dice are common in word games. It can be fun to try to spell funny words with boggle dice, for instance. If you grab a handful of dice, chances are you won't be able to spell certain words. ...
20
votes
16answers
998 views

Are there N consecutive occurrences of a number in a row/column in a matrix?

Take a matrix A consisting positive integers, and a single positive integer N as input, and determine if there are at least N consecutive occurrences of the same number in any row or column in the ...
20
votes
9answers
2k views

Is it within the Cantor set?

The Challenge For this challenge, you are supposed to determine if a given number is in the Cantor set. So first, let's define the Cantor set. First, start with the numbers between 0 and 1. Any ...
20
votes
10answers
2k views

Can maze be solved?

The puzzle Print 0 if a maze n*m can not be solved Print 1 if a maze n*m can be solved (in 1 or more ways) (so I'm not asking for paths but if it's possible to solve!!!) Input array(2d): ...
20
votes
10answers
2k views

Connect Four Validator

Introduction Connect Four is a game where you attempt to get four in a row: horizontally, vertically, or diagonally. In this code golf, we will be trying to find who won, given a game board. There ...
20
votes
7answers
924 views

Numpad Word Search

Given an integer from 1 to 999 inclusive, output a truthy value if it appears horizontally, vertically, or diagonally, either forwards or backwards, anywhere in the 3x3 square of digits 1-9 on a ...
20
votes
10answers
2k views

Bracket balancing

You will be given a (possibly empty) string containing brackets ([{()}]) and any other characters (A-...
19
votes
47answers
5k views

Determining Yes or No?

After inputting a string [length 1-20], only containing the chars y for yes and n for no, your program should output the result (y or n). Example input: yynynynny ...
19
votes
21answers
2k views

The repetitive byte counter

Your task is to write a non-empty program / function of byte count L, which, when repeated M times, checks whether a given positive integer N is equal to L × M. You should, in theory, support an ...
19
votes
15answers
2k views

Match Roman Numerals

Challenge Given some input string, return a truthy value if it represents a correct roman numeral between 1 (=I) and 3999 (=...
19
votes
13answers
1k views

Refined Partitions

Consider an array of integers: [1, 0, 9, 1, 3, 8] There are a lot of ways to partition this list into consecutive sublists. Here are three: ...
19
votes
21answers
3k views

Does it oscillate periodically?

Challenge Given a list, determine if grouping the list into runs of increasing and decreasing elements will result in a list of equal-sized lists. In other words, "turning points" of the list are ...
19
votes
12answers
2k views

Is the Matrix Positive-Definite?

Introduction Today we're gonna take care of the bane of first-year linear algebra students: matrix definiteness! Apparently this doesn't yet have a challenge so here we go: Input A \$n\times n\$ ...
19
votes
14answers
2k views

Is it a shuffle?

Yesterday I asked this question about riffle shuffles. It seems that yesterdays question was a bit too hard so this question is a related but much easier task. Today you are asked to determine if a ...
19
votes
13answers
2k views

Check if all non-zero elements in a matrix are connected

Input: A matrix containing integers in the range [0 - 9]. Challenge: Determine if all non-zero elements are connected to each other vertically and/or horizontally. Output: A truthy value if all ...
19
votes
11answers
2k views

Socket - Plug compatibility

Traveling with electronics is always fun, especially when you need an adapter to charge them. Your challenge is to make planning a trip a little easier by checking if a given plug will be compatible ...
19
votes
32answers
3k views

How fast am I vrooooming?

Introduction My car speedometer was hacked! Instead of showing me how fast i'm driving, it just shows: "Vroooom!" Please help me know how fast i'm going. Challenge Take a string as input, and check ...
19
votes
19answers
2k views

Detect Rectangular Text with Rectangular Code

Given a string of printable ASCII text (including newlines and spaces) that contains at least one character that is neither a newline nor a space, output a truthy value if the string is rectangular, ...
19
votes
9answers
2k views

Does this line pass through that square?

Divide the first quadrant (including the positive x-axis, the positive y-axis, and the origin) into 1x1 grids, with each grid labelled by the coordinates of its bottom-left corner, as demonstrated ...
19
votes
5answers
388 views

Modified Boggle Checker, with Modified Boggle-able Code

Background Boggle is a board game where the players have to find English words on a 4-by-4 board of random alphabets. Words can be constructed by selecting sequentially adjacent cells on the board. ("...
19
votes
7answers
1k views

Uh, is it a haiku?

So you want to create a haiku, but you're not sure if it follows the syllable rules for a haiku. I couldn't be bothered to write a proper blurb like I usually do, so you'll have to make do with this. ...