The Beauty and Joy of Computing 1 Lab Exercise 4: Starting a simple math tutor program and more interaction

Size: px
Start display at page:

Download "The Beauty and Joy of Computing 1 Lab Exercise 4: Starting a simple math tutor program and more interaction"

Transcription

1 The Beauty and Joy of Computing 1 Lab Exercise 4: Starting a simple math tutor program and more interaction Objectives By completing this lab exercise, you should learn to Create your own reporter and predicate blocks; Distinguish between three different scopes of BYOB variables: global, sprite local, and script local; Choose appropriate variable scope when writing BYOB programs; Describe and implement operations needed to add fractions; and Write programs that interact with the user through typed inputs. Background (Pre-Lab Reading) You should read this section before coming to the lab. It describes how various things work in BYOB and provides pictures that show what they look like in BYOB. You only need to read this material to get familiar with it. There is no need to actually do the actions described in this section, but you certainly can do them if it would help you follow along with the examples. The idea with this lab, and with the homework that follows up on this lab, it to create a math tutor program that teaches school kids about working with fractions: finding lowest common denominators and adding fractions. This lab is about doing the calculations, and your complete tutor program will combine these calculations with the stamping scripts from the previous lab so that a teacher can write problems on a board for students. Defining Your Own Reporter and Predicate Blocks In the last lab you learned about different types of blocks (command, reporter, and hat), and created some of your own command blocks. The distinguishing characteristic of a reporter block is that it reports a value since it produces a value, like a function in mathematics, many programming languages use the term functions rather than reporters. There are several functions that are useful, but are not provided by BYOB. For example, the maximum function, typically written as max(x,y) in mathematics, is useful in many situations, but is not provided as a block. As an example of defining a reporter block, we will define a block that reports the maximum of two numbers. We start the definition exactly as we did with command blocks in the last lab, and add two parameters (using our naming convention!) along with the title text. Like the built-in operators of +, -, etc., we won t give the parameters default values. The definition 1 Lab Exercises for The Beauty and Joy of Computing Copyright by Stephen R. Tate Creative Commons License See for more information

2 looks like this: Notice the report blocks that are used in the script and the report statement at the bottom of the window. The internal ones directly report a value (if px is larger it reports px; otherwise, it reports py). The report px at the bottom is the default return value if execution falls off the bottom of the script without a report block being found, this is the value that is reported. In this particular example definition there is no way this could happen, since we handle all cases directly with report blocks, but it is always a good idea to put a value here just in case. Now we have a max block that can be used just like any other operator block, which appears in the blocks palette like this: Predicate definitions are the same, but you have to select predicate when making the block so that it has the right shape. The following definition is an example of defining a predicate for less than or equal : The use of the default report value at the bottom is trickier than the previous example, and is vital to the correct functioning of this definition. It is worth your time to think this through until you understand how this definition works.

3 In the last lab you used one of your custom blocks ( stamp character ) to build up an even more complex block ( stamp string ). Using one of your blocks to build other blocks is common with reporter blocks as well. For example, you might define a block that reports the maximum of three numbers using the block we defined for the maximum of two values: we take the maximum of the first two values, and then the maximum of this value and the remaining input value. Here s the definition make sure you understand how this works: You have now seen examples of how you can Build Your Own Block to create a command, reporter, or predicate block. The activities you will do in the lab give you more practice with this, making blocks that simplify your work in an upcoming homework assignment (creating a simple math tutor). Scope of Variables Another topic in this pre-lab reading covers some issues related to variables that we have just glossed over up until now. The idea of a variable is simple, and you have used them for the previous two labs, but there are some details and subtleties that you should understand. We start with a simple scenario so that we can introduce the concepts: We are making a simple game that has a horse and a lion (which often play nicely together, right?), so we start by importing these sprites we ll give these names by changing Sprite1 and Sprite2 at the top of their sprite pane, and we ll name the horse Mr. Ed and the lion Simba. Once we create these, the sprites area shows both sprites with their names, like this: Next we want to declare some variables: Our game will have a score, which we will keep track of in a variable, and the amount of food and gold that the two characters have. To make the score variable, we go to the Variables category and click the Make a variable button, which pops up the window that allows us to give the variable the name score after doing that, this

4 is what the window looks like: Items in BYOB, including scripts, variables, and block definitions, can exist either everywhere (in which case we say they are global) or just in the context in which they are defined (in which case we say they are local to some context). In the very first lab, we talked about scripts defined with a sprite being local to the sprite, which means that they only apply to the sprite in which they are defined for example, in the Angry Alonzos script from Lab 2, Alonzo flew from one side of the screen to the other. But since that script was defined in Alonzo s script area it was local to Alonzo. If we wanted the dragon to fly like that, we could not use the script defined for Alonzo. In that situation we could copy Alonzo s script over to the dragon, but that just makes another local copy for the dragon any changes we make to the dragon s script would not change Alonzo s script and vice versa. We refer to the context in which something is defined to be the item s scope, which can either be global or local to some item like a sprite. The choice in the variable definition between For all sprites and For this sprite only chooses the scope of the variable: Either the variable is global, so it exists for all sprites, or it is local to this sprite. Our game has only a single score, not a score for each character, and all characters might need to access or change the score that means we need it to be global, and keep the For all sprites selection checked, and then click on OK. Next we define a variable for how much food, or hay, the horse Mr. Ed has. This only applies to the horse, so in this case we first select Mr. Ed as our current sprite, and then click Make a variable to define hay and select For this sprite only. We do the same thing for Simba, to create a variable called meat. The effect of this is immediately apparent: when we select the Mr. Ed sprite and look in the Variables category of the blocks palette, we see this: And when we select Simba, the top of the Variables category changes to look like this: Notice that when Mr. Ed was selected we saw the global variable score and his food variable hay (separated by a line global variables will always be above this line, and local variables

5 below), but we do not see Simba s variable meat. When we select Simba, we can still see the global variable score but now the only local variable we see is Simba s variable meat. Therefore, we have no access to Simba s meat variable when we are writing scripts for Mr. Ed, which makes sense. Finally, let s define a variable for the amount of gold each character has (lions and horses love gold!). We define a local gold variable for Mr. Ed, and then do the same for Simba, where these are local to their sprite since each sprite can have a different amount of gold. Now when we flip between the two sprites, the variable gold looks like it stays there, but it s below the line in the variable list: Below the line means it s a local variable, so despite the fact that you see the same name in both places there are actually two different gold variables: one for Mr. Ed and one for Simba. Since all of our variables are checked, they are all set as watch variables, and so are displayed on the stage: Looking at that display, it s clear that there s only one score (no context is given), but there s both a Mr. Ed gold and a Simba gold those are the two local gold variables, and the sprite name gives the context in which they are valid. While it s probably obvious if you think about it, you should be aware that when the set block is used in a sprite s scripts, it can only access global variables or local variables for that particular sprite. For example: When you create variables, you should follow what I ll call the Principle of Least Scope 2 : Define variables with the smallest possible scope. This means that if a variable can be local, then it should be local. There are two reasons for this: First, if you start defining lots of global variables, they appear in the Variables pane of every sprite in your program, so you will see all those variables (most of which might be completely 2 That s not a standard computer science phrase I just made it up but it s patterned after a common computer security concept known as the Principle of Least Privilege.

6 irrelevant to your sprite) and have to find a variable that you want that s confusing, and there s no good reason for it! The second reason is that global variables form connections between sprites: changing a global variable in one sprite may change the operation of a completely different sprite that uses the same global variable. If you can reduce the amount of connections between the behavior of your sprites, then when something goes wrong it is much easier to locate and fix the error. When you were defining your own blocks in the last lab, you were also given a choice between For all sprites and For this sprite only. This has the exact same effect as the scope of variables: a block may be general-purpose and apply to all sprites, in which case it should be global, or it could be something specific to just a single sprite, in which case it should be local. For example, both Mr. Ed and Simba might run, so there could be a global block defined for run, but then since only Mr. Ed eats hay there could be an eat hay block that would be for Mr. Ed only. If Mr. Ed is selected and you look at the blocks created this way, you will see this: (note that there is no nice global/local dividing line like there is for variables). If you select Simba, the eat hay block that is local to Mr. Ed disappears, but instead there might be a block that reflects Simba s eating preferences: Script Variables There is one more kind of variable, that we haven t used yet, but will be very useful for this lab: a script variable. A script variable has a very small scope, as it is only valid within the script in which it is defined. Consider this problem: In our game, gold is being produced faster and faster as the game progresses. In the first minute the game produces one bar of gold; in the second minute it produces two additional bars of gold; in the third minute it produces three more bars of gold, etc. So the total produced in the first 3 minutes is 1+2+3=6 bars of gold. We want to make a block that can tell us how many blocks of gold were produced in some time interval thinking abstractly about what we want, rather than how we are going to do it, we decide we want a reporter block that looks like this: This will report the value of the numbers from the low number to the high number, inclusive. So the block above reports the value of , or 10. This is a general operation, not tied to any specific sprite, so we d like to define this as a global block (i.e., For all sprites ). Identifying the operation we want to perform and how we want to use it, before actually worrying about the details of how the block will work or implementing it, is called top-down design. There s actually a formula for computing this sum, but let s pretend that we don t know that and that we need to actually add up the numbers in the range. To add up 1 to 4 we ll need something that counts and takes on the values 1, 2, 3, and 4 (that s one variable), and we ll need to keep track of the sum as we add each of these numbers in (that s another variable). In

7 fact, we ll use the counter pattern from the previous lab, but consider the variables (such as the counter) more carefully. Remember the Principle of Least Scope? We can t use a local sprite variable for this, since the block is to be used for any sprite, and we don t want to use a global variable for all the reasons that make the Principle of Least Scope a good idea. The answer to this dilemma is a special kind of variable called a script variable script variables have smaller scope than even sprite local variables, because they are only valid in the script in which they are defined and used (remember that a script is just a connected sequence of blocks, so a sprite may have multiple scripts). Script variables are most commonly used in a block definition, but they are not limited to that: regular scripts defined for a sprite can also have script variables. To create a script variable, you use the script variables block that is in the Variables category of the block palette, and looks like this: This block creates a script variable named a. The block also has a new feature that we haven t seen before: it takes a variable number of arguments. If you click on the arrow at the far right hand side of the block, it will add an additional argument. Here s what it looks like after we do that to create a second script variable, which BYOB calls b : At this point you can create more script variables, or delete the ones that are there (using the left arrow). Script variables come into existence when the script executes this script variables block, and disappear when the script containing this block finishes. The default names for script variables are a, b, etc. These are pretty horrible names, so you should always change the names of the script variables. Just like we did for parameters, we will use a naming convention for script variables: they should start with a lowercase s since a variable always represents some quantity, the rest of the name should reflect what it represents. For example, in our definition of the add from to block, we need the two variables described above, so we will name them scounter (for the counter that goes 1, 2, 3, 4) and ssum (which keeps track of the sum). To change the name of a variable, just click on it in the script variables block, and a pop-up window will allow you to set a new name. Let s get back to our problem of defining an add from to... block: We start defining the block as we ve done many times, giving it two parameters (pfirst and plast) with default values of 1 and 10, then we put in the script variables block and set the names of our script variables. The next thing we want to do is initialize our script variables, so we use a set block dragging it out and clicking on the drop-down menu to select the variable name, we see variables grouped by scope, separated by horizontal lines. It looks like this, where the scopes of variables are labeled

8 in our picture (they aren t labeled in BYOB): Notice that the parameters are actually script variables! That makes a lot of sense, because parameters are only meaningful in the script that defines the block to which they are parameters. An important point about script variables is that they come into existence when the script executes the script variables block, and don t exist outside of the script containing the script variables block. If you were to put a set block above the script variables block, it would not give you those variables as options, since they don t exist at that point in the script. The script variables will also not be available in scripts that are not connected to this one keep that in mind if you like to assemble multi-block components that you snap together later into a script, since anything separated from the script variables block will not have those variables available, even if you intend to combine it with the script variables block later! Now let s finish our block definition. The idea is simple extension of the counter pattern, but you should study the solution below to get comfortable with how this works. First, we limit the iteration not by a fixed number of iterations, but by a final value for the counter ( plast ). Second, we use the variable ssum to keep the running total as we count through the range from pfirst to plast. Finally, our block should report the sum. Putting these ideas together, we get the following solution (on the next page):

9 Adding a variable to a loop that keeps a running value is another very common computing pattern, and so this has a name: the accumulator pattern (you are accumulating the final answer in this case the sum). Make sure you fully understand how this script works! There s only one last thing to say about script variables: It is possible for a script variable to have the same name as either a global or a sprite variable. In other words, it s possible that we could have a global variable in our program named sum in addition to a script variable named sum. Despite the fact that these have the same name, and they look exactly alike when used in a script, they are two different variables. You can tell the difference in the set block because of the positioning within the drop-down menu, but in other parts of the code it s impossible to tell which variable you are using unless, you reliably follow our naming conventions! With the naming conventions, you know that a variable starting with an s is a script variable, and can t be global or sprite local. Hopefully you re starting to see the value of the naming convention. Tip: You can also get BYOB to help you see the scope by turning on the Scope Contrast option in BYOB s Edit menu. Why doesn t BYOB force script variables to have different names from other variables? There s actually a very good reason, and it has to do with abstraction: When we define a block, we should concentrate on the logic of that block, and not be concerned at all with what s going on outside that block definition the block definition should be entirely self-contained. If we say we have to avoid using the same name as a global or sprite variable, then we are not self-contained since we re thinking about things outside the block definition. You can also look at this from the other perspective, that of someone using the block. A programmer using the add from to block should not have to worry about the fact that certain variable names are used inside the block definition. Good block definitions are self-contained abstractions, where the user of the block only needs to be concerned about what the block does, and should not have to think at all about how the block does its work. By using our naming convention, we get the same useful

10 benefit of BYOB forcing the names to be different, without BYOB trying to enforce its own view of how you should think about things. Now you know almost everything there is to know about variables in BYOB! Math Background for Lab 4 The goal of this lab and the following homework assignment is to create a simple math tutor program, that helps school kids learn about and practice adding fractions. While you are free to have your tutor program explain adding fractions in any way that is sensible, the underlying code of this assignment will need to add fractions as well, and should take the specific approach that we describe here. For example, let s say that we want to compute the sum 5/6 + 6/15. We need to convert these fractions so that they have a common denominator, so this sum is the same as 25/ /30, at which point we can add numerators and get the sum of 37/30. How do we describe this algorithmically, so we can do this computation in our program? We can compute everything we need if we can compute the greatest common divisor, or GCD, of the denominators. The greatest common divisor is the largest integer that divides evenly into the two values, so in our case we find that the GCD of 6 and 15 is 3, which we typically write as GCD(6,15)=3. You ll have to define a block for computing the GCD in Activity 1 below, but you should think a little about how you could do it now: think of starting at the largest possible value of the GCD and decreasing it until it divides evenly into both numbers. So we could start at 6 and ask does 6 divide evenly into 6 and 15? 6 doesn t divide evenly into 15, so we decrease it and try 5. 5 doesn t divide evenly into 6, so we step down to 4. That doesn t divide evenly into either number, so we go down to 3. That one works, and since we were counting down and we stopped at the first common divisor, we know we have the greatest possible divisor. This is tedious if you do it by hand, but tedious calculations are exactly the thing that computers are good at! Note that there are much more efficient ways to compute the GCD, but this simple technique is all we need for this lab exercise. Now that you can compute GCD s, how does that help you find common denominators? That turns out to be easy! Let s say we re adding a/x + b/y, where a, b, x, and y are all integers. The two denominators are x and y, and we use g to denote the GCD of these values (so GCD(x,y)=g). Now we know that g divides evenly into both x and y, so x y g is an integer, which happens to be the lowest common denominator! Why? We can compute y/g (remember, g divides y, so this is an integer), and multiply the fraction a/x by y/ g. This gives y/ g a ( y / g ) x ( y / g) for the first fraction. For the second fraction, we multiply by an integer), so the second fraction becomes b (x / g ) y ( x / g) denominator x y g x/ g x/ g (note that x/g is, and both fractions have the common. Solving one problem (finding lowest common denominators) by turning it

11 into a related problem (GCD) is called a reduction we will say more about this in the Discussion section. Putting our example in this context: we have 5/6 + 6/15, so a=5, b=6, x=6, and y=15. We figured out above that GCD(6,15)=3, so g=3. To adjust the first fraction, we compute y/g = 15/3 = 5, and multiply the first fraction by 5/5 to get 5*5 / 6*5 = 25/30. For the second fraction, we compute x/g = 6/3 = 2, and multiply the second fraction by 2/2 to get 6*2 / 15*2 = 12/30. Now that both are over the common denominator of 30, we can add numerators to get (25+12)/30 = 37/30. You may not have done additions of fractions by computing GCDs in the past, but the nice thing about this approach is that once you know the GCD of the two denominators, computing everything else is easy! Hopefully all of this was clear to you work through the practice problems below in Self-Assessment Questions to practice and make sure you see how things work out. Self-Assessment Questions Use these questions to test your understanding of the Background reading. Answers can be found at the end of the lab exercise. 1. What scope variable would you use to keep track of the time remaining in a game? 2. What scope variable would you use to keep track of the amount of silver that a character has? 3. If characters can have gold, copper, and silver, and you created a reporter block to report their net worth adding up the value of all their different kinds of treasure what scope variable would you use for adding up this value? 4. Consider the following BYOB block definition what does this report when called with argument 5 (as shown on the right)? Can you describe at a high level what this block computes (remember to focus on what it computes how it does so is irrelevant)? Let s say that the programmer wanted to see

12 what the value of scounter was after the loop ran, and so somehow managed to create this code: What s wrong with this? 5. In the following picture, the script on the left is defined in Alonzo s scripts area, and the part on the right shows how the block some block is defined: What does Alonzo say when this is run? Before you spend too much time trying to figure that out, think of non-traditional answers this is actually something of a trick question. If you figure that hint out, can you describe what the problem is here? What should have been done to avoid this problem? 6. Walk through the steps of adding the fractions 2/3 + 3/4 using the technique described above. List out each step: What is g? Show how you use g to calculate what each fraction is multiplied by, and then show the final sum. 7. Walk through the steps of adding the fractions 5/6 + 3/10 using the technique described above. List out each step: What is g? Show how you use g to calculate what each fraction is multiplied by, and then show the final sum. Activities (In-Lab Work) Activity 1: For this activity, you should make a reporter block that computes the greatest common divisor of two integers. Your reporter block should look like the following (shown displaying the GCD of 6 and 15): Hint: The Math Background for Lab 4 section in the Pre-Lab Reading described a simple algorithm, or technique, for computing the GCD of two integers. This involves testing if one number divides evenly into another, which you know how to do if you think about it: asking whether x divides evenly into y is the same thing as asking whether y mod x is 0 (i.e., the remainder of the division is 0). The GCD solution involves counting down in a loop, very, very similar to the way we counted up in the sum of block in the first part of the Pre-Lab reading.

13 Figuring out when this loop should stop is a little more difficult, but consider how easy it would be if you had a block of the following form: If you define this block first so that you can use it in your GCD definition, it will simplify this activity greatly! There are several ways you could define this block. You can actually do it with just a couple of if blocks, or alternatively you could consider using the and block, which is a Boolean operator. Boolean operators are things like and, or, and not, and their use corresponds to regular English usage (we ll say a little more about Boolean operators in the Discussion section below). We used and in the name of the block, so consider a test that looks like this (for appropriate definitions of x, y, and z): You ll need to fill in the parts that correspond to dividing evenly (remember the mod block!) if you want to use this alternative, but if you figure that out then the definition is pretty simple! Save your complete solution as Lab4-Activity1. Activity 2: Use the technique described in the Math Background section to create a reporter block that finds that lowest common denominator for two integers. It should look like the following: Save your solution to this activity as Lab4-Activity2. Activity 3: In this activity, you will create a reporter block that takes 4 parameters, defining two fractions, and computes the numerator of the sum of these (so, taken together with the block from the previous activity, you should be able to compute the sum, both numerator and denominator), of any two fractions. You do not need to worry about putting fractions in lowest terms. Here s an example of what this block should look like: Save your solution to this activity as Lab4-Activity3. Activity 4: This activity does not build on the previous ones after you re sure the previous activity has been saved, start a new project in BYOB to clear out your previous work.

14 For the last activity in this lab, you will make a number guessing game so that you can practice using two new blocks: the ask block and the join block. Here are the basics of what you will do: create a game in which a character (you can use Alonzo or whatever character you want) picks a random number between 1 and 10, and asks the player to guess the number. The ask... block is in the Sensing category of the blocks palette when executed, it draws a dialog talking bubble for the character (like the say block) and provides an input box for the user to type an answer. You can test what the user typed by using the answer variable that is right below the ask block in the blocks palette, and your character should say either Too low, Too high, or You got it! My number was 4 (where 4 is replaced with the actual number). For that last message, you need to combine a fixed text string ( You got it! My number was ) with the value of a variable (the secret number), and display all of that together using a say block. Remember the join block that you used in the last lab? This is a great place to use it again, doing something like this: Finally, you should use a repeat loop to allow the user to keep guessing until they get the answer correct. The only requirements for this activity are a number guessing game that repeatedly says too low or too high until the number is guessed, with at least one use of the join block in an argument to say. You are encouraged to be creative in the time you have for this activity: use different characters, change the dialog messages (as long as they fit the minimum requirements of the game), have a celebratory animation when the number is guessed correctly, or anything else you can think of. When you complete this activity, save your final program as Lab4-Game. Submission In this lab, you should have saved the following files: Lab4-Activity1, Lab4-Activity2, Lab4- Activity3, and Lab4-Game. In this lab, activities 2 and 3 do not destroy work in the previous activities, so if Lab4-Activity3 contains all of your work from the previous activities, you do not need to turn in Lab4-Activity1 or Lab4-Activity2. Turn these in using whatever submission mechanism your school has set up for you. Discussion (Post-Lab Follow-up) Reduction: In doing the math for adding fractions, the problem of finding the lowest common denominator was solved by computing a greatest common divisor and then transforming the result using some simple formulas. In other words, all of the real computational effort was done in the GCD function, and then we just did a few minor calculations to turn the answer into what we originally wanted (the lowest common denominator). This is called a computational reduction (or just reduction when it s clear that you re talking about a computational reduction), and we say that we have reduced the problem of computing lowest common denominators to the problem of computing greatest common divisors. Unfortunately, the word reduce has different meanings in different contexts: At the end of the Math Background section we noted that you can reduce a fraction to lowest terms using the GCD function, which is an entirely different use of the word reduce that has absolutely nothing to do with

15 computational reductions. Yes, this is confusing, and I m about to make it even more confusing. Since we turned the problem of reducing a fraction into the problem of computing a GCD (plus a couple of additional divisions), we have reduced the problem of reducing a fraction to the problem of computing a GCD. Did you get that? It s unfortunate terminology in this case, but it does make sense if you think it through, and it s worth your time to figure out what that sentence means! As a final comment, notice that we reduced two different problems on fractions to a single core problem, that of computing a GCD. When you can do this in a program it is fantastic news! You put the complicated computation into one function, which you can write and test thoroughly, and then you can use that one well-tested solution to solve your other problems. Top-down design: When we introduced the add from to block above, that block was driven by a higher-level need in the system. Starting from a system-level perspective and figuring out what building blocks or components you need for the system, and then figuring out the building blocks you need to build those components, and so on, is what we refer to as topdown design. This is pretty much identical to the notion of problem decomposition that we described in Lab 1, but people tend to use the phrase problem decomposition for small-scale problems, and top-down design when designing complex systems. The opposite of top-down design is bottom-up design, which means starting at the lowest building blocks, and assembling things until you have something interesting you start with the simple pieces and build more and more complex objects. While top-down design and bottom-up design are the common terminology in computer science, in other areas of design top-down design is referred to as decomposition and bottom-up design is referred to as synthesis. Boolean Operators: Boolean operators are operators that work on truth values: true or false. The term Boolean (also used in Boolean Algebra and Boolean Logic ) comes from George Boole, a mathematician who lived in the 1800 s and developed much of the logic that is used in computers today. The main Boolean operators provided by BYOB are and, or, and not. We can define what these operators do using truth tables, which give the value of a Boolean operator for any possible value of the inputs. For example, the truth table for the and operator is shown below: x y x AND y false false false false true false true false false true true true So if x is true and y is false, then x AND y is false. In BYOB terms, if the and block is called with the true as the first argument and false as the second argument, then the and block reports false. In fact, the only way for x AND y to be true is if both x and y are true matching the common English understanding of the word and. The truth table for or is as follows: x y x OR y false false false

16 false true true true false true true true true This matches our intuition about the word or except for one possible case. In some cases, the English language use of or means one thing or another, but not both. For example, I might say I will go to the movies or I will study, which means that I will do exactly one of those actions, but not both. In a Boolean or the answer is true if either of the arguments is true but it is also true if both arguments are true! There is a special kind of or that more closely matches the either-one-or-the-other meaning, and in Boolean logic that is called an exclusive-or. While the exclusive-or is very useful in some situations, it is not provided by BYOB and is not something we will need in this class. Finally, the not operator takes a single parameter and flips it: true becomes false, and false becomes true. This can be very useful in some situations. For example, while we noted in the activities above that there is no less than or equal to in BYOB, the following is entirely equivalent to a predicate that tests if x is less than or equal to y can you see why? Boolean operators can be very powerful, but the basics are simple. If you study discrete mathematics or logic you will learn much more about how these operators work together. Terminology accumulator pattern: A programming pattern that loops through values and updates a running value, like a running sum, running maximum, etc. Boolean operator: An operator that works on true/false values, such as and, or, and not. bottom-up design: Constructing components from basic operations, and building more complex components from those, and so on until a complete system is built from the bottom up. computatoinal reduction (or reduction): Using the solution to one computational problem ( Problem A ) to solve another one ( Problem B ), typically with a small amount of computation to convert the inputs for Problem B into inputs for Problem A, and/or a small amount of computation to convert the output from Problem A into the output for Problem B. exclusive-or: A special form of the or Boolean operator that is false if both arguments are true (unlike a regular Boolean or which is true in that situation). global: A computational item like a variable or block that is available from all parts of a program. local: A computational item like a variable or a block that is available only in a particular context, where the context can be a particular sprite or a particular script. principle of least scope: The program design principle that says that you should always use the smallest possible scope for a variable so, in particular, global variables should only be used as a last resort.

17 reduce: In the description of computational reduction above, we say that we reduce Problem B (the problem we want to solve) to Problem A (the problem we have a solution to). scope: The parts of a program in which an item (like a variable or block) is defined and available. script variable: A variable with very small scope: it is only available from the point that it is defined (using a script variable block) until the end of that script. top-down design: Designing a program by starting at the top, system level, deciding what components are needed to make the system work, and further breaking those components down into smaller pieces. truth table: A table that shows the value of a Boolean expression for all possible values of inputs. Answers to Pre-Lab Self-Assessment Questions 1. What scope variable would you use to keep track of the time remaining in a game? Answer: Global. A value associated with the game as a whole, and not with a specific sprite, needs to be global. 2. What scope variable would you use to keep track of the amount of silver that a character has? Answer: Sprite local. This can t be local to a script or a block definition, since it s a longterm value (existing beyond the time that a specific script is running). It can be sprite local, and so it should be (as opposed to global) according the principle of least scope. 3. If characters can have gold, copper, and silver, and you created a reporter block to report their net worth adding up the value of all their different kinds of treasure what scope variable would you use for adding up this value? Answer: Script local. The variable used to add up the value is only needed temporarily, while the script is running. Therefore, it should be a script variable (scope script local). 4. Consider the following BYOB block definition [see questions for the picture] what does this report when called with argument 5 (as shown on the right)? Answer: It reports 32. You can figure this out by tracing through the code. When the block is called, pvalue becomes 5. Before we reach the loop, variable scounter is set to 1 and sresult is set to 1. Next, we hit the repeat loop since scounter (with value 1) is not greater than pvalue (with value 1), we execute the blocks inside the loop which change sresult to 2*1=2, and changes scounter to 2 (changed by 1 from previous value). Then we check the condition and see that scounter (now 2) is still not greater than pvalue (still 5), so we need to execute the blocks inside the loop again. We continue this way until the loop exits, and we summarize this tracing as follows: After next loop iteration: sresult = 2*2 = 4 ; scounter = 2+1 = 3 scounter is not > 5, so loop again giving: sresult = 2*4 = 8 ; scounter = 3+1 = 4 scounter is not > 5, so loop again giving: sresult = 2*8 = 16 ; scounter = 4+1 = 5 scounter is not > 5, so loop again giving: sresult = 2*16 = 32 ; scounter = 5+1 = 6

18 And now, scounter is > sresult, so we stop the loop iteration, reporting sresult (current value is 32). Can you describe at a high level what this block computes (remember to focus on what it computes how it does so is irrelevant)? Answer: It computes 2 pvalue (two to the power of the argument). Let s say that the programmer wanted to see what the value of scounter was after the loop ran, and so somehow managed to create this code: What s wrong with this? Answer: The variable scounter doesn t exist outside the script in the definition of mystery that means that this variable doesn t exist in this context! If it were possible to make this code, it must mean that there is a different variable named scounter (not the script variable we re interested in) that this is accessing. 5. In the following picture, the script on the left is defined in Alonzo s scripts area, and the part on the right shows how the block some block is defined [see questions for picture]. What does Alonzo say when this is run? Before you spend too much time trying to figure that out, think of non-traditional answers this is actually something of a trick question. If you figure that hint out, can you describe what the problem is here? What should have been done to avoid this problem? Answer: It s actually impossible to tell what it would say from these pictures. Is the value argument to the say block the global variable value or the parameter value? These are two different variables, even though they look the same. If this is the global variable, Alonzo would say 12. If this is the parameter, then Alonzo would say 32. If we had followed our naming convention we would never have gotten into this situation, since the parameter would be named something like pvalue and it would be clear whether the say block was using the global variable or the parameter. 6. Walk through the steps of adding the fractions 2/3 + 3/4 using the technique described above. List out each step: What is g? Show how you use g to calculate what each fraction is multiplied by, and then show the final sum. Answer: We first compute g, which is the GCD of denominators 3 and 4 for these values, g=1. Next, we multiply both numerator and denominator of 2/3 by 4/g=4, so we get (2*4)/(3*4) = 8/12. We adjust the second fraction similarly, multiplying numerator and denominator of 3/4 by 3/g=3, so we get (3*3)/(4*3) = 9/12. Finally we can directly add 8/12 + 9/12 to get 17/12, which is the final answer. 7. Walk through the steps of adding the fractions 5/6 + 3/10 using the technique described above. List out each step: What is g? Show how you use g to calculate what each fraction is multiplied by, and then show the final sum.

19 Answer: We first compute g, which is the GCD of denominators 6 and 10 for these values, g=2. Next, we multiply both numerator and denominator of 5/6 by 10/g=5, so we get (5*5)/(6*5) = 25/30. We adjust the second fraction similarly, multiplying numerator and denominator of 3/10 by 6/g=3, so we get (3*3)/(10*3) = 9/30. Finally we can directly add 25/30 + 9/30 to get 34/30, which is the final answer. Note that we could reduce this to lowest terms by computing the GCD of 34 and 30 (which is 2), and dividing each number by 2 resulting in 17/15. See how useful being able to compute GCDs is?

n! = 1 * 2 * 3 * 4 * * (n-1) * n

n! = 1 * 2 * 3 * 4 * * (n-1) * n The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are

More information

The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication

The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication Objectives By completing this lab exercise, you should learn to understand the basic user interface

More information

The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion - Python version

The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion - Python version The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion - Python version Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems

More information

MAT 003 Brian Killough s Instructor Notes Saint Leo University

MAT 003 Brian Killough s Instructor Notes Saint Leo University MAT 003 Brian Killough s Instructor Notes Saint Leo University Success in online courses requires self-motivation and discipline. It is anticipated that students will read the textbook and complete sample

More information

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Variable is a letter or symbol that represents a number. Variable (algebraic)

More information

Fractions and their Equivalent Forms

Fractions and their Equivalent Forms Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

Excerpt from Art of Problem Solving Volume 1: the Basics 2014 AoPS Inc. Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10.

Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 10. PA Ch 5 Rational Expressions Rational Number is a number that can be written as a quotient of two integers. DECIMALS are special fractions whose denominators are powers of 0. Since decimals are special

More information

9. MATHEMATICIANS ARE FOND OF COLLECTIONS

9. MATHEMATICIANS ARE FOND OF COLLECTIONS get the complete book: http://wwwonemathematicalcatorg/getfulltextfullbookhtm 9 MATHEMATICIANS ARE FOND OF COLLECTIONS collections Collections are extremely important in life: when we group together objects

More information

Part 1. Summary of For Loops and While Loops

Part 1. Summary of For Loops and While Loops NAME EET 2259 Lab 5 Loops OBJECTIVES -Understand when to use a For Loop and when to use a While Loop. -Write LabVIEW programs using each kind of loop. -Write LabVIEW programs with one loop inside another.

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

More information

Fractions and their Equivalent Forms

Fractions and their Equivalent Forms Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda

More information

SPRITES Moving Two At the Same Using Game State

SPRITES Moving Two At the Same Using Game State If you recall our collision detection lesson, you ll likely remember that you couldn t move both sprites at the same time unless you hit a movement key for each at exactly the same time. Why was that?

More information

SCRATCH MODULE 3: NUMBER CONVERSIONS

SCRATCH MODULE 3: NUMBER CONVERSIONS SCRATCH MODULE 3: NUMBER CONVERSIONS INTRODUCTION The purpose of this module is to experiment with user interactions, error checking input, and number conversion algorithms in Scratch. We will be exploring

More information

Table of Laplace Transforms

Table of Laplace Transforms Table of Laplace Transforms 1 1 2 3 4, p > -1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Heaviside Function 27 28. Dirac Delta Function 29 30. 31 32. 1 33 34. 35 36. 37 Laplace Transforms

More information

1) Complete problems 1-65 on pages You are encouraged to use the space provided.

1) Complete problems 1-65 on pages You are encouraged to use the space provided. Dear Accelerated Pre-Calculus Student (017-018), I am excited to have you enrolled in our class for next year! We will learn a lot of material and do so in a fairly short amount of time. This class will

More information

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra

Topic 3: Fractions. Topic 1 Integers. Topic 2 Decimals. Topic 3 Fractions. Topic 4 Ratios. Topic 5 Percentages. Topic 6 Algebra Topic : Fractions Topic Integers Topic Decimals Topic Fractions Topic Ratios Topic Percentages Duration / weeks Content Outline PART (/ week) Introduction Converting Fractions to Decimals Converting Decimals

More information

Congruence Arithmetic

Congruence Arithmetic Module 4 Congruence Arithmetic Popper 4 Introduction to what is like Modulus choices Partitions by modulus Mod 5 Mod 7 Mod 30 Modular Arithmetic Addition Subtraction Multiplication INTEGERS! Mod 12 Cayley

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently. The Science of Computing I Lesson 4: Introduction to Data Structures Living with Cyber Pillar: Data Structures The need for data structures The algorithms we design to solve problems rarely do so without

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Lecture Transcript While and Do While Statements in C++

Lecture Transcript While and Do While Statements in C++ Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some

More information

Pre-Algebra Notes Unit Five: Rational Numbers and Equations

Pre-Algebra Notes Unit Five: Rational Numbers and Equations Pre-Algebra Notes Unit Five: Rational Numbers and Equations Rational Numbers Rational numbers are numbers that can be written as a quotient of two integers. Since decimals are special fractions, all the

More information

Pre-Algebra Notes Unit Five: Rational Numbers and Equations

Pre-Algebra Notes Unit Five: Rational Numbers and Equations Pre-Algebra Notes Unit Five: Rational Numbers and Equations Rational Numbers Rational numbers are numbers that can be written as a quotient of two integers. Since decimals are special fractions, all the

More information

Implementing an Algorithm for Boomerang Fraction Sequences in Python

Implementing an Algorithm for Boomerang Fraction Sequences in Python Introduction Implementing an Algorithm for Boomerang Fraction Sequences in Python We ve all encountered maze problems, where the challenge is to find a path through a labyrinth from a starting point to

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word

Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word Teacher Activity: page 1/9 Mathematical Expressions in Microsoft Word These instructions assume that you are familiar with using MS Word for ordinary word processing *. If you are not comfortable entering

More information

Fractions and their Equivalent Forms

Fractions and their Equivalent Forms Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda

More information

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below. Graphing in Excel featuring Excel 2007 1 A spreadsheet can be a powerful tool for analyzing and graphing data, but it works completely differently from the graphing calculator that you re used to. If you

More information

Math 7 Notes Unit Three: Applying Rational Numbers

Math 7 Notes Unit Three: Applying Rational Numbers Math 7 Notes Unit Three: Applying Rational Numbers Strategy note to teachers: Typically students need more practice doing computations with fractions. You may want to consider teaching the sections on

More information

Excel Basics: Working with Spreadsheets

Excel Basics: Working with Spreadsheets Excel Basics: Working with Spreadsheets E 890 / 1 Unravel the Mysteries of Cells, Rows, Ranges, Formulas and More Spreadsheets are all about numbers: they help us keep track of figures and make calculations.

More information

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and

More information

How Your First Program Works

How Your First Program Works How Your First Program Works Section 2: How Your First Program Works How Programs Are Structured...19 Method Main ( )...21 How Programs Are Structured In Section 1, you typed in and ran your first program

More information

Properties and Definitions

Properties and Definitions Section 0.1 Contents: Operations Defined Multiplication as an Abbreviation Visualizing Multiplication Commutative Properties Parentheses Associative Properties Identities Zero Product Answers to Exercises

More information

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14 600.363 Introduction to Algorithms / 600.463 Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14 23.1 Introduction We spent last week proving that for certain problems,

More information

Pre-Algebra Notes Unit Five: Rational Numbers and Equations

Pre-Algebra Notes Unit Five: Rational Numbers and Equations Pre-Algebra Notes Unit Five: Rational Numbers and Equations Rational Numbers Rational numbers are numbers that can be written as a quotient of two integers. Since decimals are special fractions, all the

More information

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list?

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list? 1 Practice problems Here is a collection of some relatively straightforward problems that let you practice simple nuts and bolts of programming. Each problem is intended to be a separate program. 1. Write

More information

MITOCW watch?v=kz7jjltq9r4

MITOCW watch?v=kz7jjltq9r4 MITOCW watch?v=kz7jjltq9r4 PROFESSOR: We're going to look at the most fundamental of all mathematical data types, namely sets, and let's begin with the definitions. So informally, a set is a collection

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a

More information

(Python) Chapter 3: Repetition

(Python) Chapter 3: Repetition (Python) Chapter 3: Repetition 3.1 while loop Motivation Using our current set of tools, repeating a simple statement many times is tedious. The only item we can currently repeat easily is printing the

More information

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed. Preface Here are my online notes for my Algebra course that I teach here at Lamar University, although I have to admit that it s been years since I last taught this course. At this point in my career I

More information

Procedures: Algorithms and Abstraction

Procedures: Algorithms and Abstraction Procedures: Algorithms and Abstraction 5 5.1 Objectives After completing this module, a student should be able to: Read and understand simple NetLogo models. Make changes to NetLogo procedures and predict

More information

First-Order Translation Checklist

First-Order Translation Checklist CS103 Winter 2019 First-Order Translation Checklist Cynthia Lee Keith Schwarz In this handout, we ve distilled five specific points that you should check in your first-order logic statements before submitting

More information

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read)

What is version control? (discuss) Who has used version control? Favorite VCS? Uses of version control (read) 1 For the remainder of the class today, I want to introduce you to a topic we will spend one or two more classes discussing and that is source code control or version control. What is version control?

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

Module 2 Congruence Arithmetic pages 39 54

Module 2 Congruence Arithmetic pages 39 54 Module 2 Congruence Arithmetic pages 9 5 Here are some excellent websites that can help you on this topic: http://mathcentral.uregina.ca/qq/database/qq.09.98/kupper1.html http://nrich.maths.org/public.viewer.php?obj_id=50

More information

JMC 2015 Teacher s notes Recap table

JMC 2015 Teacher s notes Recap table JMC 2015 Teacher s notes Recap table JMC 2015 1 Number / Adding and subtracting integers Number / Negative numbers JMC 2015 2 Measuring / Time units JMC 2015 3 Number / Estimating Number / Properties of

More information

Lecture 3: Linear Classification

Lecture 3: Linear Classification Lecture 3: Linear Classification Roger Grosse 1 Introduction Last week, we saw an example of a learning task called regression. There, the goal was to predict a scalar-valued target from a set of features.

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

Learn Ninja-Like Spreadsheet Skills with LESSON 9. Math, Step by Step

Learn Ninja-Like Spreadsheet Skills with LESSON 9. Math, Step by Step EXCELL MASTERY Learn Ninja-Like Spreadsheet Skills with LESSON 9 Doing Math, Step by Step It s Elementary, My Dear Ninja There is a scene in the short story The Crooked Man, where Sherlock Holmes accurately

More information

(Refer Slide Time 3:31)

(Refer Slide Time 3:31) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions

More information

Intro. Speed V Growth

Intro. Speed V Growth Intro Good code is two things. It's elegant, and it's fast. In other words, we got a need for speed. We want to find out what's fast, what's slow, and what we can optimize. First, we'll take a tour of

More information

Pre-Algebra Notes Unit One: Variables, Expressions, and Integers

Pre-Algebra Notes Unit One: Variables, Expressions, and Integers Pre-Algebra Notes Unit One: Variables, Expressions, and Integers Evaluating Algebraic Expressions Syllabus Objective: (.) The student will evaluate variable and numerical expressions using the order of

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function?

Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function? Meeting 1 Introduction to Functions Part 1 Graphing Points on a Plane (REVIEW) A plane is a flat, two-dimensional surface. We describe particular locations, or points, on a plane relative to two number

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

EC121 Mathematical Techniques A Revision Notes

EC121 Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes Mathematical Techniques A begins with two weeks of intensive revision of basic arithmetic and algebra, to the level

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

Basics of Computational Geometry

Basics of Computational Geometry Basics of Computational Geometry Nadeem Mohsin October 12, 2013 1 Contents This handout covers the basic concepts of computational geometry. Rather than exhaustively covering all the algorithms, it deals

More information

COMP combinational logic 1 Jan. 18, 2016

COMP combinational logic 1 Jan. 18, 2016 In lectures 1 and 2, we looked at representations of numbers. For the case of integers, we saw that we could perform addition of two numbers using a binary representation and using the same algorithm that

More information

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software.

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software. Welcome to Basic Excel, presented by STEM Gateway as part of the Essential Academic Skills Enhancement, or EASE, workshop series. Before we begin, I want to make sure we are clear that this is by no means

More information

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression

Outline. Announcements. Homework 2. Boolean expressions 10/12/2007. Announcements Homework 2 questions. Boolean expression Outline ECS 10 10/8 Announcements Homework 2 questions Boolean expressions If/else statements State variables and avoiding sys.exit( ) Example: Coin flipping (if time permits) Announcements Professor Amenta

More information

4. Java Project Design, Input Methods

4. Java Project Design, Input Methods 4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

More information

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program. Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 Euclid's Algorithm

More information

Math Fundamentals for Statistics (Math 52) Unit 3: Addition and Subtraction. Scott Fallstrom and Brent Pickett The How and Whys Guys.

Math Fundamentals for Statistics (Math 52) Unit 3: Addition and Subtraction. Scott Fallstrom and Brent Pickett The How and Whys Guys. Math Fundamentals for Statistics (Math 52) Unit 3: Addition and Subtraction Scott Fallstrom and Brent Pickett The How and Whys Guys Unit 3 Page 1 3.1: Place Value (Addition Preview) Our system is a base-ten,

More information

Mathematics. Name: Class: Transforming Life chances

Mathematics. Name: Class: Transforming Life chances Mathematics Name: Class: Transforming Life chances Children first- Aspire- Challenge- Achieve Aspire: To be the best I can be in everything that I try to do. To use the adults and resources available both

More information

DECIMALS are special fractions whose denominators are powers of 10.

DECIMALS are special fractions whose denominators are powers of 10. Ch 3 DECIMALS ~ Notes DECIMALS are special fractions whose denominators are powers of 10. Since decimals are special fractions, then all the rules we have already learned for fractions should work for

More information

Lesson 12: Order and Compare with Benchmarks

Lesson 12: Order and Compare with Benchmarks Lesson 12: Order and Compare with Benchmarks Objective By the end of the lesson, students will be able to order and compare fractions with like and unlike denominators, using the definition for equivalent

More information

Variables and Data Representation

Variables and Data Representation You will recall that a computer program is a set of instructions that tell a computer how to transform a given set of input into a specific output. Any program, procedural, event driven or object oriented

More information

Starting Boolean Algebra

Starting Boolean Algebra Boolean Algebra March 2, 27 Diagram for FunChip2 Here is a picture of FunChip2 that we created more or less randomly in class on /25 (used in various Activities): Starting Boolean Algebra Boolean algebra

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

6.001 Notes: Section 4.1

6.001 Notes: Section 4.1 6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

COPYRIGHTED MATERIAL. Starting Strong with Visual C# 2005 Express Edition

COPYRIGHTED MATERIAL. Starting Strong with Visual C# 2005 Express Edition 1 Starting Strong with Visual C# 2005 Express Edition Okay, so the title of this chapter may be a little over the top. But to be honest, the Visual C# 2005 Express Edition, from now on referred to as C#

More information

Unit 4: Multiplication

Unit 4: Multiplication Math Fundamentals for Statistics I (Math 52) Unit 4: Multiplication By Scott Fallstrom and Brent Pickett The How and Whys Guys This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike

More information

COMP 161 Lecture Notes 16 Analyzing Search and Sort

COMP 161 Lecture Notes 16 Analyzing Search and Sort COMP 161 Lecture Notes 16 Analyzing Search and Sort In these notes we analyze search and sort. Counting Operations When we analyze the complexity of procedures we re determine the order of the number of

More information

Watkins Mill High School. Algebra 2. Math Challenge

Watkins Mill High School. Algebra 2. Math Challenge Watkins Mill High School Algebra 2 Math Challenge "This packet will help you prepare for Algebra 2 next fall. It will be collected the first week of school. It will count as a grade in the first marking

More information

What we still don t know about addition and multiplication

What we still don t know about addition and multiplication What we still don t know about addition and multiplication Carl Pomerance, Dartmouth College Hanover, New Hampshire, USA Michigan State University, October 11, 2016 You would think that all of the issues

More information

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System

Course Learning Outcomes for Unit I. Reading Assignment. Unit Lesson. UNIT I STUDY GUIDE Number Theory and the Real Number System UNIT I STUDY GUIDE Number Theory and the Real Number System Course Learning Outcomes for Unit I Upon completion of this unit, students should be able to: 2. Relate number theory, integer computation, and

More information

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via by Friday, Mar. 18, 2016

Math Dr. Miller - Constructing in Sketchpad (tm) - Due via  by Friday, Mar. 18, 2016 Math 304 - Dr. Miller - Constructing in Sketchpad (tm) - Due via email by Friday, Mar. 18, 2016 As with our second GSP activity for this course, you will email the assignment at the end of this tutorial

More information

COMP-202 Unit 4: Programming with Iterations

COMP-202 Unit 4: Programming with Iterations COMP-202 Unit 4: Programming with Iterations Doing the same thing again and again and again and again and again and again and again and again and again... CONTENTS: While loops Class (static) variables

More information

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology.

In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. Guide to and Hi everybody! In our first lecture on sets and set theory, we introduced a bunch of new symbols and terminology. This guide focuses on two of those symbols: and. These symbols represent concepts

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

For Module 2 SKILLS CHECKLIST. Fraction Notation. George Hartas, MS. Educational Assistant for Mathematics Remediation MAT 025 Instructor

For Module 2 SKILLS CHECKLIST. Fraction Notation. George Hartas, MS. Educational Assistant for Mathematics Remediation MAT 025 Instructor Last Updated: // SKILLS CHECKLIST For Module Fraction Notation By George Hartas, MS Educational Assistant for Mathematics Remediation MAT 0 Instructor Assignment, Section. Divisibility SKILL: Determine

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

MAT 090 Brian Killough s Instructor Notes Strayer University

MAT 090 Brian Killough s Instructor Notes Strayer University MAT 090 Brian Killough s Instructor Notes Strayer University Success in online courses requires self-motivation and discipline. It is anticipated that students will read the textbook and complete sample

More information

CS 4349 Lecture October 18th, 2017

CS 4349 Lecture October 18th, 2017 CS 4349 Lecture October 18th, 2017 Main topics for #lecture include #minimum_spanning_trees. Prelude Homework 6 due today. Homework 7 due Wednesday, October 25th. Homework 7 has one normal homework problem.

More information

COPYRIGHTED MATERIAL. An Introduction to Computers That Will Actually Help You in Life. Chapter 1. Memory: Not Exactly 0s and 1s. Memory Organization

COPYRIGHTED MATERIAL. An Introduction to Computers That Will Actually Help You in Life. Chapter 1. Memory: Not Exactly 0s and 1s. Memory Organization Chapter 1 An Introduction to Computers That Will Actually Help You in Life Memory: Not Exactly 0s and 1s Memory Organization A Very Simple Computer COPYRIGHTED MATERIAL 2 Chapter 1 An Introduction to Computers

More information

Signed umbers. Sign/Magnitude otation

Signed umbers. Sign/Magnitude otation Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

More information

Introduction to Computer Science Unit 3. Programs

Introduction to Computer Science Unit 3. Programs Introduction to Computer Science Unit 3. Programs This section must be updated to work with repl.it Programs 1 to 4 require you to use the mod, %, operator. 1. Let the user enter an integer. Your program

More information

The first program: Little Crab

The first program: Little Crab Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,

More information