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

Commonmark migration
Source Link

##Actually, 19 bytes

Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index

##Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index

Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index
added 91 characters in body
Source Link
user45941
user45941

##Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index

##Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index

##Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index
Source Link
user45941
user45941

##Actually, 19 bytes

╗1`r♂Pεj╜@íu`;)╓i@ƒ

Takes a string as input and outputs the 1-based index of the substring

Try it online!

Explanation:

╗1`r♂Pεj╜@íu`;)╓i@ƒ
╗ push input to register 0
 `r♂Pεj╜@íu`;) push this function twice, moving one copy to the bottom of the stack:
 r♂Pεj concatenate primes from 0 to n-1 (inclusive)
 ╜@íu 1-based index of input, 0 if not found
1 ╓ find first value of n (starting from n = 0) where the function returns a truthy value
 i@ flatten the list and move the other copy of the function on top
 ƒ call the function again to get the 1-based index

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