Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 15 characters in body
Source Link
H.PWiz
  • 11.7k
  • 2
  • 23
  • 57

Regex (ECMAScript), 29 bytes

^(?!(xx+|(x(x))+)(1円3円)+$)xxx

Try it online!

Inspired by Grimy in chat

The regex asserts that the input is greater than 3, and that it is neither of the form: (xx+)1円+ or ((xx)+)(1円x)+.

The first matches composite numbers greater than 3.
The second matches a number that is 1 less than a multiple of some odd number greater than 2.

The first will not match prime numbers, or 0 or 1.
The second will not match numbers of the form \2ドル^n-1\$, or numbers that are 1 less than an odd prime.

Since 2 is the only prime that is 1 less than an odd prime, the negative lookahead, together with the assertion that the input is greater than 3, will match only mersenne primes.

Regex (ECMAScript), 29 bytes

^(?!(xx+|(x(x))+)(1円3円)+$)xxx

Try it online!

Inspired by Grimy in chat

The regex asserts that the input is greater than 3, and that it is neither of the form: (xx+)1円+ or ((xx)+)(1円x)+.

The first matches composite numbers greater than 3.
The second matches a number that is 1 less than a multiple of some odd number greater than 2.

The first will not match prime numbers, or 0 or 1.
The second will not match numbers of the form \2ドル^n-1\$, or numbers that are 1 less than an odd prime.

Since 2 is the only prime that is 1 less than an odd prime, the negative lookahead, together with the assertion that the input is greater than 3, will match only mersenne primes.

Regex (ECMAScript), 29 bytes

^(?!(xx+|(x(x))+)(1円3円)+$)xxx

Try it online!

Inspired by Grimy in chat

The regex asserts that the input is greater than 3, and that it is neither of the form: (xx+)1円+ or ((xx)+)(1円x)+.

The first matches composite numbers.
The second matches a number that is 1 less than a multiple of some odd number greater than 2.

The first will not match prime numbers, or 0 or 1.
The second will not match numbers of the form \2ドル^n-1\$, or numbers that are 1 less than an odd prime.

Since 2 is the only prime that is 1 less than an odd prime, the negative lookahead, together with the assertion that the input is greater than 3, will match only mersenne primes.

Source Link
H.PWiz
  • 11.7k
  • 2
  • 23
  • 57

Regex (ECMAScript), 29 bytes

^(?!(xx+|(x(x))+)(1円3円)+$)xxx

Try it online!

Inspired by Grimy in chat

The regex asserts that the input is greater than 3, and that it is neither of the form: (xx+)1円+ or ((xx)+)(1円x)+.

The first matches composite numbers greater than 3.
The second matches a number that is 1 less than a multiple of some odd number greater than 2.

The first will not match prime numbers, or 0 or 1.
The second will not match numbers of the form \2ドル^n-1\$, or numbers that are 1 less than an odd prime.

Since 2 is the only prime that is 1 less than an odd prime, the negative lookahead, together with the assertion that the input is greater than 3, will match only mersenne primes.

AltStyle によって変換されたページ (->オリジナル) /