Skip to content

Add exponentiation by squaring in Dana#43

Merged
kostis merged 2 commits intokostis:masterfrom
orestis42:patch-1
Feb 13, 2025
Merged

Add exponentiation by squaring in Dana#43
kostis merged 2 commits intokostis:masterfrom
orestis42:patch-1

Conversation

@orestis42
Copy link
Contributor

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.

@kostis
Copy link
Owner

kostis commented Feb 12, 2025

Thanks for your contribution.

Before it can be merged, please fix the following:

  1. Note that file names of Dana programs should end in .dana
  2. If you look at the other languages (e.g. Alan), you will see that it contains a similar program powint.alan that reads its three inputs without prompts and also contains sample inputs and output for it. You are not aware of this detail yet, but it will simplify the testing if similar programs of different languages have similar names and take their inputs uniformly and produce the exact same output.

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.
@orestis42
Copy link
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.

@kostis kostis merged commit d8cf356 into kostis:master Feb 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants