-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
133 lines (127 loc) · 3.33 KB
/
test.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# from sympy import Symbol, solve, S
# from sympy.solvers import solveset
#
# x = Symbol('x', real=True)
# f = x ** 2 - 5 * x + 1
# # a = solve(f, x)
# result = solveset(f, x, domain=S.Reals)
#
# for i in result:
# print(float(i))
# a = ['123', '111111', 1, 1, 838, 453]
import sys
from sympy import Symbol, solve
def solver(line):
user_id, bid, type, i, ori_amount, total_earning = line.replace(' ', '').split(",")
c = float(total_earning) / float(ori_amount)
i = float(i)
p = Symbol('p', real=True)
tol = ((i * p - 1) * (1 + p) ** i + 1) / ((1 + p) ** i - 1) - c
# result = solveset(tol, p, domain=S.Reals)
result = solve(tol, p)
for i in result:
try:
i = float(i)
if i >= 0.01 and i <= 0.8:
x = i
else:
x = 'can not solve'
except:
x = 'can not solve'
return str(x)
try:
for line in sys.stdin:
line = line.strip()
print(line + " " + solver(line))
except Exception as e:
print('[PYTHON_MONTH_RATE]###%s:%s' % (line, e))
#
#
#
#
#
#
#
#
# import sys
# import numpy as np
# import pandas as pd
# from sympy import Symbol, S
# from sympy.solvers import solveset
#
#
# def solver(line):
# user_id, bid, type, i, ori_amount, total_earning = line.strip().split("\t")
# c = float(total_earning) / float(ori_amount)
# i = float(i)
# p = Symbol('p', real=True)
# tol = ((i * p - 1) * (1 + p) ** i + 1) / ((1 + p) ** i - 1) - c
# result = solve(tol, p)
# for i in result:
# try:
# i = float(i)
# if i >= 0.01 and i <= 0.8:
# x = i
# else:
# x = 'can not solve'
# except:
# x = 'can not solve'
# return str(x)
#
#
# try:
# for line in sys.stdin:
# line = line.strip()
# print(line + " " + solver(line))
# except Exception as e:
# print('[PYTHON_MONTH_RATE]###%s:%s' % (line, e))
#
#
# def solver2(line):
# user_id, bid, type, i, ori_amount, total_earning = line.strip().split("\t")
# c = float(total_earning) / float(ori_amount)
# i = float(i)
# p = Symbol('p', real=True)
# tol = abs(((i * p - 1) * (1 + p) ** i + 1) / ((1 + p) ** i - 1) - c)
# result = solveset(tol, p, domain=S.Reals)
# for i in result:
# try:
# i = float(i)
# if i >= 0.01 and i <= 0.8:
# x = i
# else:
# x = 'can not solve'
# except:
# x = 'can not solve'
# return str(x)
#
#
# try:
# for line in sys.stdin:
# line = line.strip()
# print(line + " " + solver2(line))
# except Exception as e:
# print('[PYTHON_MONTH_RATE]###%s:%s' % (line, e))
#
#
# def solver(line):
# user_id, bid, type, i, ori_amount, total_earning = line.strip().split("\t")
# c = float(total_earning) / float(ori_amount)
# i = float(i)
# m = 100000000000000
# x = 0
# p_list = np.arange(0.01, 0.8, 0.001)
# for p in p_list:
# tol = abs(((i * p - 1) * (1 + p) ** i + 1) / ((1 + p) ** i - 1) - c)
# if tol <= m:
# m = tol
# x = p
# return str(x)
#
#
# try:
# for line in sys.stdin:
# line = line.strip()
# print(line + " " + solver(line))
# except Exception as e:
# print('[PYTHON_MONTH_RATE]###%s:%s' % (line, e))