From 577449f096b7953ff314cd097b7879f6a605e889 Mon Sep 17 00:00:00 2001 From: QueenLy <89299701+LyFromQixing@users.noreply.github.com> Date: Fri, 12 Nov 2021 21:57:52 +0700 Subject: [PATCH 1/2] Adding Pascal's triangular matrix algorithm --- algorithms/math/pascal_matrix.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 algorithms/math/pascal_matrix.py 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) From 2a44428cf5ccc80850cc194660c7779dcc0720a4 Mon Sep 17 00:00:00 2001 From: QueenLy <89299701+LyFromQixing@users.noreply.github.com> Date: Fri, 12 Nov 2021 22:11:57 +0700 Subject: [PATCH 2/2] Added Simple Hexadecimal Algorithm --- .../math/Addition_of_Two_Hexadecimal.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 algorithms/math/Addition_of_Two_Hexadecimal.py 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)