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 2078 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

I've verified the last test case locally; it took 8 minutes and 48 seconds.

How it works

çD Main link. Argument: n (integer)
 D Decimal; yield A, the array of base 10 digits of n.
ç Call the second helper link with arguments n and A.
Ḥçßç? Second helper link. Left argument: n. Right argument: A.
Ḥ Unhalve; yield 2n.
 ? If...
 ç the first helper link called with 2n and A returns a non-zero integer:
 ç Return that integer.
 Else:
 ß Recursively call the second helper link with arguments 2n and A.
ÆRDFṡL}i First helper link. Left argument: k. Right argument: A.
ÆR Prime range; yield the array of all primes up to k.
 DF Convert each prime to base 10 and flatten the resulting nested array.
 L} Yield l, the length of A.
 ṡ Split the flattened array into overlapping slices of length l.
 i Find the 1-based index of A in the result (0 if not found).

Alternate version, 11 bytes (non-competing)

ÆRVw3
ḤÇßÇ?

The w atom did not exist when this challenge was posted. Try it online!

How it works

ḤÇßÇ? Main link. Argument: n (integer)
Ḥ Unhalve; yield 2n.
 ? If...
 Ç the helper link called with argument 2n returns a non-zero integer:
 Ç Return that integer.
 Else:
 ß Recursively call the main link with argument 2n.
ÆRVw3 Helper link. Argument: k (integer)
ÆR Prime range; yield the array of all primes up to k.
 V Eval; concatenate all primes, forming a single integer.
 3 Yield the first command-line argument (original value of n).
 w Windowed index of; find the 1-based index of the digits of the result to
 the right in the digits of the result to the left (0 if not found).

I've verified the last test case locally; it took 8 minutes and 48 seconds.

How it works

çD Main link. Argument: n (integer)
 D Decimal; yield A, the array of base 10 digits of n.
ç Call the second helper link with arguments n and A.
Ḥçßç? Second helper link. Left argument: n. Right argument: A.
Ḥ Unhalve; yield 2n.
 ? If...
 ç the first helper link called with 2n and A returns a non-zero integer:
 ç Return that integer.
 Else:
 ß Recursively call the second helper link with arguments 2n and A.
ÆRDFṡL}i First helper link. Left argument: k. Right argument: A.
ÆR Prime range; yield the array of all primes up to k.
 DF Convert each prime to base 10 and flatten the resulting nested array.
 L} Yield l, the length of A.
 ṡ Split the flattened array into overlapping slices of length l.
 i Find the 1-based index of A in the result (0 if not found).

Alternate version, 11 bytes (non-competing)

ÆRVw3
ḤÇßÇ?

The w atom did not exist when this challenge was posted. Try it online!

How it works

ḤÇßÇ? Main link. Argument: n (integer)
Ḥ Unhalve; yield 2n.
 ? If...
 Ç the helper link called with argument 2n returns a non-zero integer:
 Ç Return that integer.
 Else:
 ß Recursively call the main link with argument 2n.
ÆRVw3 Helper link. Argument: k (integer)
ÆR Prime range; yield the array of all primes up to k.
 V Eval; concatenate all primes, forming a single integer.
 3 Yield the first command-line argument (original value of n).
 w Windowed index of; find the 1-based index of the digits of the result to
 the right in the digits of the result to the left (0 if not found).
added 41 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 17 bytes

ÆRDFṡL}i
‘çßçḤçßç?
çD

Try it online! Returns the 1-based index. Try it online! or verify the smaller test cases verify most test cases.

Jelly, 17 bytes

ÆRDFṡL}i
‘çßç?
çD

Try it online! or verify the smaller test cases.

Jelly, 17 bytes

ÆRDFṡL}i
Ḥçßç?
çD

Returns the 1-based index. Try it online! or verify most test cases.

Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Jelly, 17 bytes

ÆRDFṡL}i
‘çßç?
çD

Try it online! or verify the smaller test cases.

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