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

added 86 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 1011 bytes

V+€J%ÞfÞ8ḢV+€J%ÞfÞẒƇḢ

A monadic Link that accepts a list of pairwise coprime integers and yields a run of the same number of consecutive composites.

Try it online! Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

V+€J%ÞfÞ8ḢV+€J%ÞfÞẒƇḢ - Link: Coprimes
V - Digit-smash {Coprimes}
 (e.g. [2, 11, 17] -> 21117 -- N.B. V >= Product+Max so is sufficient*)
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in:
 Coprimes Ƈ - {Comprimes} for which:
 Ẓ - is prime?
 Ḣ - head

* Thanks to Leo for this proof that the digit concatenation performed by V is guaranteed to be greater than or equal to the product plus the maximum that we may need to search through:

The concatenation \$a|b\$ of two positive numbers \$a\$ and \$b\$ is equal to \$a\times c + b\$, where \$c\$ is the first power of \10ドル\$ larger than \$b\$ (i.e. \$c = 10^{\lfloor 1 + \log_{10}{b} \rfloor}\$).

Since \$c \ge b + 1\$ we get \$a|b \ge a \times (b + 1) + b = a \times b + a + b\$.

As such the concatenation of two numbers is always at least as large as their product plus their sum. This then extends to more terms as each of the operations, concatenation and taking a product, may be applied in succession.

Jelly, 10 bytes

V+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of pairwise coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

V+€J%ÞfÞ8Ḣ - Link: Coprimes
V - Digit-smash {Coprimes}
 (e.g. [2, 11, 17] -> 21117 -- N.B. V >= Product+Max so is sufficient*)
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

* Thanks to Leo for this proof that the digit concatenation performed by V is guaranteed to be greater than or equal to the product plus the maximum that we may need to search through:

The concatenation \$a|b\$ of two positive numbers \$a\$ and \$b\$ is equal to \$a\times c + b\$, where \$c\$ is the first power of \10ドル\$ larger than \$b\$ (i.e. \$c = 10^{\lfloor 1 + \log_{10}{b} \rfloor}\$).

Since \$c \ge b + 1\$ we get \$a|b \ge a \times (b + 1) + b = a \times b + a + b\$.

As such the concatenation of two numbers is always at least as large as their product plus their sum. This then extends to more terms as each of the operations, concatenation and taking a product, may be applied in succession.

Jelly, 11 bytes

V+€J%ÞfÞẒƇḢ

A monadic Link that accepts a list of pairwise coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

V+€J%ÞfÞẒƇḢ - Link: Coprimes
V - Digit-smash {Coprimes}
 (e.g. [2, 11, 17] -> 21117 -- N.B. V >= Product+Max so is sufficient*)
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f - keep those which are in:
  Ƈ - {Comprimes} for which:
 Ẓ - is prime?
 Ḣ - head

* Thanks to Leo for this proof that the digit concatenation performed by V is guaranteed to be greater than or equal to the product plus the maximum that we may need to search through:

The concatenation \$a|b\$ of two positive numbers \$a\$ and \$b\$ is equal to \$a\times c + b\$, where \$c\$ is the first power of \10ドル\$ larger than \$b\$ (i.e. \$c = 10^{\lfloor 1 + \log_{10}{b} \rfloor}\$).

Since \$c \ge b + 1\$ we get \$a|b \ge a \times (b + 1) + b = a \times b + a + b\$.

As such the concatenation of two numbers is always at least as large as their product plus their sum. This then extends to more terms as each of the operations, concatenation and taking a product, may be applied in succession.

added 468 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, (10?)* 1110 bytes

PḤ+€J%ÞfÞ8ḢV+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of pairwise coprime integers and yields a run of the same number of consecutive composites.

Try it online! Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

PḤ+€J%ÞfÞ8ḢV+€J%ÞfÞ8Ḣ - Link: Coprimes
P V - productDigit-smash {Coprimes}
  - double (e.g. [2, 11, 17] -> 2P21117 (-- N.B. 2PV >= P+max(Coprimes)Product+Max so is sufficient*)
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

* Thanks to (10?) IfLeo for this proof that the digit concatenation of the decimal digits of any coprime list (e.g. [3, 5, 16] ->performed by 3516V) is guaranteed to be at leastgreater than or equal to the product of the coprimes plus itsthe maximum that we may need to search through:

The concatenation (e.g.\$a|b\$ of two positive numbers [3, 5, 16]\$a\$ and ->\$b\$ is equal to 3*5*16+16 = 256)\$a\times c + b\$, thenwhere PḤ could be replaced with\$c\$ is the first power of V\10ドル\$ larger than \$b\$ (i. Ie. think it\$c = 10^{\lfloor 1 + \log_{10}{b} \rfloor}\$).

Since \$c \ge b + 1\$ we get \$a|b \ge a \times (b + 1) + b = a \times b + a + b\$.

As such the concatenation of two numbers is always big enough but I'm not 100% sureat least as large as their product plus their sum. This then extends to more terms as each of the operations, concatenation and taking a product, may be applied in succession.

Jelly, (10?)* 11 bytes

PḤ+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

PḤ+€J%ÞfÞ8Ḣ - Link: Coprimes
P  - product {Coprimes}
  - double -> 2P (N.B. 2P >= P+max(Coprimes))
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

* (10?) If the concatenation of the decimal digits of any coprime list (e.g. [3, 5, 16] -> 3516) is guaranteed to be at least the product of the coprimes plus its maximum (e.g. [3, 5, 16] -> 3*5*16+16 = 256), then PḤ could be replaced with V. I think it is always big enough but I'm not 100% sure.

Jelly, 10 bytes

V+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of pairwise coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

V+€J%ÞfÞ8Ḣ - Link: Coprimes
V - Digit-smash {Coprimes}
 (e.g. [2, 11, 17] -> 21117 -- N.B. V >= Product+Max so is sufficient*)
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

* Thanks to Leo for this proof that the digit concatenation performed by V is guaranteed to be greater than or equal to the product plus the maximum that we may need to search through:

The concatenation \$a|b\$ of two positive numbers \$a\$ and \$b\$ is equal to \$a\times c + b\$, where \$c\$ is the first power of \10ドル\$ larger than \$b\$ (i.e. \$c = 10^{\lfloor 1 + \log_{10}{b} \rfloor}\$).

Since \$c \ge b + 1\$ we get \$a|b \ge a \times (b + 1) + b = a \times b + a + b\$.

As such the concatenation of two numbers is always at least as large as their product plus their sum. This then extends to more terms as each of the operations, concatenation and taking a product, may be applied in succession.

added 189 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, (10?)* 11 bytes

PḤ+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

PḤ+€J%ÞfÞ8Ḣ - Link: Coprimes
P - product {Coprimes}
 Ḥ - double -> 2P (N.B. 2P >= P+max(Coprimes))
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

Hmm maybe* (10?) If the concatenation of the decimal digits of any coprime list (e.g. PḤ[3, 5, 16] could be -> V3516) is guaranteed to be at least the product of the coprimes plus its maximum (effectively concatenate all digits of Coprimes to make an integere.g. [3, 5, 16] -> 3*5*16+16 = 256), then PḤ could be replaced with V. I think it is always big enough.. but I'm not 100% sure.

Jelly, 11 bytes

PḤ+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

PḤ+€J%ÞfÞ8Ḣ - Link: Coprimes
P - product {Coprimes}
 Ḥ - double -> 2P (N.B. 2P >= P+max(Coprimes))
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

Hmm maybe PḤ could be V (effectively concatenate all digits of Coprimes to make an integer), I think it is always big enough...

Jelly, (10?)* 11 bytes

PḤ+€J%ÞfÞ8Ḣ

A monadic Link that accepts a list of coprime integers and yields a run of the same number of consecutive composites.

Try it online!

How?

Uses the Chinese Remainder theorem in the most naive way possible, systematic search.

PḤ+€J%ÞfÞ8Ḣ - Link: Coprimes
P - product {Coprimes}
 Ḥ - double -> 2P (N.B. 2P >= P+max(Coprimes))
 J - 1-indexed indices {Coprimes} -> [1..n=length(Coprimes)]
 € - for each {v in [1..2P]}:
 + - {v} add {[1..n]} (vectorises)
 Þ - sort by:
 % - modulo {Coprimes} (vectorises)
 Þ - sort by:
 f 8 - keep those which are in Coprimes
 Ḣ - head

* (10?) If the concatenation of the decimal digits of any coprime list (e.g. [3, 5, 16] -> 3516) is guaranteed to be at least the product of the coprimes plus its maximum (e.g. [3, 5, 16] -> 3*5*16+16 = 256), then PḤ could be replaced with V. I think it is always big enough but I'm not 100% sure.

added 135 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
deleted 73 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
added 89 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading

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