TelenkovDmitry 2 лет назад
Родитель
Сommit
b7af879071
2 измененных файлов с 35 добавлено и 1 удалено
  1. 0 0
      leetcode.py
  2. 35 1
      misc2.py

+ 0 - 0
leetcode.py


+ 35 - 1
misc2.py

@@ -3,6 +3,7 @@
 # "is2 Thi1s T4est 3a"  -->  "Thi1s is2 3a T4est"
 # "4of Fo1r pe6ople g3ood th5e the2"  -->  "Fo1r the2 g3ood 4of th5e pe6ople"
 
+from msilib import sequence
 from operator import itemgetter
 from numpy import block
 
@@ -232,4 +233,37 @@ def binary_array_to_number(arr):
 def litres(time):
     return int(time*0.5//1)
 
-# print(litres(2))
+# print(litres(2))
+
+# ------------------------------------------------------------------------------- #
+
+# Нужно вернуть n числе последовательности Трибоначчи
+'''
+def tribonacci(signature, n):
+    sequence = []
+    
+    if n < 3:
+        for i in range(n):
+            sequence.append(signature[i])
+        return sequence
+    else:
+        sequence.extend(signature)
+
+    for i in range(3, n):
+        sequence.append(sequence[i-3] + sequence[i-2] + sequence[i-1])
+
+    return(sequence)
+'''
+
+
+# Хорошее решение через срез
+def tribonacci(signature, n):
+  res = signature[:n]
+  print(res)
+  for i in range(n - 3): 
+      res.append(sum(res[-3:]))
+  return res
+
+
+# print(tribonacci([0.5, 0.5, 0.5], 1))
+