From 3f060e55ccefd38a64332067de8e2364bf1a5e89 Mon Sep 17 00:00:00 2001 From: Ateng Date: Sun, 11 Oct 2026 10:25:55 +0700 Subject: [PATCH 1/6] feat: menambahakan Fft (#354) * feat: add fft * feat: add fft --- math/fft.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 math/fft.py diff --git a/math/fft.py b/math/fft.py new file mode 100644 index 00000000..0b86e9df --- /dev/null +++ b/math/fft.py @@ -0,0 +1,33 @@ +import cmath +import numpy as np + + +def fft(A): + """ + Fungsi untuk kalkulasi Fast Fourier Transform + + >>> y = [i for i in range(1, 10)] + >>> fft(y) + array([45. -0.j , 3.27090469+9.43955428j, + 4.30540729+3.93923101j, 4.77196636+1.65987555j, + 5. +0.j , 4.25695936-1.83110215j, + 5.69459271-3.93923101j, 7.70016959-9.26832768j, + 0. +0.j ]) + """ + N = len(A) + if N == 1: + return A + odd = fft(A[1::2]) + even = fft(A[::2]) + res = [0] * N + for i in range(N // 2): + W = cmath.exp(-1j * 2 * cmath.pi * i / N) + res[i] = even[i] + W * odd[i] + res[i + N // 2] = even[i] - W * odd[i] + return np.array(res) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 4667436bc877c040d73a8eba4449e7844cc7e713 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 11 Oct 2026 03:26:03 +0000 Subject: [PATCH 2/6] docs: update DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 67d468db..6eec9a30 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -267,6 +267,7 @@ * [Faktor Prima](https://github.com/bellshade/Python/blob/main/math/faktor_prima.py) * [Faktorial Looping](https://github.com/bellshade/Python/blob/main/math/faktorial_looping.py) * [Faktorial Rekursif](https://github.com/bellshade/Python/blob/main/math/faktorial_rekursif.py) + * [Fft](https://github.com/bellshade/Python/blob/main/math/fft.py) * [Fibonacci](https://github.com/bellshade/Python/blob/main/math/fibonacci.py) * [Fungsi Gamma](https://github.com/bellshade/Python/blob/main/math/fungsi_gamma.py) * [Geometric Sum](https://github.com/bellshade/Python/blob/main/math/geometric_sum.py) From c5160d59545b5d9ae3eb09a6bfc4d827dc924963 Mon Sep 17 00:00:00 2001 From: Ateng Date: Tue, 13 Oct 2026 18:48:27 +0700 Subject: [PATCH 3/6] feat: menambahkan algoritma kaprekar number (#338) * feat: menambahkan algoritma kaprekar number * fix: menghapus numpy * fix: memperbaiki sedikit bug * fix: memperbaiki redifition * fix: memperbaiki code * fix: memperbaiki test dan memperbaiki test --- other/kaprekar_number.py | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 other/kaprekar_number.py diff --git a/other/kaprekar_number.py b/other/kaprekar_number.py new file mode 100644 index 00000000..c6d9c4f6 --- /dev/null +++ b/other/kaprekar_number.py @@ -0,0 +1,61 @@ +# mengecek apakah bilangan apakah bilangan itu masuk kaprekar +# https://en.wikipedia.org/wiki/Kaprekar_number +import math + + +def kaprekar_number(number: int) -> str: + """ + Angka kaprekar adalah angka yang yang di kuadratkan, + dan di pisahmenjadi dua bagian dan di jumlahkan lagi + maka akat menjadi angka itu kembali. + + >>> kaprekar_number(45) + 'Angka Kaprekar' + >>> kaprekar_number(9) + 'Angka Kaprekar' + >>> kaprekar_number(5) + 'Bukan Angka Kaprekar' + >>> kaprekar_number(10) + 'Bukan Angka Kaprekar' + + """ + benar, bukan = "Angka Kaprekar", "Bukan Angka Kaprekar" + if number == 1: + return benar + + square_number = number * number + + cout_d = 0 + while not square_number == 0: + cout_d += 1 + square_number = square_number // 10 + + square_number = number * number + + r_digits = 0 + while r_digits < cout_d: + r_digits += 1 + eq_parts = math.pow(10, r_digits) + + if eq_parts == number: + continue + + jumlah = square_number // eq_parts + square_number % eq_parts + if jumlah == number: + return benar + + return bukan + + +def main(args=None): + import doctest + + doctest.testmod() + + +if __name__ == "__main__": + # sampel case + print(kaprekar_number(45)) # Angka Kaprekar + print(kaprekar_number(9)) # Angka Kaprekar + print(kaprekar_number(5)) # Bukan Angka Kaprekar + print(kaprekar_number(10)) # Bukan Angka Kaprekar From ee19ee43db09986e1f8a8fd2be5103021e37a6e5 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 13 Oct 2026 11:48:36 +0000 Subject: [PATCH 4/6] docs: update DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 6eec9a30..8be00bc7 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -360,6 +360,7 @@ * [Happy Number](https://github.com/bellshade/Python/blob/main/other/happy_number.py) * [Hex To Rgb](https://github.com/bellshade/Python/blob/main/other/hex_to_rgb.py) * [Is Palindrom](https://github.com/bellshade/Python/blob/main/other/is_palindrom.py) + * [Kaprekar Number](https://github.com/bellshade/Python/blob/main/other/kaprekar_number.py) * [Krisnamurtycheck](https://github.com/bellshade/Python/blob/main/other/krisnamurtyCheck.py) * [Logic Gate](https://github.com/bellshade/Python/blob/main/other/logic_gate.py) * [Lucky Number](https://github.com/bellshade/Python/blob/main/other/lucky_number.py) From 65fc4aaf228bb008e9ed938a7667ce9cdac5a90d Mon Sep 17 00:00:00 2001 From: Ateng Date: Wed, 14 Oct 2026 20:49:15 +0700 Subject: [PATCH 5/6] feat: menambahkan pendulum (#343) * feat: menambahkan pendulum * docs: memperbaiki doc pendulum * fix: memperbaiki variabel pendulum * fix: merapihkan code * fix: memperbaiki animation * fix: test pre-commit * fix: menyesuaikan dengan standar --- implementation/physics/pendulum.py | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 implementation/physics/pendulum.py diff --git a/implementation/physics/pendulum.py b/implementation/physics/pendulum.py new file mode 100644 index 00000000..ec465cb9 --- /dev/null +++ b/implementation/physics/pendulum.py @@ -0,0 +1,100 @@ +# https://en.wikipedia.org/wiki/Pendulum +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + + +def parameter(g=9.8, L=1.0, a=float, b=float) -> float: + time_step = a / b + time_stap = np.linspace(0, a, b) + return g, L, time_step, time_stap + + +def full_pendulum(g, L, theta, theta_velocity, time_step): + """ + fungsi untuk menghitung persamaan pendulum. + """ + theta_acceleration = -(g / L) * np.sin(theta) + theta_velocity += time_step * theta_acceleration + theta += time_step * theta_velocity + return theta, theta_velocity + + +def calculate_pendulum() -> float: + """ + Melakukan kalkulasi pendulum + """ + theta = [np.radians(90)] + theta_velocity = 0 + + for _ in time_stap: + theta_new, theta_velocity = full_pendulum( + g, L, theta[-1], theta_velocity, time_step + ) + theta.append(theta_new) + + # persamaan proyeksi panjang tali + x = L * np.sin(theta) + y = -L * np.cos(theta) + return x, y + + +def setup_axis(axis) -> None: + """ + Setup sumbu x dan y. + """ + axis.set_xlim(-L - 0.2, L + 0.2) + axis.set_ylim(-L - 0.2, L) + axis.grid() + return axis + + +def create_plot_elements(axis) -> None: + """ + Membuat elemen plot yang akan dianimasu. + """ + (rod_line,) = axis.plot([], [], lw=2) + (mass_point,) = axis.plot([], [], marker="o", markersize=10) + (trace,) = axis.plot([], [], "-", lw=1, alpha=0.6) + return rod_line, mass_point, trace + + +def animate(frame, x, y, rod_line, mass_point, trace) -> None: + """ + Fungsi ini berguna untuk mengambil setiap hasil hitungan + dan menjadikan setiap hitungan frame. + """ + rod_line.set_data([0, x[frame]], [0, y[frame]]) + mass_point.set_data([x[frame]], [y[frame]]) + trace.set_data(x[:frame], y[:frame]) + return rod_line, mass_point, trace + + +if __name__ == "__main__": + g, L, time_step, time_stap = parameter(a=20, b=300) + x, y = calculate_pendulum() + fig, axis = plt.subplots() + axis = setup_axis(axis) + rod_line, mass_point, trace = create_plot_elements(axis) + + def init(): + """ + Parameter awal. + """ + rod_line.set_data([], []) + mass_point.set_data([], []) + trace.set_data([], []) + return rod_line, mass_point, trace + + animation = FuncAnimation( + fig=fig, + func=animate, + fargs=(x, y, rod_line, mass_point, trace), + init_func=init, + frames=len(time_stap), + interval=25, + blit=True, + ) + + print(animation) + plt.show() From 1bb7fe4f82683d26d4759818aaae7a903d797c20 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 14 Oct 2026 13:49:26 +0000 Subject: [PATCH 6/6] docs: update DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 8be00bc7..e49bece0 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -236,6 +236,7 @@ * [Transformation 2D](https://github.com/bellshade/Python/blob/main/implementation/linear_algebra/transformation_2d.py) * Physics * [N Body Simulation](https://github.com/bellshade/Python/blob/main/implementation/physics/n_body_simulation.py) + * [Pendulum](https://github.com/bellshade/Python/blob/main/implementation/physics/pendulum.py) * [Percepatan](https://github.com/bellshade/Python/blob/main/implementation/physics/percepatan.py) * Statistic * [Labelencoding](https://github.com/bellshade/Python/blob/main/implementation/statistic/LabelEncoding.py)