-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday21.sol
47 lines (39 loc) · 956 Bytes
/
day21.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
contract Day3 {
// first solutiion
// function hcf(uint256 num1, uint256 num2)
// public
// pure
// returns(uint256)
// {
// // Everything divides 0
// if (num1 == 0 && num2 == 0){
// return 0;
// }
// if (num1 == 0){
// return num2;
// }
// if (num2 == 0){
// return num1;
// }
// // Base case
// if (num1 == num2){
// return num1;
// }
// // num1 is greater
// if (num1 > num2){
// return hcf(num1 - num2, num2);
// }
// return hcf(num1, num2 - num1);
// }
// better solution
function hcf(uint256 num1, uint256 num2)
public
pure
returns(uint256){
if (num2 == 0)
return num1;
return hcf(num2, num1 % num2);
}
}