Add exponentiation by squaring in Dana#43
Merged
kostis merged 2 commits intokostis:masterfrom Feb 13, 2025
Merged
Conversation
Owner
|
Thanks for your contribution. Before it can be merged, please fix the following:
Please do these changes. |
Renamed the file to powint.dana. Removed prompts and now reads three inputs (base, exponent, mod). Prints only the result plus a newline, matching the style of powint.alan.
Contributor
Author
|
Thank you for the quick feedback! I’ve renamed the file to powint.dana and updated it to read three inputs (base, exponent, mod) without prompts, then print only the result plus a newline, just like powint.alan. Please let me know if there’s anything else I need to adjust. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The algorithm computes a power by reducing the exponent recursively: for even exponents, it halves the exponent, computes the result for that smaller exponent, and then squares it; for odd exponents, it multiplies the base by the result of the exponent decreased by one. The process continues until the exponent reaches zero, where the result is defined as one.