dynamic_programming.minimum_steps_to_one

YouTube Explanation: https://www.youtube.com/watch?v=f2xi3c1S95M

Given an integer n, return the minimum steps from n to 1

AVAILABLE STEPS:
  • Decrement by 1

  • if n is divisible by 2, divide by 2

  • if n is divisible by 3, divide by 3

Example 1: n = 10 10 -> 9 -> 3 -> 1 Result: 3 steps

Example 2: n = 15 15 -> 5 -> 4 -> 2 -> 1 Result: 4 steps

Example 3: n = 6 6 -> 2 -> 1 Result: 2 step

Attributes

__author__

Functions

min_steps_to_one(→ int)

Minimum steps to 1 implemented using tabulation.

Module Contents

dynamic_programming.minimum_steps_to_one.min_steps_to_one(number: int) int

Minimum steps to 1 implemented using tabulation. >>> min_steps_to_one(10) 3 >>> min_steps_to_one(15) 4 >>> min_steps_to_one(6) 2

Parameters:

number

Return int:

dynamic_programming.minimum_steps_to_one.__author__ = 'Alexander Joslin'