nord vpnnord vpn
Ad

Tempo

mail@pastecode.io avatar
unknown
python
a month ago
1.8 kB
1
Indexable
Never
import re
import requests

def extract_parameters(html_content):
    """Extracts U0, add_to_un, and add_to_n from the HTML content."""
    # Regular expressions to match the parameters
    u0_pattern = re.compile(r'U<sub>0</sub>\s*=\s*(-?\d+)')
    add_to_un_pattern = re.compile(r'U<sub>n\+1</sub>\s*=\s*\[\s*(-?\d+)\s*\+\s*U<sub>n</sub>\]')
    add_to_n_pattern = re.compile(r'U<sub>n\+1</sub>\s*=.*\+\s*\[\s*n\s*\+\s*(\d+)\s*\]')

    # Find the parameters in the content
    u0_match = u0_pattern.search(html_content)
    add_to_un_match = add_to_un_pattern.search(html_content)
    add_to_n_match = add_to_n_pattern.search(html_content)

    # Extract the values
    u0 = int(u0_match.group(1)) if u0_match else None
    add_to_un = int(add_to_un_match.group(1)) if add_to_un_match else None
    add_to_n = int(add_to_n_match.group(1)) if add_to_n_match else None

    return u0, add_to_un, add_to_n

def calculate_un(n, u0, add_to_un, add_to_n):
    """Calculate the nth term of the sequence defined by Un+1 = [add_to_un + Un] + [n + add_to_n]."""
    un = u0
    for i in range(n):
        un = (add_to_un + un) + (i + add_to_n)
    return un

# URL to which the request will be sent
url = 'https://mathematic-progression.challenges.airbus.pro.root-me.org/e_p1_v.php?result='

# Send the request and get the response
response = requests.get(url)
html_content = response.text

# Extract parameters from the HTML content
u0, add_to_un, add_to_n = extract_parameters(html_content)

# Assuming we need to calculate U1
if u0 is not None and add_to_un is not None and add_to_n is not None:
    result = calculate_un(1, u0, add_to_un, add_to_n)
    print(f'The result is: {result}')
else:
    print('Could not extract the necessary parameters.')

nord vpnnord vpn
Ad