Skip to main content
improved formatting
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Sisyphus's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Sisyphus's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Sisyphus's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

corrected answer reference
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Bubbler's@Sisyphus's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Bubbler's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Sisyphus's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

added 531 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Bubbler's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Bubbler's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Charcoal, 35 bytes

Nθ≔X²⁻Xθ³θηW∨﹪Π…¹θθ﹪÷Xηθ⊖η⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code. Uses @xnor's formulas (see @Bubbler's answer), so slow for large inputs (seems to be OK up to \$ b = 27 \$ at least). Explanation:

Nθ

Input \$ n \$, which is initially equal to \$ b \$.

≔X²⁻Xθ³θη

Calculate \$ 2 ^ { b (b - 1) (b + 1) } \$ which is used in @xnor's GCD calculation.

W∨

While either...

﹪Π…¹θθ

... \$ n \$ does not divide \$ (n - 1)! \$, meaning that \$ n \$ is 4 or prime, or...

﹪÷Xηθ⊖η⊖X²θ

... \$ 2 ^ n - 1 \$ does not divide \$ \left \lfloor \frac { 2 ^ { n b (b - 1) (b + 1) } } { 2 ^ { b (b - 1) (b + 1) } - 1 } \right \rfloor \$, meaning that \$ n \$ is not coprime to all of \$ b - 1 \$, \$ b \$ and \$ b + 1 \$, ...

≦⊕θ

... increment \$ n \$.

Iθ

Output the final value of \$ n \$.

Much faster 38-byte version which performs separate coprimaility testing on \$ b - 1 \$, \$ b \$ and \$ b + 1 \$:

Nθ≔E³X²⊖⁺θιηW∨﹪Π…¹θθ⊙η﹪÷Xκθ⊖κ⊖X²θ≦⊕θIθ

Try it online! Link is to verbose version of code.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281
Loading