Teaching Kids Programming – Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm)


Teaching Kids Programming: Videos on Data Structures and Algorithms

Given equation tex_53a69f903faabd0c8689cb44d19a5c77 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video we know the n must be non-negative integers in order for factorial n! to make sense. If we bruteforce, we don’t know yet the upperbound, however we can ask computer to try until it can find one. If there is no solution, the algorithms will be non-stopping. This is unbounded bruteforce algorithm.

1
2
3
4
5
6
7
def findSolution():
    n = 0
    while True:
        if n * n + 19 * n - math.factorial(n) == 0:
            return n
        n += 1
    # never reach here...
def findSolution():
    n = 0
    while True:
        if n * n + 19 * n - math.factorial(n) == 0:
            return n
        n += 1
    # never reach here...

We can use math.factorial to compute the factorial – to avoid reinventing the wheel. We can also use Recursion to compute the factorial:

1
2
3
4
def f(n):
    if n == 0:
        return 1
    return n * f(n-1)
def f(n):
    if n == 0:
        return 1
    return n * f(n-1)

Alternatively, we can iterate this:

1
2
3
4
5
def f(n):
    ans = 1
    for i in range(2, n + 1):
        ans *= i
    return ans
def f(n):
    ans = 1
    for i in range(2, n + 1):
        ans *= i
    return ans

Solving Math Equation n*n+19*n-n!=0

Let’s move tex_cb21d330969774520ec591a4ca1a9f8a Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video to other side:

tex_9f1b02fb36ee59632b2ef44c69d664f3 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video
And then tex_f90e8246e1df32473ec78b866067696d Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video
Because n is not zero – or zero is not the solution to the equation, we can safely divide both sides by n.
That becomes tex_da9796a00c040a29c222752882c9c796 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video
Let’s use tex_525723e0f70d9889aaf67eb59e956f14 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video to substitute tex_fbf93419d501d5a86d68818d291d3006 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video so tex_2724f0b533835f38bfb6337e3cc94998 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video
tex_1e1241d451ab445f6b192b4456422709 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video

tex_ab04ae591aae9b6384120bb06285b004 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video is a line, and we can try first few numbers and we can see that when k is 4, tex_88a0e96227b987a3378c082d2818fdf2 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video while k is larger than 4, the tex_f0617ff9bb1b7c673bc83033803e608e Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video grows a lot faster than tex_ab04ae591aae9b6384120bb06285b004 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video and there is no cross between two functions.

Therefore, tex_dbdc816ed8fb0365531d7982ae8d91d5 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video is the only solution to tex_53a69f903faabd0c8689cb44d19a5c77 Teaching Kids Programming - Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm) brute force math python teaching kids programming youtube video

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
813 words
Last Post: Teaching Kids Programming - Converting (Binary) Trees to Undirectional Graphs via DFS and BFS Algorithms
Next Post: Teaching Kids Programming - Silver Ratio and Pell Numbers (Metal Quadratic Equation)

The Permanent URL is: Teaching Kids Programming – Solving Math Equation n*n+19*n-n!=0 (Factorial Function and Unbounded Bruteforce Algorithm)

Leave a Reply