Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Ion Flux Relabeling

def process_converter(max_idx, converter):
    prev_node = -1
    current_node = max_idx
    # The subtree is how many elements we have in total for a node
    subtree = max_idx

    if current_node == converter:
        return prev_node

    prev_node = current_node

    while subtree > 1:
        # As we go down through the tree, each level reduces the number by half, which is the same as shifting 1 bit
        subtree = subtree >> 1

        left = current_node - subtree - 1
        right = current_node - 1

        if converter == left or converter == right:
            return prev_node

        if converter < left:
            current_node = left
        elif converter > left:
            current_node = right

        prev_node = current_node

    return -1

def solution(h, q):
    max_idx = 2**h-1
    return [process_converter(max_idx, converter) for converter in q]
Comment

PREVIOUS NEXT
Code Example
Python :: youtube-dl python get file name 
Python :: Python Requests Library Post Method 
Python :: how to get bot voice channel discord.py 
Python :: iterate through characters in a string python 
Python :: python list unique in order 
Python :: Import "whitenoise.django" could not be resolved 
Python :: operator precedence in python 
Python :: indentation levels in programming 
Python :: assign multiline string to variable in python 
Python :: how to connect an ml model to a web application 
Python :: plt.tick_params 
Python :: python list prime numbers 
Python :: discord.py how to print audit logs 
Python :: number of unique pairs in columns pandas 
Python :: how to move tkinter images 
Python :: openpyxl load file 
Python :: python date range 
Python :: discord.py read embed on message 
Python :: pandas dataframe lists as columns 
Python :: how to make a string case insensitive in python 
Python :: isntall packages to databricks 
Python :: dataframein python 
Python :: plotly vertical bar chart 
Python :: create a blank image opencv 
Python :: how to add for loop in python 
Python :: get context data django 
Python :: how to simplify fraction in python 
Python :: python find smallest value in 2d list 
Python :: show columns pandas 
Python :: to_csv create folder 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =