Skip to content

Commit c2cc33b

Browse files
mkubdevPanquesito7
andauthored
[docs/fix]: Update the list alphabetically + fix Searches folder ref. (#56)
* [doc]: update the algo list alphabetically + add new merged algo * [fix]: rename DynamicProgramming folder * chore: apply suggestions from code review Co-authored-by: David Leal <[email protected]>
1 parent b002077 commit c2cc33b

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

README.md

+37-31
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,44 @@ This is going to be used for our partnership with [Dev Protocol](https://devprot
3232

3333
Implementations are for learning purposes only. As they may be less secure than in real-world context, use them at your discretion.
3434

35-
## Lists of Algorithms-
35+
## Lists of Algorithms
3636

37-
* [Algorithms](./src)
38-
* [Maths](./src/Maths)
39-
* [Abs](./src/Maths/Abs.sol)
40-
* [AddArray](./src/Maths/AddArray.sol)
41-
* [AliquotSum](./src/Maths/AliquotSum.sol)
42-
* [Area](./src/Maths/Area.sol)
43-
* [Armstrong Number](./src/Maths/armstrongNumber.sol)
44-
* [Average Mean](./src/Maths/AverageMean.sol)
45-
* [Divide Digit](./src/Maths/divideDigit.sol)
46-
* [Exponentiation](./src/Maths/exponentiation.sol)
47-
* [Factorial](./src/Maths/factorial.sol)
48-
* [Fibonacci](./src/Maths/fibonacci.sol)
49-
* [Lucas Series](./src/Maths/lucasSeries.sol)
50-
* [Modulo](./src/Maths/modulo.sol)
51-
* [Multiply Array](./src/Maths/MulArray.sol)
52-
* [Multiply Digit](./src/Maths/multiplyDigit.sol)
53-
* [Percentage](./src/Maths/Percentage.sol)
54-
* [Perfect Square](./src/Maths/perfectSquare.sol)
55-
* [Sub Digit](./src/Maths/subDigit.sol)
56-
* [Sum Digit](./src/Maths/subDigit.sol)
57-
* [Volume](./src/Maths/volume.sol)
58-
* [Zellers Congruence Algorithm](./src/Maths/zellersCongruenceAlgorithm.sol)
59-
* [Searches](./src/Searchs)
60-
* [Binary Search](./src/Searches/BinarySearch.sol)
61-
* [Sorts](./src/Sorts)
62-
* [Bubble Sort](./src/Sorts/BubbleSort.sol)
63-
* [Quick Sort](./src/Sorts/QuickSort.sol)
64-
* [Selection Sort](./src/Sorts/SelectionSort.sol)
37+
- [Algorithms](./src)
38+
- [Maths](./src/Maths)
39+
- [Abs](./src/Maths/Abs.sol)
40+
- [AddArray](./src/Maths/AddArray.sol)
41+
- [AliquotSum](./src/Maths/AliquotSum.sol)
42+
- [Area](./src/Maths/Area.sol)
43+
- [Armstrong Number](./src/Maths/armstrongNumber.sol)
44+
- [Array Reversal](./src/Maths/ReverseArray.sol)
45+
- [Average Mean](./src/Maths/AverageMean.sol)
46+
- [BinaryExponentiation](./src/Maths/BinaryExponentiation.sol)
47+
- [Divide Digit](./src/Maths/divideDigit.sol)
48+
- [Exponentiation](./src/Maths/exponentiation.sol)
49+
- [Factorial](./src/Maths/factorial.sol)
50+
- [Fibonacci](./src/Maths/fibonacci.sol)
51+
- [Lucas Series](./src/Maths/lucasSeries.sol)
52+
- [Modulo](./src/Maths/modulo.sol)
53+
- [Multiply Array](./src/Maths/MulArray.sol)
54+
- [Multiply Digit](./src/Maths/multiplyDigit.sol)
55+
- [Percentage](./src/Maths/Percentage.sol)
56+
- [Perfect Square](./src/Maths/perfectSquare.sol)
57+
- [Sub Digit](./src/Maths/subDigit.sol)
58+
- [Sum Digit](./src/Maths/subDigit.sol)
59+
- [String Matching](./src/Maths/stringMatch.sol)
60+
- [Volume](./src/Maths/volume.sol)
61+
- [Zellers Congruence Algorithm](./src/Maths/zellersCongruenceAlgorithm.sol)
62+
- [Dynamic Programming](./src/DynamicProgramming)
63+
- [Knapsack](./src/DynamicProgramming/Knapsack.sol)
64+
- [Searches](./src/Searches)
65+
- [Binary Search](./src/Searches/BinarySearch.sol)
66+
- [Linear Search](./src/Searches/LinearSearch.sol)
67+
- [Sorts](./src/Sorts)
68+
- [Bubble Sort](./src/Sorts/BubbleSort.sol)
69+
- [Merge Sort](./src/Sorts/MergeSort.sol)
70+
- [Quick Sort](./src/Sorts/QuickSort.sol)
71+
- [Selection Sort](./src/Sorts/SelectionSort.sol)
6572

66-
67-
## Community Channels
73+
## Community Channels
6874

6975
We're on [Discord](https://discord.gg/c7MnfGFGa6) and [Gitter](https://gitter.im/TheAlgorithms)! Community channels are great for you to ask questions and get help. Please join us!

src/Maths/BinaryExponentiation.sol

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

4-
/// @title BinaryExponentiation
5-
/// @author https://github.com/xeno097
6-
/// @notice A contract that implements the binary exponentiation
7-
/// algorithm for unsigned integers.
8-
/// @dev This algorithm allows to efficiently calculate base**exp
9-
/// using the binary representation of exp.
10-
/// Every bit represents the square number of the previous one
11-
/// starting from base**1. The result is computed by multiplying
12-
/// the elements of the series where the nth bit of exp is 1.
13-
///
14-
/// Example:
15-
/// Compute 5**17
16-
///
17-
/// 17 in binary is 10001
18-
///
19-
/// 1st bit -> 5**1 = 5
20-
/// 2nd bit -> 5**2 = 25
21-
/// 3rd bit -> 5**4 = 625
22-
/// 4th bit -> 5**8 = 390625
23-
/// 5th bit -> 5**16 = 152587890625
24-
///
25-
/// Only the first and fifth bits are ones, so:
26-
/// 5**17 = 152587890625 * 5 = 762939453125
27-
///
4+
/**
5+
@title BinaryExponentiation
6+
@author [Sebastiano Faiella](https://github.com/xeno097)
7+
@notice A contract that implements the binary exponentiation
8+
algorithm for unsigned integers.
9+
@dev This algorithm allows to efficiently calculate base**exp
10+
using the binary representation of exp.
11+
Every bit represents the square number of the previous one
12+
starting from base**1. The result is computed by multiplying
13+
the elements of the series where the nth bit of exp is 1.
14+
15+
Example:
16+
Compute 5**17
17+
17 in binary is 10001
18+
1st bit -> 5**1 = 5
19+
2nd bit -> 5**2 = 25
20+
3rd bit -> 5**4 = 625
21+
4th bit -> 5**8 = 390625
22+
5th bit -> 5**16 = 152587890625
23+
Only the first and fifth bits are ones, so:
24+
5**17 = 152587890625 * 5 = 762939453125
25+
*/
2826
contract BinaryExponentiation {
29-
/// @notice Takes two unsigned integers and calculates the base to the power of exp.
30-
/// @param base the number which power must be calculated.
31-
/// @param exp the exponent used to calculate the base power.
32-
/// @return power the result of computing base to the power of exp.
27+
/**
28+
@notice Takes two unsigned integers and calculates the base to the power of exp.
29+
@param base the number which power must be calculated.
30+
@param exp the exponent used to calculate the base power.
31+
@return power the result of computing base to the power of exp.
32+
*/
3333
function pow(uint256 base, uint256 exp) public pure returns (uint256) {
3434
// Base case x**0 = 1
3535
uint256 result = 1;

0 commit comments

Comments
 (0)