Skip to content
Menu
Petra Academy
  • Home
  • Forum
    • Latest News
    • Scholar’s Forum
  • Admissions
    • Profile
    • Distinctives
    • Statements
    • Open House
    • Scholarships
    • Apply
  • School
    • Academics
    • Arts
      • Dramatic Arts
      • Musical Arts
      • Visual Arts
    • Athletics
    • Board
    • Faculty & Staff
    • Facility
    • Houses
    • Events
    • Forms
      • Admissions
      • Permission Slips
      • School Supplies
      • Employment
      • Athletics
    • How You Can Help
  • Parents
    • Resources
  • Contact
  • Give
  • Apply
  • Portal
Close Menu

Learning to Fail on Pi Day

Sam Koenen, Academic Dean
Sam Koenen, Academic Dean

As a belated celebration of Pi Day (March 14), the Petra 10th grade Computer Science class recently completed a programming lab to calculate the value of π by using the Monte Carlo method. In addition to learning important coding structures, the class also reviewed how to graphically represent data and how to evaluate the efficiency of their program.

They also learned the vital lesson that finding a right solution to a problem isn’t the same as finding the best solution.

The Monte Carlo Method

The Monte Carlo method of approximating the value of π begins with a circle inscribed in a square. The circle has a radius of 1 unit, which means the sides of the square are 2 units long.

unitCircle

The area of the circle is π square units (A = π * 12), and the area of the square is 4 square units (A = 22). This means that the ratio of the area of the circle to the area of the square is π : 4 or π / 4.

If we were to throw a certain number of darts at the circle, and then count the number of darts that hit the circle, we can approximate the value of π. The ratio of number of hits (H) to the total number of darts thrown (D) is approximately equal to the ratio of the areas:  H / D ≈ π / 4.

If we divide both side by 4, we find a formula for approximating π: π ≈ (H / D) / 4. Now we just need to write a computer program that can simulate the dart throwing.

Throwing the Darts

The Python programming language that the Petra students are learning has a very useful graphics module called Turtle. Using the Turtle module and the approximation formula in the section above, we were able to write a program that simulated random dart throwing.

The 1-unit scale of the target prohibited us from drawing a true circle, so we added some code to mark hits in red and misses in blue. Then, we began testing our program, starting with 10 darts.

10 Darts (<1 sec) // Result: 2.8

Since 10 darts gave us a very poor approximation of 2.8, we then tried 100 darts.

100 Darts (<1 sec) // Result: 3.08

Increasing our dart throws by an order of 10 gave us more accuracy, so we ran tests of 1000 darts and 10,000 darts.

1000Darts
1000 Darts (< 1 sec) // Result: 3.096
10000Darts
10,000 Darts (< 1 min) // Result: 3.1444

Throwing 10000 darts increased our accuracy, but we also noticed that the program took significantly longer to run. We ran one more test of 100,000 darts, which gave us some significant data to consider.

100000Darts
100,000 Darts (~ 20 min) // Result: 3.14612

The final test with 100,000 darts took 20 minutes to complete on my MacBook Pro without a significant gain in accuracy. After completing this test, we assessed how helpful our program was.

Assessment

The final test of 100,000 darts gave us clear evidence that the Monte Carlo method for approximating π is not very effective. 100,000 iterations give us a very imprecise result and takes a lot of time to do it. Though removing the graphical element from our program would certainly speed up our tests, we realized that other approximation methods (like Archimedes’ method) would be faster and more efficient.

Final Lessons

Computer ScienceThe program we wrote was certainly useful for learning code structures and applications. It also taught us two valuable lessons that can be applied to other areas of life:

First, even if the first solution works, we should keep looking for a better one. Our initial program worked just fine, but it required too many resources to justify its use. To find a better solution meant starting again with a better tool for approximation.

Second, failure can help lead us to the best solution. We spent a lot of time building our program, only to realize that it wasn’t a useful solution. It would be easy to think that our time was wasted and become discouraged. But our initial failure actually helped us realize a better solution.

Perhaps the most important lesson this lab taught us was that failure is a necessary part of learning, problem solving, and life in general.

Or as is commonly said in the world of digital making, the word fail is an acronym for First Attempt In Learning.

The AP Question The Mission in K4 (Part 1 of 2)

Related Posts

Academics, Friendship, Students, Vision

Preparation for Life: Living in Community at Petra Academy

Academics, Curriculum, Students, Uncategorized, Vision

Petra Academy: Educating the Whole Person

Academics, Faculty, Headmaster, Humanities, Students, Teachers, Uncategorized, Vision

Finding the Truth about Everything

Academics, Beauty, Faculty, Friendship, Headmaster, House, Parents, Students, Teachers, Uncategorized, Vision

When 80% Is Good Enough

Academics, Headmaster, Parents, Students, Teachers, Uncategorized, Vision, Volunteers

All Is Gift

Academics, Beauty, College, Curriculum, Faculty, Headmaster, Parents, Students, Teachers, Uncategorized, Vision

Classical Christian Education Alive & Well

Academics, Faculty, Headmaster, Parents, Survey, Teachers, Uncategorized, Vision

What Parents Want in a Christian School

Academics, Art, Beauty, Curriculum, Drama, Faculty, Uncategorized

Why We Love, Dramaturgically Speaking

Academics, School Choice, Students, Uncategorized

Educational Freedom

Academics, Beauty, College, Headmaster, History, Humanities, Parents, Recitation, Students, Teachers, Uncategorized, Vision

Recitation & the Progress of Humanity

Search

Recent Articles

  • Preparation for Life: Living in Community at Petra Academy Mar 24, 2020
  • Petra Academy: Educating the Whole Person Mar 18, 2020
  • An Investment Worth Making: Thursday, January 30 Jan 16, 2020
  • Buy Your Tickets for “The Odyssey” Oct 29, 2019
  • Confession of a Montana Headmaster Oct 14, 2019

Categories

  • Academics (54)
  • Art (13)
  • Athletics (3)
  • Beauty (30)
  • Church (3)
  • College (6)
  • Computer Science (3)
  • Curriculum (32)
  • Drama (8)
  • Faculty (28)
  • Friendship (7)
  • Headmaster (68)
  • History (16)
  • Holidays (11)
  • House (4)
  • Humanities (22)
  • Latin (3)
  • Memory (2)
  • Music (10)
  • News (1)
  • Parents (43)
  • Poetry (7)
  • Pre-Grammar (4)
  • Recitation (4)
  • Rhetoric (7)
  • School Choice (8)
  • Story (13)
  • Students (35)
  • Survey (3)
  • Teachers (18)
  • Testing (4)
  • Uncategorized (118)
  • Vision (40)
  • Volunteers (2)
Back To Top
Petra Academy, 4720 Classical Way, Bozeman, MT 59718
Telephone: (406) 582-8165 | Fax: (406) 556-8777 | Email: office@petraacademy.com
© 2019 Petra Academy. All rights reserved.
Privacy Policy | Terms of Use