Skip to main content
Commonmark migration
Source Link

#Python 2, 113 bytes

Python 2, 113 bytes

r=range
lambda N:[n for n in r(1,N)if 1-any((bin(k).count('1')<3)*all((n^k)%q for q in r(2,n^k))for k in r(n+1))]

(The second line is an unnamed function which returns a list of all bitflip-resistant composite numbers which are less than the input to the function.)

The syntax all(u%q for q in range(2,u)) will evaluate to True whenever u is either prime or less than or equal to 2, and otherwise will evaluate to False. (It is vacuously True if u is less than or equal to 2.)

In other words, all(u%q for q in range(2,u)) is equal to 0 if and only if u is composite.

If the function's input is less than 2, then function returns an empty list (as desired). So assume the input N is at least 2, and suppose 1 <= n < N. For each k from 0 through n (inclusive), the code will check whether n XOR'd with k is composite, and it also checks whether k has at most two 1's in its binary representation. If n^k is composite, or if k has more than two 1's, then it moves on to the next value of k. If it gets through all the values of k from 0 through n this way, then it includes n in the list.

On the other hand, if there's a value of k with at most two 1's such that n^k is not composite, then n is not included in the list.

#Python 2, 113 bytes

r=range
lambda N:[n for n in r(1,N)if 1-any((bin(k).count('1')<3)*all((n^k)%q for q in r(2,n^k))for k in r(n+1))]

(The second line is an unnamed function which returns a list of all bitflip-resistant composite numbers which are less than the input to the function.)

The syntax all(u%q for q in range(2,u)) will evaluate to True whenever u is either prime or less than or equal to 2, and otherwise will evaluate to False. (It is vacuously True if u is less than or equal to 2.)

In other words, all(u%q for q in range(2,u)) is equal to 0 if and only if u is composite.

If the function's input is less than 2, then function returns an empty list (as desired). So assume the input N is at least 2, and suppose 1 <= n < N. For each k from 0 through n (inclusive), the code will check whether n XOR'd with k is composite, and it also checks whether k has at most two 1's in its binary representation. If n^k is composite, or if k has more than two 1's, then it moves on to the next value of k. If it gets through all the values of k from 0 through n this way, then it includes n in the list.

On the other hand, if there's a value of k with at most two 1's such that n^k is not composite, then n is not included in the list.

Python 2, 113 bytes

r=range
lambda N:[n for n in r(1,N)if 1-any((bin(k).count('1')<3)*all((n^k)%q for q in r(2,n^k))for k in r(n+1))]

(The second line is an unnamed function which returns a list of all bitflip-resistant composite numbers which are less than the input to the function.)

The syntax all(u%q for q in range(2,u)) will evaluate to True whenever u is either prime or less than or equal to 2, and otherwise will evaluate to False. (It is vacuously True if u is less than or equal to 2.)

In other words, all(u%q for q in range(2,u)) is equal to 0 if and only if u is composite.

If the function's input is less than 2, then function returns an empty list (as desired). So assume the input N is at least 2, and suppose 1 <= n < N. For each k from 0 through n (inclusive), the code will check whether n XOR'd with k is composite, and it also checks whether k has at most two 1's in its binary representation. If n^k is composite, or if k has more than two 1's, then it moves on to the next value of k. If it gets through all the values of k from 0 through n this way, then it includes n in the list.

On the other hand, if there's a value of k with at most two 1's such that n^k is not composite, then n is not included in the list.

Source Link
mathmandan
  • 1k
  • 11
  • 10

#Python 2, 113 bytes

r=range
lambda N:[n for n in r(1,N)if 1-any((bin(k).count('1')<3)*all((n^k)%q for q in r(2,n^k))for k in r(n+1))]

(The second line is an unnamed function which returns a list of all bitflip-resistant composite numbers which are less than the input to the function.)

The syntax all(u%q for q in range(2,u)) will evaluate to True whenever u is either prime or less than or equal to 2, and otherwise will evaluate to False. (It is vacuously True if u is less than or equal to 2.)

In other words, all(u%q for q in range(2,u)) is equal to 0 if and only if u is composite.

If the function's input is less than 2, then function returns an empty list (as desired). So assume the input N is at least 2, and suppose 1 <= n < N. For each k from 0 through n (inclusive), the code will check whether n XOR'd with k is composite, and it also checks whether k has at most two 1's in its binary representation. If n^k is composite, or if k has more than two 1's, then it moves on to the next value of k. If it gets through all the values of k from 0 through n this way, then it includes n in the list.

On the other hand, if there's a value of k with at most two 1's such that n^k is not composite, then n is not included in the list.