pythonMathLog.py
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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