diff --git a/algorithms/math/Addition_of_Two_Hexadecimal.py b/algorithms/math/Addition_of_Two_Hexadecimal.py new file mode 100644 index 0000000..743151f --- /dev/null +++ b/algorithms/math/Addition_of_Two_Hexadecimal.py @@ -0,0 +1,24 @@ +# Credit : LyFromQixing a.k.a QueenLy +# Date : 12 November 2021 +# Description : A program that accepts two hexadecimal digits of exactly two digits long, performs an addition, and writes the result in two hexadecimal digits + +hex_char = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"] + +def hex_to_dec(string): + idx = 0 + while (hex_char[idx] != string[0]): + idx += 1 + result = idx*16 + idx = 0 + while (hex_char[idx] != string[1]): + idx += 1 + result += idx + return result + +def dec_to_hex(x): + return hex_char[x//16] + hex_char[x%16] + +A = input("Insert A: ") +B = input("Insert B: ") +hex_result = dec_to_hex(hex_to_dec(A) + hex_to_dec(B)) +print(A, "+", B, "=", hex_result) diff --git a/algorithms/math/pascal_matrix.py b/algorithms/math/pascal_matrix.py new file mode 100644 index 0000000..b4a4efa --- /dev/null +++ b/algorithms/math/pascal_matrix.py @@ -0,0 +1,21 @@ +# Credit : LyFromQixing a.k.a QueenLy +# Date : 12 November 2021 +# Description : A program that accepts N input and writes a Pascal's triangular matrix of size N*N. + +def pascal_matrix(N): + + # Creating Pascal's Triangular Matrix + matrix = [[1 for i in range(N)] for j in range(N)] + for i in range(1, N): + for j in range(1, N): + matrix[i][j] = (matrix[i-1][j] + matrix[i][j-1]) + + # Showing matrix + for i in range(N): + print() + for j in range(N): + print(matrix[i][j], end=" ") + +N = int(input("Insert N: ")) + +pascal_matrix(N)