(Mar-24-2024, 10:45 AM)MoreMoney Wrote: Thanks it's work but i'm open for improvement is it possible to increase the completion time even small amount? How to do it?There are many ways algorithms can do some improvement,but for big leap can use eg Numba, Cython, PyPy.
As this is homework i guess is more the algorithms rute.
To show a example with Numba.
from numba import jit import time @jit(nopython=True) def find_pin_numba(target_pin): for guess in range(1000000000): if guess == target_pin: return True return False def main(): pin_input = input("Enter PIN: ") # Validate input if not pin_input.isdigit() or len(pin_input) != 9: print("Entered PIN is invalid.") return target_pin = int(pin_input) start = time.time() if find_pin_numba(target_pin): print(f"Found PIN in {time.time() - start} seconds.") else: print("PIN not found.") if __name__ == "__main__": main()
# Python G:\div_code\po_env λ python fast_1.py Enter PIN: 999999999 Found pin in 46.00567603111267 seconds. # Numba G:\div_code\po_env λ python fast_numba.py Enter PIN: 999999999 Found PIN in 0.43939685821533203 seconds.So as you see that speed goes down from 46-sec standar Python to 0.4-sec with Numba.
The only change is is comment out line 5.
#@jit(nopython=True)