Program Design Invasion Percolation: The Grid

Slides:



Advertisements
Similar presentations
Input and Output Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advertisements

Floating Point Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Control Flow Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
LECTURE 7 SEP 27, 2010 Building computational pipelines.
Fixtures Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Invasion Percolation: Assembly Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Debugging Strategies from Software Carpentry. Agan's Rules Many people make debugging harder than it needs to be by: Using inadequate tools Not going.
Interface and Implementation Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Storage Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
More Patterns Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Basics Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Rollback Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Invasion Percolation: Randomness Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Exceptions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction to python programming
Python Aliasing Copyright © Software Carpentry 2010
More File Input and Output
EGR 2261 Unit 11 Pointers and Dynamic Variables
Sampling Distribution Models
Program Design Invasion Percolation: Aliasing
EGR 2261 Unit 10 Two-dimensional Arrays
PYGAME.
Part of the Assembler Language Programmers Toolbox
Properties of Operations for Real Numbers
Thought for the Week ‘Caring for others.’
CS 5010 Program Design Paradigms "Bootcamp" Lesson 9.4
Program Design Invasion Percolation: Testing
Sets and Dictionaries Examples Copyright © Software Carpentry 2010
Two-dimensional arrays
Introduction to Computer Science / Procedural – 67130
CMSC201 Computer Science I for Majors Lecture 12 – Lists (cont)
Halting Functions for Tree-Like Structures
Program Design Invasion Percolation: Resolving Ties
Confidence Intervals for Proportions
Program Design Invasion Percolation: Neighbors
Other Kinds of Arrays Chapter 11
Solving Mazes Troy Mahon.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Functions Chapter 9 Copyright © 2008 W. W. Norton & Company. 1
Confidence Intervals for Proportions
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Random Numbers In today’s lesson we will look at:
Topic 26 Two Dimensional Arrays
Matlab tutorial course
Arrays in Java What, why and how Copyright Curt Hill.
Coding Concepts (Data Structures)
Solving Your Problem by Generalization
Thought for the Week: Being forgiving.
Version Control Basic Operation Copyright © Software Carpentry 2010
MATLAB Programming Indexing Copyright © Software Carpentry 2011
Coding Concepts (Data- Types)
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
Sampling Distribution Models
Version Control Introduction Copyright © Software Carpentry 2010
Program Design Invasion Percolation: Bugs
MATLAB Programming Basics Copyright © Software Carpentry 2011
Copyright © Cengage Learning. All rights reserved.
Confidence Intervals for Proportions
GIVE MANAGING STRESS: MAKING CHOICES
Lecture 22 Logistics Last lecture Today
Version Control Conflict Copyright © Software Carpentry 2010
A10 Generating sequences
The 5 Minute Workload Plan
And now for something completely different . . .
Browsing Directories Using walk
2D Array and Matrix Application: Game of Life
Design Strategies 3: Divide into cases
Thinking Multiplicatively: From Arrays to the ‘Area Model’
Presentation transcript:

Program Design Invasion Percolation: The Grid Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.

Need: - a random 2D grid 5 3 7 2 6 1 4 8 9

Need: - a random 2D grid - to mark cells 5 3 7 2 6 1 4 8 9 3

Don’t care about a cell’s value after it has been filled 5 3 7 2 6 1 4 8 9 4

So use any value that can’t ever be a real cell value to mark filled cells 5 3 7 2 6 1 4 8 9 -1 5

Note: we’re using integers as: 6

Note: we’re using integers as: - Actual data values 7

Note: we’re using integers as: - Actual data values - Flags to represent cell states 8

Note: we’re using integers as: - Actual data values - Flags to represent cell states It’s simple to do... 9

Note: we’re using integers as: - Actual data values - Flags to represent cell states It’s simple to do... ...but if we ever get data whose values are those we’ve been using as flags, our program will interpret them as flags 10

Note: we’re using integers as: - Actual data values - Flags to represent cell states It’s simple to do... ...but if we ever get data whose values are those we’ve been using as flags, our program will interpret them as flags This kind of error can be very hard to track down 11

Are grids always square? 5 3 7 2 6 1 8 4 9 -1 12

Are grids always square? Are they always odd × odd (so that there is a unique center square)? 5 3 7 2 6 1 8 4 9 -1 13

How general should we make the first version of our program? 5 3 7 2 6 1 8 4 9 -1 14

“Don’t build it until you need it.” How general should we make the first version of our program? 5 3 7 2 6 1 8 4 9 -1 “Don’t build it until you need it.” 15

“Don’t build it until you need it.” vs. How general should we make the first version of our program? 5 3 7 2 6 1 8 4 9 -1 “Don’t build it until you need it.” vs. “A week of hard work can sometimes save you an hour of thought.” 16

Like many generalizations, these rules are:

Like many generalizations, these rules are: - True 18

Like many generalizations, these rules are: - True - Not particularly useful 19

Like many generalizations, these rules are: - True - Not particularly useful Knowing what rules to apply when comes with experience 20

Like many generalizations, these rules are: - True - Not particularly useful Knowing what rules to apply when comes with experience The only way to get experience is to work through many examples 21

Problem: Python doesn’t actually have 2D arrays 5 3 7 2 6 1 4 8 9

But it does have 1D lists 3 5 7

But it does have 1D lists Which can refer to other lists 3 5 7 2 6 5 4 8

But it does have 1D lists Which can refer to other lists This gives us grid[1][0] == 2 But it does have 1D lists Which can refer to other lists This gives us double subscripts 3 5 grid 7 2 6 5 4 3 8 25

But it does have 1D lists Which can refer to other lists This gives us grid[1][0] == 2 But it does have 1D lists Which can refer to other lists This gives us double subscripts ...which is really what we mean by “two-dimensional” 3 5 grid 7 2 6 5 4 3 8 26

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value 27

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value 28

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value grid 29

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value grid 30

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value grid 1 31

# Create an NxN grid of random integers in 1..Z. assert N > 0, "Grid size must be positive" assert N%2 == 1, "Grid size must be odd" grid = [] for x in range(N): grid.append([]) for y in range(N): grid[-1].append(1) # FIXME: need a random value grid 1 1 32

Greg Wilson created by May 2010 Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information.