Showing posts with label factorial. Show all posts
Showing posts with label factorial. Show all posts

Wednesday, November 18, 2015

Combinations - nCr


   In the previous post on Factorials I mentioned that I needed a factorial algorithm for a Combinations project and the Combinations project for a Random Walker project.
   As you can see in the formula for the number of combinations of n things taken r at a time with no duplications there are three factorials to compute to get to the nCr.
   This is a screenshot of the Combinations project. The graphic of the fruit is to illustrate that if n = 4 (the pear, orange, banana, and strawberry) then there are four combinations (shown in the four rows) when taken 3 at a time. The project first asks for n, then r and then computes nCr.
   The project can be viewed and downloaded by clicking on this link.
https://scratch.mit.edu/projects/88028765/
   A free document in PDF format describing the coding in more detail can be obtained on request. Send an email to grandadscience@gmail.com.


Friday, November 13, 2015

Factorial


   This project computes Factorial N written as N!
   Here is the definition of Factorial N.
    Writing code is not a one-step process. Over the years I've found that breaking the coding process into three parts helps students understand that first of all, coding is an exercise in problem-solving and breaking the coding problem into a series of smaller problems is the most efficient method for coding.
   Here are the three Parts and seven Steps I encourage students to use when coding.
   I Do the Math with Paper & Pencil Part
     • (1) Analyze the problem
   II Do the Algebraic Thinking Part
     • (2) Identify the variables
     • (3) Determine the relationships between the variables
   III Do the Algorithmic Thinking Part
     • (4) Create a Logic Flow diagram
     • (5) Translate the relationships (math syntax) into (computer
             syntax)
     • (6) Combine the pieces of code (into the algorithm that solves
        the problem)
     • (7) Test the algorithm (debug)
   I describe in detail how to apply this method to the problem of coding a Factorial algorithm in a six-page document. Any interested reader can obtain a copy of this copyright-free document in pdf format by sending an email to grandadscience@gmail.com
   Here is the opening screen of the project. The user is asked to input N! The number 11 was typed into the blue-lined box at the bottom of the screen.
   In this picture the computation of 11! is reported as 39,916,800.
   This project can be viewed and downloaded by clicking on the following link to the Scratch web site.
https://scratch.mit.edu/projects/87399897/