Skip to content

Add Digital Root algorithm to maths - #14988

Open
MeiSiristhebest wants to merge 2 commits into
TheAlgorithms:masterfrom
MeiSiristhebest:maths/digital_root
Open

Add Digital Root algorithm to maths#14988
MeiSiristhebest wants to merge 2 commits into
TheAlgorithms:masterfrom
MeiSiristhebest:maths/digital_root

Conversation

@MeiSiristhebest

Copy link
Copy Markdown

Description

Adds the Digital Root algorithm (maths/digital_root.py).

The digital root (repeated digital sum) of a non-negative integer is the single-digit value obtained by iteratively summing its decimal digits until only one digit remains. It complements the existing maths/sum_of_digits.py (single-pass digit sum) and is a classic number-theory / arithmetic routine.

Reference

Verification (local CI, matching repo config: Python 3.14, ruff, mypy, pytest)

  • ruff format --check : passed
  • ruff check : passed
  • mypy : passed (no issues)
  • pytest --doctest-modules : 1 passed (doctests cover 0, single digit, multi-digit, negative input, and a large number)

Checklist

  • Single algorithm per file, snake_case filename
  • Type hints + docstring + doctests present
  • Wikipedia reference linked
  • No duplicate of an existing implementation
  • DIRECTORY.md is auto-generated by the directory_writer workflow on push (not manually edited)

@algorithms-keeper algorithms-keeper Bot added the require descriptive names This PR needs descriptive function and/or variable names label Aug 1, 2026

@algorithms-keeper algorithms-keeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

Comment thread maths/digital_root.py Outdated
"""


def digital_root(n: int) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: n

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Aug 1, 2026
@algorithms-keeper algorithms-keeper Bot removed the require descriptive names This PR needs descriptive function and/or variable names label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants