Teaching Kids Programming – Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation


Teaching Kids Programming: Videos on Data Structures and Algorithms

Eric wants to build a Rectangle Fence against an old wall using length of bricks (all 32), see below:

-------------------------- // old wall
     |    |
     |    |
     L____J  // new wall

Eric wants to maximize the area of the fence. What is the height and width?

Compute the Max Fence Area via Bruteforce Algorithm

Since the unit is integer – we can bruteforce all possibilities of either H or W. The domain space is limited. We can either list the values in a table or use computer program to search for the maximal area:

1
2
3
4
5
6
7
8
9
def getMaxAreaOfFence():
  ans = 0
  maxh = 0
  for h in range(1, 16):
    w = 32 - h - h
    if w * h > ans:
      ans = w * h
      maxH = h
  return ans, h, 32 - h - h
def getMaxAreaOfFence():
  ans = 0
  maxh = 0
  for h in range(1, 16):
    w = 32 - h - h
    if w * h > ans:
      ans = w * h
      maxH = h
  return ans, h, 32 - h - h

Maximal Area by Solving Parabola Quadratic Equation

Mathematically speak, the area function f(w, h) aka tex_e69018e9bdb90890f88aefa3e40285c5 Teaching Kids Programming - Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation algorithms brute force math python teaching kids programming youtube video which can then be rewritten as a quadratic equation tex_d06c324157a70c269a56d8379441340e Teaching Kids Programming - Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation algorithms brute force math python teaching kids programming youtube video i.e. tex_13cd22b1135924ed809533d4b542e568 Teaching Kids Programming - Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation algorithms brute force math python teaching kids programming youtube video .

The symmetric axis for this function is tex_869878ab4bc269707a3bc929e11a265b Teaching Kids Programming - Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation algorithms brute force math python teaching kids programming youtube video which is (h=8), where this function has a maximal value. The area is 8*16=128

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
462 words
Last Post: Teaching Kids Programming - Number of Unique Email Addresses
Next Post: Teaching Kids Programming - Compute the Maximal Perimeter by Forming a Rectangle from N squares

The Permanent URL is: Teaching Kids Programming – Compute the Max Fence Area via Bruteforce Algorithm or Parabola Quadratic Equation

Leave a Reply