Dmitry Telenkov 1 year ago
parent
commit
48bdcf92ff

BIN
courses/cpp_1/hello_word


+ 29 - 2
courses/cpp_1/hello_word.cpp

@@ -1,19 +1,39 @@
 #include <iostream>
 using namespace std;
 
+#define sqr(x) x * x
+// #define MAX(a, b, c) ((a) >= (b)) ? (c) = (a) : (c) = (b); 
+#define MAX(x, y, r) {typeof(x) _x = x; typeof(y) _y = y; \
+        (r) = (_x >= _y ? _x : _y);}
+
+
 void sum();
 void out_stream();
 void in_stream();
 void in_stream_get();
+int power(int x, unsigned p);
 
 
 int main()
 {
     std::cout << "Hello, World!\n";
+    int c = 0;
     // sum();
     // out_stream();
     // in_stream();
-    in_stream_get();
+    // in_stream_get();
+
+#if 0
+    int ret = power(5, 2);
+    std::cout << "res = " << ret << "\r\n";
+    ret = power(5, 0);
+    std::cout << "res = " << ret << "\r\n";
+#endif
+
+    // std::cout << sqr(3 + 0) << "\r\n";
+    MAX(4, 6, c);
+    std::cout << c << "\r\n";
+
     return 0;
 }
 
@@ -58,4 +78,11 @@ void in_stream_get()
             std::cout << c;
         else break;
     }
-}
+}
+
+int power(int x, unsigned p)
+{
+    return (!p) ? 1 : x * power(x, p - 1);
+}
+
+

+ 65 - 0
courses/python_for_begginers/list.py

@@ -136,3 +136,68 @@ def list_12():
 
 # list_12()
 
+def list_13():
+    l1 = list(map(int, input().split()))
+    l2 = list(map(int, input().split()))
+    for i in range(len(l1)):
+        print(l1[i] + l2[i], end = ' ')
+
+# list_13()
+
+def list_14():
+    l1 = list(map(int, input().split()))
+    l2 = []
+    for i in l1:
+        l2.append(i)
+        l2.append('+')
+
+    l2.pop()
+    print(*l2, sep='', end='')
+    print('=', sum(l1), sep='')
+
+# list_14()
+
+# abc-def-hijk или
+# 7-abc-def-hijk
+
+def list_15():
+    l = list(input())
+    flag = True
+    if (l[3] == l[7] == '-') and len(l) == 12:
+        for i in range(len(l)):
+            if (l[i].isdigit() == False) and (l[i] != '-'):
+                flag = False
+    elif (l[1] == l[5] == l[9] == '-') and len(l) == 14:
+        for i in range(len(l)):
+            if (l[i].isdigit() == False) and (l[i] != '-'):
+                flag = False
+    else:
+        flag = False
+
+    if flag == False:
+        print("NO")
+    else:
+        print("YES")
+
+# list_15()
+
+
+def list_16():
+    l = list(input().split())
+    length = [len(word) for word in l]
+    print(max(length))
+
+# list_16()
+    
+def list_17():
+    l = list(input().split())
+    l2 = []
+    new_word = ''
+    for word in l:
+        new_word = word[1:] + word[0] + 'ки'
+        l2.append(new_word)
+
+    print(*l2)
+
+# list_17()    
+

+ 76 - 0
courses/python_for_begginers/sort.py

@@ -173,6 +173,7 @@ def sort_2():
 
 # sort_2()
 
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
 
 def sort_3():
     drivers = {}
@@ -199,3 +200,78 @@ def sort_3():
         print(i[0], i[1])
 
 # sort_3()
+
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
+
+# Сортировка пузырьком
+def sort_bubble():
+    a = [1, 7, -3, 9, 0, -67, 34, 12, 45, 1000, 6,  8, -2, 99]
+    n = len(a)
+    flag = True
+
+    for i in range(n - 1):
+        flag = True
+        for j in range(n - i - 1):
+            if a[j] > a[j + 1]:                  # если порядок элементов пары неправильный
+                a[j], a[j + 1] = a[j + 1], a[j]  # меняем элементы пары местами 
+                flag = False
+        if flag == True:
+            break
+
+    print('Отсортированный список:', a)
+
+# sort_bubble()
+    
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
+
+# Сортировка выбором
+def sort_selection():
+    a = [78, -32, 5, 39, 58, -5, -63, 57, 72, 9, 53, -1, 63, -97,
+        -21, -94, -47, 57, -8, 60, -23, -72, -22, -79, 90, 96, -41,
+        -71, -48, 84, 89, -96, 41, -16, 94, -60, -64, -39, 60, -14,
+        -62, -19, -3, 32, 98, 14, 43, 3, -56, 71, -71, -67, 80, 27,
+        92, 92, -64, 0, -77, 2, -26, 41, 3, -31, 48, 39, 20, -30,
+        35, 32, -58, 2, 63, 64, 66, 62, 82, -62, 9, -52, 35, -61,
+        87, 78, 93, -42, 87, -72, -10, -36, 61, -16, 59, 59, 22,
+        -24, -67, 76, -94, 59]
+
+    n = len(a)
+    
+    new_a = []
+
+    for i in range(len(a)):
+        el = min(a)
+        index = a.index(el)
+        a.pop(index)
+        new_a.append(el)
+
+    print(new_a)
+
+# sort_selection()
+
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
+
+# Сортировка простыми вставками
+def sort_simple_insertion():
+    a = [1, 7, -3, 9, 0, -67, 34, 12, 45, 1000, 6,  8, -2, 99]
+    n = len(a)
+
+    for i in range(1, n): 
+        elem = a[i]  # берем первый элемент из неотсортированной части списка
+        j = i
+        
+        # пока элемент слева существует и больше нашего текущего элемента
+        while j >= 1 and a[j - 1] > elem:
+            # смещаем j-й элемент отсортированной части вправо
+            a[j] = a[j - 1]
+            # сами идём влево, дальше ищем место для нашего текущего элемента
+            j -= 1
+
+        # нашли место для нащего текущего элемента из неотсортированной части
+        # и вставляем его на индекс j в отсортированной части
+        a[j] = elem
+
+
+    print('Отсортированный список:', a)
+    
+sort_simple_insertion()

+ 37 - 0
jsonrpc/teplo_api_controller.py

@@ -0,0 +1,37 @@
+
+# Исходный вариант функции
+def get_current_values(self, device_id, subsystem, value_name_list):
+    if device_id != 'gius-controller':
+        return APIBase.get_current_values(self, device_id, subsystem, value_name_list)
+    
+    result = {}
+    for value_name in value_name_list:
+        try:
+            if value_name.startswith("AI"):
+                v = self.get_sensorman().get_sensor_value_by_alias("teploUB.adc%s"%(value_name[-1]))
+            else:
+                v = self.get_sensorman().get_sensor_value_by_alias("DI%s"%(value_name[-1]))
+            result[value_name] = ( v, int(time.time()), OPC_QUALITY_GOOD )
+        except Exception as e:
+            self.logger.exception("get_current_values {0} error {1}".format(device_id, e))
+            result[value_name] = (None, None, OPC_QUALITY_BAD)
+    return result
+
+# Вариант с дополнениями
+def get_current_values(self, device_id, subsystem, value_name_list):
+    if device_id != 'gius-controller':
+        return APIBase.get_current_values(self, device_id, subsystem, value_name_list)
+    
+    result = {}
+    for value_name in value_name_list:
+        try:
+            if value_name.startswith("AI"):
+                v = self.get_sensorman().get_sensor_value_by_alias("teploUB.adc%s"%(value_name[-1]))
+            else:
+                v = self.get_sensorman().get_sensor_value_by_alias("DI%s"%(value_name[-1]))
+            result[value_name] = ( v, int(time.time()), OPC_QUALITY_GOOD, "str_param" )
+        except Exception as e:
+            self.logger.exception("get_current_values {0} error {1}".format(device_id, e))
+            result[value_name] = (None, None, OPC_QUALITY_BAD)
+    return result
+

+ 18 - 0
leetcode.py

@@ -0,0 +1,18 @@
+# Проверка числа на полиндром
+def is_polindrom(x: int) -> bool:
+
+    if x < 0:
+        return False
+
+    new = 0
+    orig = x
+    while x:
+        x, d = divmod(x, 10)
+        new = new*10 + d
+
+    return new == orig    
+
+print(is_polindrom(121))
+
+
+

+ 32 - 0
std_lib/log.py

@@ -0,0 +1,32 @@
+import logging
+
+
+logging.basicConfig(level=logging.INFO, filename="py_log.log", filemode="w",
+                    format="%(asctime)s %(levelname)s %(message)s")
+# logging.info("loggin info")
+
+"""
+x = 3
+y = 0
+
+logging.info(f"The value of x and y are {x} and {y}.")
+
+try:
+    x/y
+    logging.info(f"x/y successful with result: {x/y}.")
+except ZeroDivisionError as err:
+    logging.error("ZeroDivisionError", exc_info=True)
+"""
+
+x_vals = [2,3,6,4,10]
+y_vals = [5,7,12,0,1]
+
+for x_val, y_val in zip(x_vals, y_vals):
+    x, y = x_val, y_val
+    logging.info(f"The values of x and y are {x} and {y}.")
+    try:
+        x/y
+        logging.info(f"x/y successful with result: {x/y}.")
+    except ZeroDivisionError as err:
+        logging.exception("ZeroDivisionError")
+        

+ 14 - 0
std_lib/py_log.log

@@ -0,0 +1,14 @@
+2023-12-18 15:05:19,255 INFO The values of x and y are 2 and 5.
+2023-12-18 15:05:19,256 INFO x/y successful with result: 0.4.
+2023-12-18 15:05:19,256 INFO The values of x and y are 3 and 7.
+2023-12-18 15:05:19,256 INFO x/y successful with result: 0.42857142857142855.
+2023-12-18 15:05:19,256 INFO The values of x and y are 6 and 12.
+2023-12-18 15:05:19,256 INFO x/y successful with result: 0.5.
+2023-12-18 15:05:19,256 INFO The values of x and y are 4 and 0.
+2023-12-18 15:05:19,256 ERROR ZeroDivisionError
+Traceback (most recent call last):
+  File "log.py", line 28, in <module>
+    x/y
+ZeroDivisionError: division by zero
+2023-12-18 15:05:19,256 INFO The values of x and y are 10 and 1.
+2023-12-18 15:05:19,256 INFO x/y successful with result: 10.0.