# 5

Nov 22nd, 2020
510
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from math import sqrt
2. def frange(start, end=None, inc=None):
3.     if end == None:
4.         end = start + 0.0
5.         start = 0.0
6.
7.     if inc == None:
8.         inc = 1.0
9.
10.     L = []
11.     while 1:
12.         next = start + len(L) * inc
13.         if inc > 0 and next >= end:
14.             break
15.         elif inc < 0 and next <= end:
16.             break
17.         L.append(next)
18.
19.     return L
20.
21. def uravnenie(a, b, c):
22.     a = float(a)
23.     b = float(b)
24.     c = float(c)
25.     discriminant = b ** 2 - 4 * a * c
26.     if discriminant < 0:
27.         print('Корней нет')
28.         return float(-2000)
29.     elif discriminant == 0:
30.         x = -b / (2 * a)
31.         return x
32.     else:
33.         x1 = (-b + discriminant ** 0.5) / (2 * a)
34.         x2 = (-b - discriminant ** 0.5) / (2 * a)
35.         return x1, x2
36.
37.
38. maximum = -20000
39. for y in frange(-3.00000, 3.00001, 0.00001):
40.     arr_of_x = list(uravnenie(1, sqrt(3)*y, (y ** 2 - 25)))
41.     if len(arr_of_x) == 1:
42.         arr_of_z = uravnenie(1, arr_of_x[0], (arr_of_x[0] ** 2 - 16))
43.         number = arr_of_x[0] * y + 2 * y * arr_of_z + sqrt(3) * arr_of_z * arr_of_x[0]
44.         if number > maximum:
45.             maximum = number
46.     if len(arr_of_x) == 2:
47.         arr_of_z = [uravnenie(1, arr_of_x[0], (arr_of_x[0] ** 2 - 16)),
48.                     uravnenie(1, arr_of_x[1], (arr_of_x[1] ** 2 - 16))]
49.         if len(arr_of_z) == 0:
50.             continue
51.         if len(arr_of_z) == 2:
52.             number1 = arr_of_x[0] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[0]
53.             number2 = arr_of_x[1] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[1]
54.             number3 = arr_of_x[0] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[0]
55.             number4 = arr_of_x[1] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[1]
56.             if max(number1, number2, number3, number4) > maximum:
57.                 maximum = max(number1, number2, number3, number4)
58.         if len(arr_of_z) == 4:
59.             number1 = arr_of_x[0] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[0]
60.             number2 = arr_of_x[0] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[0] * arr_of_x[1]
61.             number3 = arr_of_x[0] * y + 2 * y * arr_of_z[2] + sqrt(3) * arr_of_z[0] * arr_of_x[2]
62.             number4 = arr_of_x[0] * y + 2 * y * arr_of_z[3] + sqrt(3) * arr_of_z[0] * arr_of_x[3]
63.             number5 = arr_of_x[1] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[1] * arr_of_x[0]
64.             number6 = arr_of_x[1] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[1]
65.             number7 = arr_of_x[1] * y + 2 * y * arr_of_z[2] + sqrt(3) * arr_of_z[1] * arr_of_x[2]
66.             number8 = arr_of_x[1] * y + 2 * y * arr_of_z[3] + sqrt(3) * arr_of_z[1] * arr_of_x[3]
67.             if max(number1, number2, number3, number4, number5, number6, number7, number8) > maximum:
68.                 maximum = max(number1, number2, number3, number4, number5, number6, number7, number8)
69. print(maximum)
70.
RAW Paste Data