<jupyter_start><jupyter_text>1. Crea una función en Python que calcule el mínimo común múltiplo de dos números.<jupyter_code># Calculate the factors of a number
def factorize(number):
    factors = []
    for n in range(2, number+1):
        if (number % n) == 0:
            factors.append(n)
    return factors

# Get factor repetition count for a number
def factors_counts(number):
    factors = factorize(number)
    res = number
    fc = dict()
    for i, f in enumerate(factors):
        while res % f == 0:
            res = res / f
            fc[f]=fc.get(f, 0) + 1
    return fc

# Calculate least common multiple
def lcm(num1, num2):
    fc1 = factors_counts(num1)
    fc2 = factors_counts(num2)
    
    common_factors = set(fc1.keys()) | set(fc2.keys())
    lcm_value = 1
    for cf in common_factors:
        count = max(fc1.get(cf, 0), fc2.get(cf, 0))
        lcm_value *= cf**count
    return lcm_value

# Well there seems to be an easier way ...
def lcm_short(n1, n2):
    if n1 == n2:
        return n1
    else:
        return n1 * n2
lcm(13, 22)
lcm_short(13, 22)<jupyter_output><empty_output><jupyter_text>2. Crea una función en Python que calcule el máximo común divisor de dos números.<jupyter_code># Greatest common dividor based on greatest common factor
def gcd(num1, num2):
    f1 = factorize(num1)
    f2 = factorize(num2)

    common_factors = set(f1) & set(f2)
    
    # If we have no common factors return None
    if len(common_factors) == 0:
        return None
    else:
        return max(common_factors)

gcd(24, 54)<jupyter_output><empty_output><jupyter_text>3. Basándote en datos aleatorios (los que quieras) crea un gráfico de tarta (pie chart) con Mapplotlib.<jupyter_code>%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
N = 5
x = np.random.randint(1, 100, size=N)
plt.pie(x)
plt.show()<jupyter_output><empty_output><jupyter_text>4. Basándote en datos aleatorios, crea un Scatter Plot con Mapplotlib. Explica para qué pueden ser útiles estos gráficos.<jupyter_code>N = 100
x, y = np.random.rand(2, N)
f = plt.scatter(x, y)
f.axes.set_title('A scatter plot, perfect to visualize two dimensional data!')
plt.show()<jupyter_output><empty_output><jupyter_text>5. Explica cómo combinar 4 gráficos en una única figura (subplot).Matplotlib has the concept of figures and axes. A single picture or image is a figure, but a figure can contain multiple axes. Using subplots one can create a grid of axes and include them in a single figure.<jupyter_code># Create a helper function to genate titled scatter plots
def scatter(ax, x, y, fig_title):
    ax.scatter(x, y)
    ax.set_title(fig_title)

# Generate random data
N = 100
naxes = 4
data = np.random.rand(naxes, 2, N)
   
# use subplots to generate 4 axis for this figure
f, axes = plt.subplots(nrows=naxes, ncols=1)

for i in range(4):
    scatter(axes[i], data[i, 0], data[i, 1], 'Figure %02d' % i)
plt.tight_layout()
plt.show()<jupyter_output><empty_output>