pythonMathLog.py 1.24 KB
import math

print("Finding most close integer n in n*log(n)")
print("Please enter the number of n*log(n)")
goal = input("Enter : ")
start = 1
increaseValue = 1
presentComparer = start

#increase or decrease : 0 - increase / 1 - decrease
valueIndicator = 0

while(1):
    presentLogValue = presentComparer * math.log10(presentComparer)
    
    if presentLogValue<goal and valueIndicator==1 and increaseValue==1 :
        print("n : " + str(presentComparer))
        print("most close number to goal : " + str(presentLogValue))
        break

    # save previous value befor comparer increasment
    prevLogValue = presentLogValue
    prevComparer = presentComparer

    # comparer increasement
    if valueIndicator == 0 :
        presentComparer += increaseValue
    elif valueIndicator == 1 :
        presentComparer -= increaseValue


    # indicator and increasement changing logic
    if presentLogValue > goal :
        valueIndicator = 1
        
        if presentComparer/10 == increaseValue*10 :
            increaseValue *= 10

    elif presentLogValue < goal :
        valueIndicator = 0

        if presentComparer/10 >= increaseValue*10 :
            increaseValue *= 10

    


# 10000/10= 1000 == 1000
# 86000/10= 1000 == 1000
# 100/10 = 9 <= 1 * 10