Skip to main content

Questions tagged [open-ended-function]

For challenges where an exact output is not required but some property must still be fulfilled.

Filter by
Sorted by
Tagged with
24 votes
6 answers
3k views

Objective Compute \$\pi\$ using nothing but \$i\$ (\$\sqrt{-1}\$). Guidelines ONLY exponentiation and multiplication may be used (i.e. \$i^i\$ or \$ii\$) No additional symbols may be used (so no ...
WarpPrime's user avatar
  • 521
8 votes
18 answers
1k views

Output any 500 different valid Roman numerals in the range 1 to 3999, in uppercase. Code golf.
Steve Bennett's user avatar
11 votes
5 answers
856 views

Write a function \$f\$ which takes rational numbers and gives binary fractions (rational numbers whose denominator is a power of two) which is bijective and preserves order. That means: Different ...
Wheat Wizard's user avatar
  • 103k
-5 votes
7 answers
490 views

It's 2025! Write a function/program that outputs this number in words. There are two twists: You can write it out in (almost) any human language (including English). None of the characters in your ...
Steve Bennett's user avatar
10 votes
2 answers
521 views

Write a function/program that generates an aesthetically pleasing square cryptic crossword grid for a given size N. You do not need to include numbers. The rules for aesthetically pleasing are: The ...
Steve Bennett's user avatar
6 votes
3 answers
651 views

Each of a regular dodecahedron's 12 faces can be painted either red or blue. Your task is to implement a function \$f\$ that takes a painted dodecahedron (as 12 booleans, in whatever order and format ...
Karl's user avatar
  • 871
4 votes
3 answers
519 views

I'm using a language "MutFk" where the basic operators like "+" and "*" actually modify the left hand side of the expression, and also return the modified version. For ...
mousetail's user avatar
  • 14.4k
14 votes
7 answers
942 views

Implement a function \$f\$ that takes 10 boolean inputs and returns a boolean. The only requirement on \$f\$ is that it satisfies the identity $$ f(x_1,x_2,x_3,x_4,x_5,x_6,x_7,x_8,x_9,x_{10})=f(x_2,...
Karl's user avatar
  • 871
33 votes
26 answers
9k views

Recently (okay, December 2023, I'm a little late) there's been a meme going around about a program checking if a 32-bit unsigned integer is even or odd using four billion if statements: ...
emanresu A's user avatar
  • 46.2k
9 votes
10 answers
2k views

Exposition You send secret information to 100 of your friends, and the next day you discover that the information has been published! Who could have revealed it? To determine that, you number your ...
anatolyg's user avatar
  • 14.2k
8 votes
12 answers
3k views

I decided to create a complete guide to the great game of tic-tac-toe. I expected it to be extremely popular, so to save on paper while printing it I decided to encode all possible game positions. I ...
talex's user avatar
  • 927
0 votes
4 answers
339 views

A monad is a type that wraps another type, that represents the available operations on the wrapped type. Monads have the following associated operations, where M is ...
bigyihsuan's user avatar
  • 11.5k
9 votes
3 answers
301 views

Let a context-free language be specified by its production rules and start symbol, e.g. S -> AbB | C C -> b | c B -> AA | AC A -> a | ε Here and in the ...
Parcly Taxel's user avatar
  • 4,749
6 votes
1 answer
461 views

Input: A positive integer n such that n is even and greater than 12 or n is odd and greater ...
Lucenaposition's user avatar
11 votes
4 answers
2k views

Follow-up of my previous challenge, inspired by @emanresu A's question, and proven possible by @att (Mathematica solution linked) For the purposes of this challenge, a 1-2-3-5-7... sequence is an ...
Tbw's user avatar
  • 3,053
22 votes
15 answers
2k views

For the purposes of this challenge, a 1-2-3 sequence is an infinite sequence of increasing positive integers such that for any positive integer \$n\$, exactly one of \$n, 2n,\$ and \$3n\$ appears in ...
Tbw's user avatar
  • 3,053
12 votes
7 answers
2k views

A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. For those who are not aware of how knights in chess work, knights are capable of ...
totallyhuman's user avatar
  • 17.4k
21 votes
9 answers
1k views

In this challenge, an infinitely proportional sequence is defined as a infinite sequence of positive integers such that: All positive integers are contained infinitely many times within the sequence. ...
emanresu A's user avatar
  • 46.2k
17 votes
12 answers
1k views

Your task is to write 2 functions/programs. They may share code. The first function must, given a string and a character, output a new string that does not contain that character. The second function ...
mousetail's user avatar
  • 14.4k
8 votes
0 answers
272 views

This was originally a pure mathematics question, but I think I've got the best chance for an answer here. The Challenge For concreteness, consider Peano Arithmetic (PA). For some language L of your ...
Charles Wang's user avatar
11 votes
9 answers
2k views

An even distribution number is a number such that if you select any of it's digits at random the probability of it being any particular value (e.g. 0 or ...
Wheat Wizard's user avatar
  • 103k
16 votes
3 answers
568 views

The way points are assigned on a dice follows a regular pattern, the center dot is present if and only if the number is odd. To represent the even numbers, pairs of dots on opposite sides of the ...
bsoelch's user avatar
  • 6,095
21 votes
23 answers
4k views

Related You are a manager at a large number factory. You want to show everyone your business is doing well, by showing randomly chosen samples. Unfortunately, your business is not doing that well. But ...
The Empty String Photographer's user avatar
17 votes
5 answers
886 views

In this challenge, we consider an encoding from positive integers (up to a limit) to binary sequences. Some examples: ...
Bubbler's user avatar
  • 79.3k
13 votes
9 answers
3k views

Recently I asked for tips on improving some code-golf of mine. The code was supposed to output every third value of the Fibonacci sequence starting with 2: ...
Wheat Wizard's user avatar
  • 103k
13 votes
8 answers
783 views

A followup to this challenge by Jeremy Collprav, inspired by DLosc solving this in Regenerate. Some sections copied from the linked challenge. Linking chains We define a chain to be a string ...
caird coinheringaahing's user avatar
13 votes
5 answers
3k views

Background An interesting way to solve a Sudoku puzzle is to represent it as a Boolean satisfiability problem, and then feed it to a SAT solver. A Boolean Satisfiability Problem (abbreviated as SAT ...
alephalpha's user avatar
  • 51.9k
14 votes
10 answers
1k views

Given a list, L, of sets of numbers like this: [[1], [0,2,3], [3,1], [1,2,3]] Output a single list of numbers such that 2 ...
mousetail's user avatar
  • 14.4k
24 votes
5 answers
3k views

The problem statement here is pretty simple, take two real numbers on the range [0,1) as input and output their sum, with probability 1. The catch here is that there are a lot of real numbers. There ...
Wheat Wizard's user avatar
  • 103k
12 votes
7 answers
883 views

(Inspired by this challenge.) Given six real values in three pairs: \$(x_1, x_2), (y_1, y_2),\$ and \$(x_0, y_0)\$, where \$x_1 < x_0 < x_2\$ and \$y_1 < y_0 < y_2\$, create a function ...
97.100.97.109's user avatar
0 votes
6 answers
534 views

Your function must accept three numbers in any order: A signed real number (or ±Infinity) - The number (N) for which you have ...
EzioMercer's user avatar
  • 1,472
13 votes
14 answers
795 views

Given a permutation, we can define its high-water marks as the indices in which its cumulative maximum increases, or, equivalently, indices with values bigger than all previous values. For example, ...
Command Master's user avatar
8 votes
3 answers
446 views

It can be easily proven using Hall's marriage theorem that given fixed \$n\$ and \$k<n/2\$, there is an injective (one-to-one) function from all \$n\$-bit strings with \$k\$ ones to \$n\$-bit ...
Parcly Taxel's user avatar
  • 4,749
13 votes
6 answers
1k views

Every odd degree polynomial has at least one real root. However this root does not have to be a rational number so your task is to output a sequence of rational numbers that approximates it. Rules ...
AndrovT's user avatar
  • 2,824
20 votes
9 answers
1k views

proposed by @Adám in chat Given an even number of finite points return a line \$y=mx+b\$ that evenly splits the points on both sides. Specs Take a list of distinct points \$(x,y)\$ (or a list of x-...
math scat's user avatar
  • 9,538
22 votes
17 answers
3k views

In this challenge you will be tasked with implementing a sequence of natural numbers such that: Each number appears a natural number of times No two numbers appear the same number of times No two ...
Wheat Wizard's user avatar
  • 103k
8 votes
4 answers
497 views

Write a function that takes an ASCII-printable-only (all charcodes ∈ [32..126]) string input x and provides an ASCII-printable-only output string ...
l4m2's user avatar
  • 32.7k
5 votes
2 answers
401 views

Last time you were required to write program that output a file, such that no byte is same as original file. The request meant to let everyone carry part of information, but it ends up that everyone ...
l4m2's user avatar
  • 32.7k
20 votes
10 answers
2k views

The cardinality of the set \$\mathbb Q\$ of rational numbers is known to be exactly the same as that of the set \$\mathbb Z\$ of integers. This means that it is possible to construct a bijection ...
att's user avatar
  • 22.8k
4 votes
1 answer
226 views

Given an integer \$n > 1\$, output a balanced binary tree with \$n\$ leaf nodes. The tree should be constructed out of (space), ...
97.100.97.109's user avatar
7 votes
9 answers
421 views

A partition of a list \$A\$ is a way of splitting \$A\$ up into smaller parts, concretely it is list of lists that when concatenated gives back \$A\$. For example ...
Wheat Wizard's user avatar
  • 103k
21 votes
11 answers
2k views

I recently stumbled across this image on wikimedia commons. It's a little bit of an information overload at first, but after examining it a bit it shows an interesting number system for writing ...
Wheat Wizard's user avatar
  • 103k
29 votes
20 answers
4k views

Write a program or function that takes a character as input and outputs a character. Also, choose a list of 13 distinct ASCII printable characters (32-126). When a character from this list is passed ...
Jiří's user avatar
  • 1,925
7 votes
5 answers
406 views

Generate \$T=\{T_1,...,T_x\}\$, the minimum number of \$k\$-length subsets of \$\{1,...,n\}\$ such that every \$v\$-length subset of \$\{1,...,n\}\$ is a subset of some set in \$T\$ Here, \$n > k &...
2FaceMan's user avatar
  • 179
23 votes
26 answers
2k views

Given a string \$ x \$, we say another string \$ y \$ is half of it, if both of the following properties are true: \$ y \$ is a (not necessarily continuous) subsequence of \$ x \$ - there exists a ...
Command Master's user avatar
2 votes
0 answers
52 views

Find a bijective function which maps integers to arbitrarily large tuples of integers. Given the input \$n\$, output the tuple it matches to. Edit: The empty tuple is included in the mapping.
dancxviii's user avatar
  • 193
17 votes
15 answers
1k views

In set theory, a set is an unordered group of unique elements. A pure set is either the empty set \$\{\}\$ or a set containing only pure sets, like \$\{\{\},\{\{\}\}\}\$. Your challenge is to write a ...
emanresu A's user avatar
  • 46.2k
22 votes
26 answers
3k views

Let \$Z\$ be either the integers, the positive integers, or the non-zero integers; pick whatever's convenient. Give two functions \$f\$ and \$g\$, each \$Z \to Z\$, such that: \$f(g(a)) = g(f(a))\$, ...
cjquines's user avatar
  • 1,391
17 votes
16 answers
2k views

Recently a friend of mine posed the following: What subset of the integers satisfies the condition if distinct a and b are in the subset, their average is not in the subset? I know the set of non-0 ...
Caelus's user avatar
  • 533
14 votes
3 answers
916 views

The brilliant engineers at <enter company you love to hate> have struck again. This time they've "revolutionised" the generation of random permutations. "Every great invention is ...
loopy walt's user avatar
  • 16.9k