Introduction to Programming
Doman’s Lecture
CSCI101
A deep understanding of programming, in particularthe notions of successive decomposition as a mode ofanalysis and debugging of trial solutions, results insignificant educational benefits in many domains ofdiscourse, including those unrelated to computers andinformation technology per se.
(Seymour Papert, in "Mindstorms")
What is programming?
Programming is a creative process done byprogrammers to instruct a computer on how to do atask. (http://cplus.about.com)
Writing an original program that performs a particulartask that meets all stated constraints (Think Like aProgrammer, V.Anton Spraul, No Starch Press, Inc. 2012)
What is programming?
A lot of this lecture is taken from the book:
Think Like a Programmer,
By  V.Anton Spraul,
No Starch Press, Inc. 2012
What is programming?
Method or interface to do this:
PROGRAMMING LANGUAGES
Example:  Java:
Public class helloWorld {
Public static void main ( ) {
system.out.println(“Hello World”)
    }
}
Instruct a computer
Example:  C++
#include<iostream>
using namespace std;
int main()
{
cout << “Hello World” << endl;
}
Instruct a computer
Example:  html
<html>
<body>
<p> Hello World </p>
</body>
</html>
Instruct a computer
GAMEMAKER
Drag and drop structured language
Uses icons, text…. Made to be easier than any ofthe previous languages.
Instruct a computer
Programming is a creative process done byprogrammers to instruct a computer on how to do atask. (http://cplus.about.com)
What is programming?
Programming is a creative process done byprogrammers to instruct a computer on how to do atask. (http://cplus.about.com)
Writing an original program that performs a particulartask that meets all stated constraints (Think Like aProgrammer, V.Anton Spraul, No Starch Press, Inc. 2012)
What is programming?
Puzzles
Problem solving
What is programming?
Your car has blue smoke coming from the tailpipe, isidling roughly and has lost fuel efficiency.
How do  you solve it?
Problem Solving
Unbreakable rules about problems or the way inwhich problems must be solved.
Car problem constraints:
Cost of repair
How long before you need it fixed
No new tools be purchases
Constraints
Programming language
Platform
Performance
Memory footprint
User/customer specific constraints
Design constraints.
Common Programming Constraints
Figure out the steps to take to solve the problem
Be able to list the steps
Be able to repeat the steps
You can NOT change the rules (constraints) to getsomething solved!
Problem solving
PROBLEM: HOW TO CROSS THE RIVER?
A farmer with a fox, a goose and a sack of cornneeds to cross a river. The farmer has a rowboat,but there is only room for the farmer and one of histhree items. Unfortunately, both the fox and thegoose are hungry. The fox cannot be left alonewith the goose; the goose cannot be left alonewith the grain.  How does the farmer geteverything across the river?
Puzzle: Fox, goose, grain
Constraints
Only one item at a time in the boat
Can’t leave fox with goose
Can’t leave goose with grain
Operations
Carry the fox to the far side of the river
Carry the goose to the far side of the river
Carry the grain to the far side of the river
Puzzle: Fox, goose, grain
Puzzle: Fox, goose, grain
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YHB28N3D\MP900201746[1].jpg
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\HY3OU23Y\MC900441392[1].wmf
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\EF10C8ZR\MC900083946[1].wmf
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YHB28N3D\MC900290567[1].wmf
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\K8HK0RLE\MC900352086[1].wmf
Abstract the problem
Be more general in describing the way we will solvethe problem
Concept: Variable
Items are fox, goose or grain
Let item vary between fox, goose or grain
Rephrase the problem
Constraints
Only one item at a time in the boat
Can’t leave item(fox) with item(goose)
Can’t leave item(goose) with item(grain)
Operations
 Row the boat from one shore to the other
If the boat is empty, load an item on the boat
If the boat is full, take the item off the boat
Puzzle: Fox, goose, grain
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YHB28N3D\MP900201746[1].jpg
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\K8HK0RLE\MC900352086[1].wmf
Puzzle: Fox, goose, grain
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\HY3OU23Y\MC900441392[1].wmf
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\EF10C8ZR\MC900083946[1].wmf
C:\Users\doman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\YHB28N3D\MC900290567[1].wmf
Puzzle: Sudoku
3
4
7
8
1
6
2
5
5
8
4
7
1
9
7
3
3
4
7
8
9
1
6
2
5
Constraints
 
Techniques
 Start with the easiest
Try something…… be prepared to change if it doesn’t work.
Try something else
Puzzle: Soduko
PROBLEM: THE SLIDING EIGHT
A 3x3 grid is filled with eight tiles, numbered 1through 8 with one empty space.  The grid isjumbled. A tile can be slid into an adjacentempty space, leaving its previous locationempty. Slide the tiles so that they are innumerical order
Puzzle: Sliding  Tile
1
2
3
4
5
7
7
8
Puzzle: Sliding TileSolution
4
7
2
8
6
1
3
5
Puzzle: Sliding Tile
Technique: the train
A circuit of tile positions that include an empty slotforms a train of tiles that can be rotated anywherealong the circuit, preserving the relative order of thetiles.
Puzzle: Sliding Tile
Puzzle: Sliding Tile
1
2
3
2
1
3
 
3
2
 
1
 
3
1
2
Look at the problem in subsets
PROBLEM: THE SLIDING FIVE
Puzzle: Sliding Tile
6
8
5
4
7
Puzzle: Sliding Tile
6
8
5
4
7
5
6
8
4
7
4
5
6
7
 
8
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
4
7
2
8
6
1
3
5
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
4
7
2
8
6
1
3
5
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
4
5
6
8
1
 
3
2
7
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
4
5
6
8
1
 
3
2
7
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
1
 2
3
6
8
 
5
4
7
Use this technique to generalize the solution to anysliding puzzle…..
Puzzle: Sliding tile
1
 2
3
6
8
 
5
4
7
 Problem Solving
Have a plan
Generalize  the problem
Restate the problem
Start with what you know
Divide the problem
Look for analogies or patterns
Experiment!!!
THINK  like a programmer!