Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

minimum-number-of-steps-to-reduce-number-to-1

#minimum-number-of-steps-to-reduce-number-to-1
def stepCount(n):
    count = 0
    while n > 1:
        if n % 2 == 0:             # bitmask: *0
            n = n // 2
        elif n == 3 or n % 4 == 1: # bitmask: 01
            n = n - 1
        else:                      # bitmask: 11
            n = n + 1
        count += 1
    return count
Comment

PREVIOUS NEXT
Code Example
Python :: implicit conversion in python example 
Python :: flask render_template 
Python :: python replace string in file 
Python :: print value of tensor 
Python :: weekday pandas 
Python :: how to extract numbers from a list in python 
Python :: discord.py send messages 
Python :: groupby year datetime pandas 
Python :: How can I install XGBoost package in python on Windows 
Python :: converting month number to month name python 
Python :: python string math 
Python :: python count total no of word in a text 
Python :: Flatten List in Python Using List Comprehension 
Python :: multiple inputs in python 
Python :: python get number of days 
Python :: python remove form list 
Python :: python download for ubuntu 20.04 
Python :: django rest 
Python :: how to find most repeated word in a string in python 
Python :: how to count special values in data in python 
Python :: add text to pygame window 
Python :: pdf to text python 
Python :: new window selenium python 
Python :: pytorch freeze layers 
Python :: python3 send mail 
Python :: python input lowercase 
Python :: create 2d array python list comprehension 
Python :: python add all items in list 
Python :: reverse text python 
Python :: python ascii code to string 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =