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 Revisions

4 of 7
added 135 characters in body
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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...

Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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