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
2 votes
3 answers
57 views

Incomparable partitions [closed]

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 ...
  • 90.5k
18 votes
10 answers
2k views

Create a nibble shorthand

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 ...
  • 90.5k
24 votes
18 answers
3k views

Transform characters of your choice into "Hello, world!"

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 ...
  • 1,475
7 votes
4 answers
274 views

Generate number set with conditions using n numbers

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 &...
  • 179
21 votes
24 answers
2k views

Generate an arbitrary half of a string

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 ...
2 votes
0 answers
45 views

Bijective Function (mapping integer to arbitrarily large integer tuple) [duplicate]

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.
  • 193
17 votes
13 answers
1k views

Enumerate all pure sets

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 ...
20 votes
25 answers
3k views

Give f and g that sometimes commute

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))\$, ...
  • 1,231
16 votes
15 answers
1k views

Average-ignorant sets of integers

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 ...
  • 513
14 votes
3 answers
844 views

Sniff out biased random permutations

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 ...
  • 9,418
18 votes
9 answers
2k views

Is it irrational?

Your task is to make a program that decides if a real number between 0 and 1 is irrational or not. As stated, this is obviously impossible, so instead we will use the following definition: ...
  • 6,775
15 votes
3 answers
356 views

What was my Wordle play?

Task Given a winning Wordle play results (clues), the target ("secret") word and a list of words, output a possible sequence of words leading to such results. The words in the list will be ...
  • 12.4k
36 votes
48 answers
3k views

Output a random unary string

Your task is simple: output the letter x a random number of times. Every possible length of xs must have a non-zero probability ...
  • 22.6k
12 votes
8 answers
802 views

All sequences as substrings

Make a program that outputs a sequence of integers so that every finite sequence of positive integers is a substring (continuous subsequence) of the output. For example, the following sequence ...
  • 6,775
15 votes
4 answers
538 views

Output a Steiner quadruple system

A Steiner quadruple system \$SQS(n)\$ is a collection of subsets (blocks) of size 4 of a set \$S\$ of size \$n\$ such that every subset of \$S\$ of size 3 is in exactly one block. It is easy to show ...
  • 1,023
3 votes
7 answers
652 views

Don't output the file

This rar file, when decompressed, gives a 65024-byte exe file. Requiring you to output the contents of that file would be ...
  • 13k
16 votes
4 answers
578 views

Probability breaking sequences

If we have a finite list of elements we can determine the probability of any one element being drawn at random as the number of times it occurs divided by the total number of elements in the list. For ...
  • 90.5k
9 votes
8 answers
551 views

Biggest katlani noun dictionary in 400 bytes

Katlani is a constructed language being designed in chat. In this challenge, your goal is to print the largest dictionary of katlani nouns possible in 400 bytes or less. Task In 400 bytes or less, ...
13 votes
8 answers
576 views

Compress and decompress

Your task is to make a bidirectional compressor. It takes a list of bytes as input and returns a list of bytes as output. It has the property than whenever it is iterated twice it returns the original ...
  • 6,775
34 votes
18 answers
3k views

Egyptian fraction representations of 1

An Egyptian fraction is a representation of a rational number using the sum of distinct unit fractions (a unit fraction is of the form \$ \frac 1 x \$ where \$ x \$ is a positive integer). For all[1] ...
  • 22.6k
7 votes
1 answer
231 views

Busy beaver in a coin

\$BB\$ is the busy beaver function, an uncomputable function. Write a program which when given an integer \$n\$ as input, will output \$BB(n)\$, with at least \$\frac 2 3\$ probability. You can do ...
  • 13k
21 votes
13 answers
2k views

Output every sublist ... eventually

You will be given as input an infinite stream of positive integers. Your task is to write a program which outputs an infinite sequence of lists with two requirements: All lists in the output are ...
  • 90.5k
18 votes
8 answers
855 views

Make every fixed list

We are to define the idea of a fixed list as follows: A fixed list is a list of fixed lists. This definition is recursive so it's useful to look at some examples. The empty list ...
  • 90.5k
18 votes
20 answers
1k views

Generate a regular graph

Inspired by this Mathematica.SE post Given two positive integers \$n, k\$ with \$n > k \ge 1\$, output a binary \$n\times n\$ matrix such that every row and column contains exactly \$k\$ 1s, and ...
16 votes
15 answers
1k views

Encode integers with some others

Input a non-empty array of positive (greater than 0) integers. Output another non-empty array of positive integers which encode the input array. Output array does not use any numbers used in the input ...
  • 30.8k
25 votes
20 answers
973 views

Kolmogorov-simple numbers

If you visit Code Golf often, you may have heard of Kolmogorov complexity. It's usually defined as the amount of bytes required to express some string in a programming language. Here the Kolmogorov-...
  • 6,775
28 votes
11 answers
2k views

Infinite ordinals from a well-ordering

Your task is to write a short program that represents a large (infinite) ordinal, using a well-ordering of the set of positive integers. Your program will take two different positive integers and ...
  • 6,775
15 votes
3 answers
253 views

Bijection between \$ \mathbb N \$ and at-most-\$n\$-ary trees

Background Related: a golflang theory I posted in TNB a while ago At-most-\$n\$-ary trees are rooted trees where each internal node has between 1 and \$n\$ children (inclusive). Two trees are ...
  • 66.2k
10 votes
0 answers
159 views

NP-complete reduction: (grid-)Hamiltonian circuit

Background Hamiltonian circuit problem is a decision problem which asks whether a given graph has a Hamiltonian circuit, i.e. a cycle that visits every vertex exactly once. This problem is one of the ...
  • 66.2k
27 votes
17 answers
3k views

Give me odd, even, square, cube, prime and composite 3-digit numbers

Given a string which is guaranteed to be either odd, even, square, ...
  • 171k
10 votes
4 answers
296 views

Venn of \$n\$ statements

Given a positive integer \$n\$, output \$n\$ 2D bool images with the same width and height such that: Each image should be 4-connected, i.e. for each two pixels that are true, you can start from one ...
  • 13k
9 votes
8 answers
768 views

Encode a Lenguage

The Len(language,encoding) family of languages is a variety of Lenguage derivatives. To encode a program into a Len language, you replace every character with its representation in a certain encoding, ...
19 votes
1 answer
597 views

Demonstrate some advanced abstract algebra

Consider a binary operator \$*\$ that operates on a set \$S\$. For simplicity's sake, we'll assume that \$*\$ is closed, meaning that its inputs and outputs are always members of \$S\$. This means ...
10 votes
5 answers
425 views

Rewrite strings without changing their order

Lexicographic Ordering For this challenge we will be talking about the lexicographic ordering of strings. If you know how to put words in alphabetical order you already understand the basic idea of ...
  • 90.5k
16 votes
11 answers
2k views

Generate a mantis's head (symmetrical triangle)

Given guaranteed strictly positive integers \$w\$ and \$n\$, output An equilateral triangle array with side length \$w\$, filled with two distinct, consistent values. I'll call these ...
  • 1,450
25 votes
10 answers
2k views

Floor of complex number

Background Complex floor is a domain extension of the mathematical floor function for complex numbers. This is used in some APL languages to implement floor , ...
  • 66.2k
17 votes
3 answers
607 views

Compute the uncomputable ... sort of

Implement a function \$f\$ (as a function or complete program), such that \$ \displaystyle\lim_{n\rightarrow \infty} f(n) \$ converges to a number which is not a computable number. Answers will be ...
  • 90.5k
40 votes
67 answers
5k views

Infinitely many ℕ

Background: A sequence of infinite naturals is a sequence that contains every natural number infinitely many times. To clarify, every number must be printed multiple times! The Challenge: Output a ...
10 votes
14 answers
501 views

Golf a bijection \$\mathbb{N}^n\to\mathbb{N}\$

Your task is to write a program which implements a bijection \$\mathbb{N}^n\to\mathbb{N}\$ for \$n \ge 1\$. Your program should take \$n\$ natural numbers as input, in any acceptable method (including ...
41 votes
21 answers
2k views

Three other numbers

Given three distinct numbers from \$1\$ to \$7\$, output three other distinct numbers from \$1\$ to \$7\$, that is having no numbers in common with the original numbers. Your code must produce a ...
  • 139k
17 votes
11 answers
2k views

Shortest total non-primitive recursive function

Natural numbers ≡ \$\mathbb{N}≡\{0,1,2,...\}\$ The submission can be either a program or a function, both cases will henceforth be referred to as "function". The task is to golf the shortest ...
  • 12.9k
20 votes
10 answers
3k views

An unknowably odd function

This challenge initially appeared in this challenge as a an extra brain teaser. I am posting it with permission from the original author so that we can have a formal competition. Your task here ...
  • 90.5k
15 votes
7 answers
1k views

As close to flat as possible

Write a program or function that fulfills the following Scores less than 101 bytes under normal code-golf rules Takes no input1 and always outputs a single integer. Every integer is a possible output....
  • 90.5k
17 votes
7 answers
2k views

Define the finite field GF(9)

\$GF(9)\$ or \$GF(3^2)\$ is the smallest finite field whose order isn't a prime or a power of two. Finite fields of prime order aren't particurlarly interesting and there are already challenges for \$...
  • 10.5k
18 votes
8 answers
1k views

Surjection from one string to two strings

This is the inverse of negative seven's question. Write a program or function which, given any single, possibly-empty string of printable ASCII (codes \$[32,126]\$) outputs or returns two strings of ...
14 votes
28 answers
2k views

Injection from two strings to one string

Challenge Write a program that applies an injective function which takes an ordered pair of strings as input and one string as output. In other words, each input must map to a unique output. ...
25 votes
7 answers
2k views

Walk Across a Keyboard

Given a word (or any sequence of letters) as input, you must interpolate between each letter such that each adjacent pair of letters in the result is also adjacent on a QWERTY keyboard, as if you ...
  • 589
26 votes
6 answers
5k views

Golf a number bigger than Loader's number

As a follow up to Shortest terminating program whose output size exceeds Graham's number and Golf a number bigger than TREE(3), I present a new challenge. Loader's number is a very large number, ...
  • 7,079
18 votes
7 answers
2k views

Hilbert's binary Hotel

In this challenge you will be asked to implement any function (or full program) that fulfills two properties. Those properties are: Your function must be an injective (reversible) function from the ...
  • 90.5k
15 votes
2 answers
297 views

Program an Uncircularness Score

Your task is to program a mathematical function \$s\$, that takes a nonempty finite set \$A\$ of points in the 2D plane, and outputs an uncircularity score \$s(A)\$ that satisfies following properties:...
  • 43.2k