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 squares satisfies the condition, but I wonder if there exists a more... dense set that satisfies the condition.
(It turns out my friend was wrong about "the set of non-0 squares satisfies the condition", just ignore that.)
Now, I thought I could turn this into a coding challenge.
The goal of this challenge is to submit a function \$f: \mathbb{N} \to \{\top, \bot\}\$ which takes in a positive integer and returns a boolean satisfying the conditions in the "Rules" section.
Your score is the length of your program in bytes. Program \$A\$ is better than program \$B\$ if \$A\$ is shorter than \$B\$.
Rules
- For any distinct \$a, b\$ so that \$f(a)\$ is true, \$f(b)\$ is true and \$a+b\$ is even, then \$f(\frac{a+b}{2})\$ is false.
- Let \$e: \mathbb{N} \to \mathbb{N}\$ be defined as \$e(x) = \text{the } x^{\text{th}} \text{ number so that } f(x) \text{ is true}\$. Then, there exists some \$m\$ so that \$e(n) < n^2\$ for all \$n \geq m\$.
- The set \$\{a: f(a) \text{ is true}\}\$ is infinite, i.e. you can't make \$f\$ hold for only finitely many values.
Leaderboard
- allxy - 4 bytes (Jelly)
- Neil - 6 bytes (Charcoal)
- m90 - 10 bytes (x86 32-bit machine code)
- m90 - 12 bytes (Re:direction)
- Dominic van Essen - 15 bytes (BQN)
- knomologs - 20 bytes (МК-52/МК-61)
- alephalpha - 22 bytes (PARI/GP)
- chunes - 23 bytes (Factor +
math.unicode
) (tied with #8) - G B - 23 bytes (Ruby) (tied with #7)
- Neil - 26 bytes (Retina 0.8.2)
- Arnauld - 28 bytes (JavaScript ES6)
- loopy walt - 31 bytes (Python 2)
- loopy walt - 33 bytes (Python)
- solid.py - 50 bytes (Python 3.6)
- friddo - 68 bytes (Python 3.8)
- Kevin Cruijssen - 110 bytes (Whitespace)