Chat

Un invernadero automatizado


No results...

Frantic Plum Pip boy

Frantic Plum Pip boy thumbnail
como puedo corregir este codigo para que funcione en flux.io import time import random import matplotlib.pyplot as plt import io import base64 from fluxio import Flow
flow = Flow()
@flow.task def linear_search(arr, target): for i in range(len(arr)): if arr[i] == target: return i return -1
@flow.task def binary_search(arr, target): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == target: return mid elif arr[mid] < target: low = mid + 1 else: high = mid - 1 return -1
@flow.task def measure_time(func, arr, target): start_time = time.time() func(arr, target) end_time = time.time() return end_time - start_time
@flow.task def generate_data_and_measure(): sizes = [100, 1000, 5000, 10000, 50000, 100000] linear_times = [] binary_times = []
for size in sizes:
    arr = random.sample(range(size * 2), size)
    target = random.choice(arr)
    sorted_arr = sorted(arr)

    linear_time = measure_time(linear_search, arr, target)
    binary_time = measure_time(binary_search, sorted_arr, target)

    linear_times.append(linear_time)
    binary_times.append(binary_time)

return sizes, linear_times, binary_times
@flow.task def plot_results(sizes, linear_times, binary_times): plt.plot(sizes, linear_times, label='Búsqueda Lineal') plt.plot(sizes, binary_times, label='Búsqueda Binaria') plt.xlabel('Tamaño del Array') plt.ylabel('Tiempo de Ejecución (segundos)') plt.title('Análisis de Complejidad Temporal') plt.legend() plt.grid(True)
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
img_str = base64.b64encode(buf.read()).decode('utf-8')
plt.close()
return img_str
@flow.task def main(): sizes, linear_times, binary_times = generate_data_and_measure() img_str = plot_results(sizes, linear_times, binary_times) return img_str
if name == "main": flow.run(main)

Properties

Properties describe core aspects of the project.

Pricing & Availability

Distributor

Qty 1

Controls