Add Self-Dividing Numbers algorithm in R #215
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a comprehensive and well-documented implementation of the Self-Dividing Numbers problem in R, featuring efficient digit extraction and divisibility checking.
A self-dividing number is a number that is divisible by every digit it contains and does not contain the digit
0
(since division by zero is undefined).The algorithm efficiently examines each number in a given range by extracting its digits and validating divisibility.
Features
%
) and division (/
)0
or iforiginal_number %% digit != 0
TRUE
only if all digits divide the number evenlyis_self_dividing_number()
— Checks an individual numberself_dividing_numbers()
— Finds all self-dividing numbers in range[left, right]
self_dividing_numbers_vectorized()
— Vectorized version for improved performanceanalyze_number_digits()
— Debug helper for visualizing digit breakdownmathematics
moduleComplexity
O(m × log₁₀(n))
where
m = right - left + 1
, andlog₁₀(n)
is the number of digits in each number.O(m)
— for storing the result list.Directory
DIRECTORY.md
Added
"Self Dividing Numbers"
entry under MathematicsDemonstration
Run the script to execute built-in examples and validations:
PowerShell
Rscript "mathematics/self_dividing_numbers.r"