Light Bot Solutions: an analysis

Slides:



Advertisements
Similar presentations
Identify the number of solutions of an equation
Advertisements

Chapter 8 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences of a problem.
Nested If Statements While Loops
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
 Communication:  Provide context, e.g., s …  TA Office hour for next Tuesday: CANCELLED  My name is: ??  Show  Scores on-line, Quiz-1 results.
Probability Three basic types of probability: Probability as counting
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Iteration and Recursion Tonga Institute of Higher Education.
Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming.
Imperative programming public int factorial (int N){ int F = 1; for(X=N; X>1; X-- ){ F= F*X; } return F; } Functional programming (defun factorial(N) (cond.
Elementary Gymnastics Educational or Developmental Accommodates individual differences Uses a variety of teaching styles Uses a variety of equipment both.
ROBOT Computer and its Programs
10-1 Programming Remember: –programming language –how to program (conceptually) –intro to programming the “ROBOT” computer In this lecture: –programming.
© 2004 Pearson Addison-Wesley. All rights reserved October 27, 2006 Recursion (part 2) ComS 207: Programming I (in Java) Iowa State University, FALL 2006.
Warm up dance Hokey Pokey
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
Solve Equations with Variables on Both Sides
Partial Fraction Decomposition Do Now: express as a single rational expression. Objective: Students will be able to decompose rational expressions into.
CS 108 Computing Fundamentals March 31, Grades not as good as I hoped I drop the lowest of the first 3 exams Exam #3 and #4 will cover much of the.
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
EXAMPLE 1 Solve an equation with variables on both sides 7 – 8x = 4x – 17 7 – 8x + 8x = 4x – x 7 = 12x – = 12x Write original equation. Add.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 We’re underway …
Inequalities and their Graphs Objective: To write and graph simple inequalities with one variable.
Moon Phases. Half of the Moon is always lit up by the sun. As the Moon orbits the Earth, we see different parts of the lighted area.
Lightbot 2.0 Armor games. Lightbot 2.0 Light-Bot 2.0 is online puzzle game built on the principles of visual programming. Light-Bot 2 contains a set of.
Scientific Method real world Example! “Let’s get Real!”
Based on Lawrence Snyder’s slides for UW-Seattle. This notice serves as permission for their use for teaching in public or private (not for profit) schools.
Based on Lawrence Snyder’s slides for UW-Seattle. This notice serves as permission for their use for teaching in public or private (not for profit) schools.
Hospitality Basic Attitude
Two paths diverge in the lectures 2 Think of the first as concepts, the second as capabilities This ClassPrinciplesDoing stuff.
Recursion Chapter 10 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Recursion Chapter 10 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
CHAPTER 16 Developing Fraction Operations
LONG DIVISION CAN BE EASY!.
Properties of Operations
Intro CS – Loops & Creating Shapes
Entry Task Factor 9x2 – 25 (3x – 5)(3x + 5).
Inequalities and their Graphs
Inequalities and their Graphs
Chapter 9 Recursion.
2-4, 2-5 Warm Up
Final Presentation EDU 214 by: Erica Maddux
Introduction to Programmng in Python
Layering: Building Functions out of Functions
Recursion (part 2) October 26, 2007 ComS 207: Programming I (in Java)
Inequalities and their Graphs
Viewing Images in Plane Mirrors
Inequalities and their Graphs
Recap the basics Lesson 1.
Light Bot Solutions: an analysis
Light Bot Solutions: an analysis
A colorful way to find the factors of given numbers
Fractions Concept of a fraction Halving Objectives Day 1
Topic 1: Problem Solving
Michigan Lean Consortium Exercise Instructions
Algorithms.
11 Recursion Software Solutions Lewis & Loftus java 5TH EDITION
Two Paths Diverge in the Lectures
Recursion Taken from notes by Dr. Neil Moore
Nested If Statements While Loops
FOUNDATIONS OF ALGEBRAIC PROBLEM SOLVING
Recap the basics Lesson 1.
Computational Thinking
Recursion (part 2) March 22, 2006 ComS 207: Programming I (in Java)
Java Software Solutions Foundations of Program Design Sixth Edition
Routines for Reasoning
Definition of logarithm
Today: to list: Syllabus change: Grade on-line
Lecture 6 - Recursion.
Presentation transcript:

Light Bot Solutions: an analysis Let’s gather our thoughts … on Lightbot … Based on Lawrence Snyder’s slides for UW-Seattle. This notice serves as permission for their use for teaching in public or private (not for profit) schools. © 2014

Goal for today: Practice Abstraction An instruction (of the Lightbot or any other computer) is abstracted into the command name; functions abstract useful and meaningful operations, functions abstract functions built of functions, etc. Layer upon layer, we build software solutions

What did we learn? Find a pattern (problem): give it a name form a concept: functional abstraction Solve the problem by defining a function F1( ): Process Stairs F2( ): Move To Next Staircase

Pattern?

Process of finding a pattern? Method 1: Brute force: S + P + S + P + S + P + S + P … Stare at the solution! Repeated: Step + Power! Answer: Define ProcessOne() SP Function name + Function Body Repeatedly invoke (call) ProcessOne until done.

Brute force is ok … or ? Method 2: observations 3 strips of identical “thinging” How to solve one “strip”? Define ProcessOneStrip() SPSPSP There are 3 strips so … Answer: 3: ProcessOneStrip Both solutions are equally good!

How about this one?

Pattern? What patterns do you see?

Pattern? 3 identical strips of Abstractions: Two connected 2 steps Strip has TwoSteps “Turn”: connecting the steps

Solving all concepts Def ProcessOneStrip() Def ProcessTwoSteps() MakeTheTurn Power Def ProcessTwoSteps() SS Def MakeTheTurn() RSL

Solution to problem Verbally 3:(ProcessOneStrip : L) Process first strip Turn Left Process second strip Process third strip 3:(ProcessOneStrip : L)

How about this? Pattern?

How about this? Pattern? Obvious one: Any other pattern? So: 4x connected sides A side is 4 steps + Power Any other pattern? Too simple Not obvious enough So: How to get to the beginning of first pattern?

Solution … Get to the pattern: Def ProcessAnEdge() Solution: PJPJPLSS or 2:(PJ)PL2:(S) Def ProcessAnEdge() SSSSPL Solution: GetToThePattern 4:(SSSSPL)

Fun yet? Pattern? Recursion Level 3

Fun yet? Pattern? Facing: Front step need power Left step need power

Solution? Solution: Notice: Def ProcessFacing() J P L J P L L After ProcessFacing The problem repeats itself!! Well, almost …

One small (but important) Point Power: Toggles NOT: on/off Observe Odd ones: Off Even ones: On Each block: Has 3 sets of “Facing”

Last one … Pattern? Recursion Level 4

Last one … Pattern? 4 sets of 3-step stairs Observation: Up and down are the same (we knew this!) Def ProcessStairs() J J J P

Trickier … StairSet: Two stairs Connected with Power + L 2 StairSets!

Process StairSet … Def ProcessStairSet() ProcessStairs L

Today: Practice Abstraction Brute force: List out solution, find patterns from the solution Observe problem Break into smaller problems that repeat themselves in the original problem Define function: solution for the smaller problem Re-use function Can be tricky to observe pattern!

Activity

Example: Moon Walk Being a rock music listener and a fan of the late Michael Jackson, the Lightbot 2.0 likes to do the Moonwalk. If we tell the bot, when its standing on a raised block, to walk, its legs and arms move, but it doesn’t go anywhere. This leads to the bot version of the Moonwalk. This is the Moonwalk definition: Def moon_walk( ) 4:(Step, Right, Right). According to the function body, the bot’s Moonwalk is four repeats of taking a step (and not going anywhere) and then turning right. So, it walks in each direction for one step. To use the moon_walk( ) function after jumping up two steps, for example, we could write Jump, Jump, moon_walk( ). This is an example of calling the moon_walk( ) function. The program asks the bot to jump twice, and then call the moon_walk( ) function, which causes it to do the operations in the function’s definition.

Def moonwalk() 4:(Step, Right)