Skip to content

Experiment with the AI assistant

Generative AI is coming to DataCamp Workspace! Go through this notebook to experience the AI-enabled functionality. In this example project, we'll be downloading and visualization financial data.

Get the data

The first step is getting data. Try asking the AI Assistant to "import yahoo finance data" for any publicly-traded company.

Visualize the data

After the data has been imported, visualize the data by using the prompt "Plot the stock value over time."

Do more

Some ideas:

  • Analyze the performance of the stock you selected in comparison to another stock throughout the pandemic. Generate a chart that showcases the values of "Stock A" and "Stock B" from 2019 to the present.
  • Plot the revenue and earnings of stock A and stock B.
  • Compare the market cap of the 5 largest companies in a sector you're interested in.

May the AI force be with you! 🤖

def max_integer(A):
    """Returns the maximum integer from array A."""
    if not A:  # Check if the list is empty
        return None
    max_val = A[0]
    for num in A:
        if num > max_val:
            max_val = num
    return max_val

# Example usage
A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
max_integer(A)
def max_and_missing_integer(A):
    """Returns the maximum integer and the smallest missing positive integer from array A."""
    if not A:  # Check if the list is empty
        return None, None
    
    max_val = A[0]
    num_set = set(A)
    
    for num in A:
        if num > max_val:
            max_val = num
    
    # Find the smallest missing positive integer
    missing_val = 1
    while missing_val in num_set:
        missing_val += 1
    
    return max_val, missing_val

# Example usage
A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
max_and_missing_integer(A)
binary_str = '0' * 64  # A binary string of 64 zeros
decimal_number = int(binary_str, 2)  # Convert the binary string to a decimal number
decimal_number
binary_str = '1' + '0' * 63  # A binary string of 1 followed by 63 zeros
decimal_number = int(binary_str, 2)  # Convert the binary string to a decimal number
decimal_number
def longest_zero_sequence(n):
    """Finds the longest sequence of zeros in the binary representation of an integer n."""
    binary_representation = bin(n)[2:]  # Get binary representation of n, remove '0b' prefix
    zero_sequences = binary_representation.split('1')  # Split by '1' to find sequences of zeros
    longest_sequence = max(zero_sequences, key=len)  # Find the longest sequence of zeros
    return len(longest_sequence)

# Example usage
n = 529  # Binary: 1000010001
longest_zero_sequence(n)
def max_and_missing_integer(A):
    # Find the maximum value in the list
    max_value = max(A)
    
    # Find the smallest missing positive integer
    A_set = set(A)
    smallest_missing = 1
    while smallest_missing in A_set:
        smallest_missing += 1
    
    return smallest_missing

# List A
A = [1,3,6,5,1,2]

max_and_missing_integer(A)
def count_conforming_bitmasks(mask1, mask2, mask3):
    """
    Count the number of 30-bit bitmasks that conform to at least one of the three given 30-bit bitmasks.
    
    A bitmask conforms to another bitmask if for every bit that is set in the given bitmask, 
    the corresponding bit in the bitmask to be checked is also set.
    
    Parameters:
    mask1, mask2, mask3 (int): The three given 30-bit bitmasks.
    
    Returns:
    int: The count of 30-bit bitmasks that conform to at least one of the given bitmasks.
    """
    count = 0
    for bitmask in range(1 << 30):
        if (bitmask & mask1 == mask1) or (bitmask & mask2 == mask2) or (bitmask & mask3 == mask3):
            count += 1
    return count

# Example usage
mask1 = 0b101010101010101010101010101010
mask2 = 0b010101010101010101010101010101
mask3 = 0b111100001111000011110000111100

count_conforming_bitmasks(mask1, mask2, mask3)
def has_consecutive_ones(n):
    """Check if the binary representation of n has consecutive ones."""
    return '11' in bin(n)


def largest_no_consecutive_ones(n):
    """Find the largest integer <= n with no consecutive ones in binary representation."""
    for i in range(n, 0, -1):
        if not has_consecutive_ones(i):
            return i
    return 0


def decompose_no_consecutive_ones(n):
    """Decompose n into a sum of integers with no consecutive ones in binary form."""
    result = []
    while n > 0:
        largest = largest_no_consecutive_ones(n)
        result.append(largest)
        n -= largest
    return result

# Example usage
n = 23
decompose_no_consecutive_ones(n)