Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Post History

50%
+0 −0
Sandbox Substring factor [FINALIZED]

posted 6mo ago by trichoplax‭  ·  edited 6mo ago by trichoplax‭

#4: Post edited by user avatar trichoplax‭ · 2024-07-07T01:02:55Z (6 months ago)
Mark as finalized
  • Substring factor
  • Substring factor [FINALIZED]
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with only a subsequence factor
  • Input: `253`
  • Output: `false`
  • The input has a ***subsequence*** 23, and 23 is a factor of 253, but 23 is not a ***substring*** (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • # Now posted: [Substring factor](https://codegolf.codidact.com/posts/291939)
  • ---
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a factor that is a strict substring of its base 10 (decimal) representation.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with only a subsequence factor
  • Input: `253`
  • Output: `false`
  • The input has a ***subsequence*** 23, and 23 is a factor of 253, but 23 is not a ***substring*** (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#3: Post edited by user avatar trichoplax‭ · 2024-07-06T17:46:06Z (6 months ago)
Emphasise difference between subsequence and substring
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with only a subsequence factor
  • Input: `253`
  • Output: `false`
  • The input has a subsequence 23, and 23 is a factor of 253, but 23 is not a substring (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with only a subsequence factor
  • Input: `253`
  • Output: `false`
  • The input has a ***subsequence*** 23, and 23 is a factor of 253, but 23 is not a ***substring*** (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#2: Post edited by user avatar trichoplax‭ · 2024-07-06T02:45:49Z (6 months ago)
Clarify example heading
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with a subsequence but not a substring
  • Input: `253`
  • Output: `false`
  • The input has a subsequence 23, and 23 is a factor of 253, but 23 is not a substring (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
  • Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?
  • ## Input
  • - A positive integer.
  • ## Output
  • - One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
  • - Only strict substrings count - a string does not count as a strict substring of itself.
  • - A substring must be contiguous, unlike a subsequence.
  • - The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
  • - Zero is not a factor of any number.
  • ## Examples
  • ### Example with a single digit input
  • Input: `4`
  • Output: `false`
  • A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).
  • ### Example with a substring factor
  • Input: `370`
  • Output: `true`
  • The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).
  • ### Example with only a subsequence factor
  • Input: `253`
  • Output: `false`
  • The input has a subsequence 23, and 23 is a factor of 253, but 23 is not a substring (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.
  • ### Example with a composite factor
  • Input: `44`
  • Output: `true`
  • The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.
  • ### Example with 1 as a factor
  • Input: `31`
  • Output: `true`
  • The input has a substring 1, and 1 is a factor of 31.
  • ## Test cases
  • - Test cases are in the format `input : output`.
  • - You may use any 2 distinct values in place of `true` and `false`.
  • ```text
  • 4 : false
  • 31 : true
  • 44 : true
  • 253 : false
  • 370 : true
  • 123456 : true
  • 345678 : true
  • 456789 : false
  • 300007 : false
  • 700003 : false
  • 672297 : true
  • 828477 : true
  • 836537 : true
  • 963833 : true
  • 4506337 : true
  • 5480778 : true
  • 6355037 : true
  • 23278699 : true
  • 22222223 : false
  • ```
  • ## Scoring
  • This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.
  • > Explanations are optional, but I'm more likely to upvote answers that have one.
  • [code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"
#1: Initial revision by user avatar trichoplax‭ · 2024-07-06T02:36:27Z (6 months ago)
Substring factor
Does a positive integer have a [substring](https://en.wikipedia.org/wiki/Substring) as a factor?

## Input
- A positive integer.

## Output
- One of 2 distinct values to indicate whether the input has a strict substring of its base 10 (decimal) representation as a factor.
- Only strict substrings count - a string does not count as a strict substring of itself.
- A substring must be contiguous, unlike a subsequence.
- The factor does not need to be a prime factor - any divisor will do, including a composite factor or 1.
- Zero is not a factor of any number.

## Examples
### Example with a single digit input
Input: `4`

Output: `false`

A single digit integer has no non-empty strict substrings, so the output for any single digit input will be `false` (or whichever value you choose to consistently represent this).

### Example with a substring factor
Input: `370`

Output: `true`

The input has a substring 37, and 37 is a factor of 370 (that is, 370 can be divided by 37 with no remainder).

### Example with a subsequence but not a substring
Input: `253`

Output: `false`

The input has a subsequence 23, and 23 is a factor of 253, but 23 is not a substring (that is, not a contiguous subsequence), so this does not count. None of the substrings of 253 is a factor of 253.

### Example with a composite factor
Input: `44`

Output: `true`

The input has a substring 4, and 4 is a factor of 44. Factors do not need to be prime.

### Example with 1 as a factor
Input: `31`

Output: `true`

The input has a substring 1, and 1 is a factor of 31.

## Test cases
- Test cases are in the format `input : output`.
- You may use any 2 distinct values in place of `true` and `false`.

```text
4 : false
31 : true
44 : true
253 : false
370 : true
123456 : true
345678 : true
456789 : false
300007 : false
700003 : false
672297 : true
828477 : true
836537 : true
963833 : true
4506337 : true
5480778 : true
6355037 : true
23278699 : true
22222223 : false
```

## Scoring
This is a [code golf challenge]. Your score is the number of bytes in your code. Lowest score for each language wins.

> Explanations are optional, but I'm more likely to upvote answers that have one.


[code golf challenge]: https://codegolf.codidact.com/categories/49/tags/4274 "The code-golf tag"