Васил обнови решението на 03.04.2015 10:06 (преди над 9 години)
+def fibonacci():
+ x1 = 0
+ x2 = 1
+ while True:
+ yield x2
+ x1, x2 = x2, x1 + x2
+
+def primes():
+ prime = 2
+ while True:
+ for i in range(2, int(prime / 2) + 1):
+ if prime % i == 0:
+ break
+ else:
+ yield prime
+ prime += 1
+
+def alphabet(code = "", letters = ""):
+ if letters == "":
+ if code == "lat":
+ alphabet = "abcdefghijklmnopqrstuvwxyz"
+ elif code == "bg":
+ alphabet = "абвгдежзийклмнопрстуфхцчшщъьюя"
+ else:
+ print("Invalid input")
+ else:
+ alphabet = letters
+ i = 0
+ while True:
+ yield alphabet[i]
+ i += 1
+
+def intertwined_sequences(data):
+ intertwined = []
+ funcs = []
+ funcvars = []
+ for i in data:
+ if i["sequence"] not in funcs:
+ funcs.append(i["sequence"])
+ if (len(i)) > 2:
+ for e in i:
+ if e != "sequence" and e != "length":
+ funcvars.append(i[e])
+ else:
+ funcvars.append("")
+ for n in funcs:
+ index = funcs.index(n)
+ c = funcvars[funcs.index(n)]
+ if c != "":
+ funcs[index] = eval(n)(c)
+ else:
+ funcs[index] = eval(n)()
+ for i in data:
+ if n == i["sequence"]:
+ (i["sequence"]) = funcs[index]
+ for i in data:
+ x = 0
+ while x < i["length"]:
+ yield(next(i["sequence"]))
+ x += 1