74
Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call codin g chunk y strin gs rebooti ng knuth (or turing or…) installi ng Debian 3.1 Engineering dept. the dumpster Universit y of St. Petersbur g On the 405, in traffic, being chased by police (and TV) helicopters. Mailing something at the Claremont Post Office Waiting for the snow enveloping you on Route 5 N to melt Krispy Kreme’s drive- through Teaching Honors English for Janice Barbee at Pomona High School Worldcom Headquart ers Leading a Gray Davis / Gary Coleman / Arnold “T-800” Schwarzenegger gubernatorial fundraiser exploring martian soil Being dragged off- course 18 miles into a marathon race by a crazed spectator Massey University Palmerston North, NZ Pittsburgh Driving N on the Dalton Highway… (though it feels like it!) Victorville, for DARPA's Urban Granc Challenge Waiting in line to vote in the Florida primaries… Denver, CO or Minneapolis, MN

Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Embed Size (px)

Citation preview

Page 1: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Welcome to Programming Practicum“Putting the C

into CS”

You aren’t here

writing clinic reports

clinic liaison phone call

coding chunky strings

rebooting knuth (or turing or…)

installing

Debian 3.1

Engineering dept.

the dumpster

University of St. Petersburg

On the 405, in traffic, being chased by police (and TV) helicopters.

Mailing something at the Claremont Post Office

Waiting for the snow enveloping you on Route 5 N to melt

Krispy Kreme’s drive-through

Teaching Honors English for Janice Barbee at

Pomona High School

Worldcom Headquarters

Leading a Gray Davis / Gary Coleman / Arnold “T-800” Schwarzenegger gubernatorial fundraiser

exploring martian soil

Being dragged off-course 18 miles into a marathon race by a crazed spectator

Massey University Palmerston North, NZ

Pittsburgh

Driving N on the Dalton Highway… (though it feels like it!)

Victorville, for DARPA's Urban Granc Challenge

Waiting in line to vote in the Florida primaries…

Denver, CO or Minneapolis, MN

Page 2: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

What is this course about?

Page 3: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

What is this course about?

• A chance to “improve” your programming skillsAlgorithm analysis and

insightProgram design and implementation

optimizing coding time

ACM programming contest

What

Why

Research/prototype programming

Hands-on practice with algorithms and techniques

Unofficial course name: CS -70

Familiarity with Java’s libraries OR your choice of language "reasonable"

Page 4: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

2007 ACM regionals - results

CSLB

PomonaSDSU

CPSLO

http://www.socalcontest.org/history/2007/results-2007.shtml

http://icpc.baylor.edu/icpc/ '09 world finals: Stockholm, Sweden

Page 5: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Class Organization

alternating format

discussion sessions

lab sessions

• problem and program analysis

• discussion of strategy and coding tips

• deciding on functional decomposition, data structures, language facilities, and algorithms to use in teams of 2-3

• teams may use 1 machine per person (only the mock contest adheres to ACM rules)

• these problems count for each member of the group

• sometimes new problems, other times with known ones

• ~ 4 problems given out per week…

a team might want to practice with only 1

machine

Page 6: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Class Organization

Feedback from prior semesters…

• make individual vs. team-based work clear, lectures vs. labs

• problems are, in general, individually completed -- except

• there should be an opportunity to start coding “cold”

• snacks and jotto!

• problems per person per week?

• about 1~2 (if you work on a team in lab)

• and consider all of the weeks of the term!

• those done during the lab "mock contest" sessions

• submit for each person (email me if there are problems…)

• provide the code to all team members

• you may or may not choose to work as a team afterwards

Page 7: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course Organization

Sep 2 Welcome! Review of dynamic programming: 4 problemsSep 9 Lab/Mock contest session: 4 problems

Sep 16 Discussion session on graph problems: 4 problemsSep 23 Lab/Mock contest session: 4 problems

Sep 30 Discussion session on geometry problems: 4 problemsOct 7 No class (I'll be out of town…)Oct 14 Lab/Mock contest session: 4 problems

Oct 21 No class… Fall break!Oct 28 Mock ACM contest, 9pm – 1:00am, 6 problems

Nov 4 Regional participants' -- preparation meeting

Nov 11 Discussion and wrap-up for the semester

You may submit problems until the end of exams…

Sat. Nov. 8 may be the regional contest

Page 8: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course webpage

references

administrative info

problem statements and sample data

problems you have solved

Page 9: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Grading

CS 189 is graded individually... (it’s possible to take it P/F, too)

Coding Guidelines• problems can be done any time

during the semester

• discussion of algorithms always OK

• coding should be within teams

• you may use any references except an existing solution or partial solution…

• one person should take the lead on each problem

• use /cs/ACM/acmSubmit <file> to submit

• try things out !

the reason for ACM!

though not for CS elective credit…

Page 10: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem multipliers

Problems are worth double if

• You solve them during the 4:15 - 5:30 lab sessions

• It's one of the "extra difficult" problems, which will be determined as we go…

• The new-language bonus is only in the spring term!

• Any standard language is OK -- but do keep in mind that the competition allows only Java, C, and C++ .

Other "standard" languages:

the team gets credit, up to 3 people

These multipliers may be accumulated…

reasonable alternatives will also be considered…

C#, python, ruby

Language Choice?

Ask about our 2 extra-credit projects!web-updating and

web-jotto

Page 11: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Spring 2008 summary

python 82

java 60

C++ 40

Tallies per problem and per language

(thus far)…

17 (+2)

8 4 16 (+2)

1 (+1)

6 (+1)

20 (+12)

(+2)

3 (+1)

1 1 2 11 (+1)

1 (+1)

17 (+9)

(+2)

4 (+2)

1

2 2 8 3 2 8 (+2)

13 (+10)

14 (+9)

1 21 (+16)

(+4)

1 1 15 (+14)

number of 2x scores number

of 4x scores

d 8

ruby 6

scheme 3

lua 2

awk 2

js 2

sqlcobolbasicx86 asmpascalmathematicash, latex

1each

Page 12: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming!

Page 13: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Jotto!

Sophs Jrs Srs Profs

A word-guessing game similar to mastermind…

pluot 1

pluot 0

pluot 1

pluot 2

Page 14: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

When a seemingly intractable problem has lots of repeated substructure, go

DP!

Build a table of partial results.

Replace computation with table look-up when possible

For example:

Page 15: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Build a table of partial results.

Replace computation with table look-up when possible

the binary-decimal problem, for example:

263190

Numbers, N, up to 106

Input

0 marks the end of the input

10111011111001

the smallest decimal multiple of N with only

the digits 0 and 1 !

Output

Ideas?

When a seemingly intractable problem has lots of repeated substructure, go

DP!

Page 16: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

One way…

Count up to the solution, starting from 1…

Page 17: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

Page 18: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

1

Page 19: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

1

10 111

Page 20: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

1

111110 10 111

10 111

Page 21: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

1

111110 10 111

10 111

1110 111110 10 111

Page 22: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

DP!

Only checking values for which a remainder has not yet been used…

Fast

Page 23: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Another example

binary-as-decimal problem

"pebbles" problem (2007 ACM regionals)

Square array, up to 15x15, of integers

from 1 to 99

Input

Output

Idea

place "pebbles" on integers, trying to maximize total, but no two pebbles may be adjacent…

maximum possible sum

14?

3 8 6 7 9 1 4 6 1

vertically, horizontally, or diagonally

3 8 67 9 14 6 1

Page 24: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Pebbles

3 8 67 9 14 6 1

Square array, up to 15x15, of integers

from 1 to 99

Input

DP Idea consider all possibilities for pebbling each row -they only depend on the previous row's best scores!

Subset chosen (pebbles)

000 001 010 011 100 101 110 111Row #

0

1

2a b c

Store the BEST score available for each possible subset.

Page 25: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Pebbles

3 8 67 9 14 6 1

Square array, up to 15x15, of integers

from 1 to 99

Input

DP Idea consider all possibilities for pebbling each row -they only depend on the previous row's best scores!

Subset chosen (pebbles)

000 001 010 011 100 101 110 111Row #

0

1

2a b c

Store the BEST score available for each possible subset.

0 6 8 x 3 9 x x

Page 26: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Pebbles

3 8 67 9 14 6 1

Square array, up to 15x15, of integers

from 1 to 99

Input

DP Idea consider all possibilities for pebbling each row -they only depend on the previous row's best scores!

Subset chosen (pebbles)

000 001 010 011 100 101 110 111Row #

0

1

2a b c

Store the BEST score available for each possible subset.

0 6 8 x 3 9 x x

90+9

41+3

99+0

137+6

88+0

x x x

Page 27: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Pebbles

3 8 67 9 14 6 1

Square array, up to 15x15, of integers

from 1 to 99

Input

DP Idea consider all possibilities for pebbling each row -they only depend on the previous row's best scores!

Subset chosen (pebbles)

000 001 010 011 100 101 110 111Row #

0

1

2a b c

Store the BEST score available for each possible subset.

0 6 8 x 3 9 x x

90+9

41+3

99+0

137+6

88+0

x x x

x x x0+13 c+13 b+9 a+9 ?

running time?

Page 28: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Pebbles

binary-as-decimal problem

"pebbles" problem (2007 ACM regionals)

71 24 95 56 5485 50 74 94 2892 96 23 71 1023 61 31 30 4664 33 32 95 89

Square array, up to 15x15, of integers

from 1 to 99

Input

Output

71 24 95 56 5485 50 74 94 2892 96 23 71 1023 61 31 30 4664 33 32 95 89

Idea

place "pebbles" on integers, trying to maximize total, but no two pebbles may be adjacent…

maximum possible sum

572

Page 29: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Thanks, Martijn!

Scanner sc = new Scanner(System.in);

even a bit easier!

Martijn is shifty!

Martijn is VERY shifty!

Where is the table?

This sure is sum code…

to the max

Page 30: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #0(4 problems)

In teams of 2~3, read over these…

I need a picture of Farmer Ran!

Page 31: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #0(4 problems)

In teams of 2~3, read over these.

• Where does the structure of the problem depend on similar (but smaller!) substructure?

• Think of your next 5-letter jotto word… !

• How might you build up a table of values toward an overall solution?

Page 32: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

See you next Tuesday!

bring a laptop, if you have one…

Page 33: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Jotto!

Sophs Jrs Srs Me

A word-guessing game similar to mastermind…

pluot 1

pluot 0

pluot 1

pluot 2

Page 34: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

4 4 tow cat row care ... .#. ... .## 0 0

# of words in the puzzle (to follow)

# of rows in the puzzle (after the words)

the words

the puzzle

this indicates the end of the input…

Page 35: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

4 4 tow cat row care ... .#. ... .## 0 0

either the solution OR a statement that it can't be solved…

Output

Problem 1 cat a#o row e## Problem 2: no layout is possible.

Page 36: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

6 5 1

1 2 2 3 4 4 5 1 3 2

1 4 2 1 0 0 0

# of empty boxes on the form

# of clerks in the office (three lines each)

clerk #0

this indicates the end of the input…

the box(es) CHECKED

the box(es) ERASED the clerks who get a copy

clerk #1

clerk #2

clerk #3

clerk #4

0 1 2 3 4 5

the form

Page 37: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

6 5 1

1 2 2 3 4 4 5 1 3 2

1 4 2 1 0 0 0

# of empty boxes on the form

# of clerks in the office (three lines each)

clerk #0

this indicates the end of the input…

the box(es) CHECKED

the box(es) ERASED the clerks who get a copy

clerk #1

clerk #2

clerk #3

clerk #4

0 1 2 3 4 5

the form

let's try it…

Page 38: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

6 5 1

1 2 2 3 4 4 5 1 3 2

1 4 2 1 0 0 0

# of empty boxes on the form

# of clerks in the office (three lines each)

clerk #0

this indicates the end of the input…

the box(es) CHECKED

the box(es) ERASED the clerks who get a copy

clerk #1

clerk #2

clerk #3

clerk #4

0 1 2 3 4 5

the form

Output1 3 4 5

the boxes checked the last time it leaves clerk #0's

desk…

Page 39: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

RDDR Speedy M 0101 Jumper F 0101 Slowpoke M 1101 Terror F 1100 Shadow F 1001 *** Frisky 0101 Sleepy 1101***

list of traits, R == "recessive" D == "dominant"

D traits are passed if EITHER parent has themR traits are passed if BOTH parents have them

all of the parents, gender, and traits

the baby shrews…

Deduce their possible parents!

Page 40: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

RDDR Speedy M 0101 Jumper F 0101 Slowpoke M 1101 Terror F 1100 Shadow F 1001 *** Frisky 0101 Sleepy 1101***

list of traits, R == "recessive" D == "dominant"

D traits are passed if EITHER parent has themR traits are passed if BOTH parents have them

all of the parents, gender, and traits

the baby bunnies…

Deduce their possible parents!

Output

Frisky by Jumper-Slowpoke or Jumper-Speedy or ______Sleepy by _________

Page 41: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

RDDR Speedy M 0101 Jumper F 0101 Slowpoke M 1101 Terror F 1100 Shadow F 1001 *** Frisky 0101 Sleepy 1101***

list of traits, R == "recessive" D == "dominant"

D traits are passed if EITHER parent has themR traits are passed if BOTH parents have them

all of the parents, gender, and traits

the baby bunnies…

Deduce their possible parents!

Output

Frisky by Jumper-Slowpoke or Jumper-Speedyor Shadow-SpeedySleepy by Shadow-Slowpoke

Page 42: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Decide which problem is the easiest and which one is the hardest …

(to code, not to compute!)

Read these three problems… then

Page 43: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

my estimates…

hardest

easiest

important heuristic:I’m always wrong

Page 44: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

See you next Tuesday

in the CS labs… !

Page 45: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Welcome to Programming Practicum“Putting the C

into CS”

You aren’t here

writing clinic reports

clinic liaison phone call

coding chunky strings

rebooting knuth (or turing or…)

installing

Debian 3.1

Engineering dept.

the dumpster

University of St. Petersburg

On the 405, in traffic, being chased by police (and TV) helicopters.

Mailing something at the Claremont Post Office

Waiting for the snow enveloping you on Route 5 N to melt

Krispy Kreme’s drive through

Teaching Honors English for Janice Barbee at

Pomona High School

Worldcom Headquarters

Leading a Gray Davis / Gary Coleman / Arnold “T-800” Schwarzenegger gubernatorial fundraiser

exploring martian soil

Being dragged off-course 18 miles into a marathon race by a crazed spectator

Massey University Palmerston North, NZ

Pittsburgh

Driving N on the Dalton Highway… (though it feels like it!)

Page 46: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

What is this course about?

• A chance to “improve” your programming skillsAlgorithm analysis and

insightProgram design and implementation

optimizing coding time

ACM programming contest

What

Why

Research/prototype programming

Hands-on practice with algorithms and techniques

Unofficial course name: CS -70

Familiarity with Java’s libraries OR your choice of language

Page 47: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course Organization

Jan 16 Welcome! Random teams of 3: 6 problems, 3 weeks

Jan 23 Lab session to work on problems (Beckman B102 or 105)

Jan 30 Discussion session on the first set of problems Feb 6 Lab session with new problems: 4 problems, 2 weeks

Feb 13 Discussion session on the second set of problemsFeb 20 Lab session with new problems: 6 problems, 3 weeks

Feb 27 Discussion session on the third set of problems

Mar 6 No class - Fall breakMar 20 Mock ACM contest, 9pm – 1am, teams of 3, 6 pr, 4 hours

Mar 27 No class (out of town)

Apr 3 Discussion session on the mock contest + Finale!

You may submit problems until the end of exams…

2 per team

2/team

3 per team

1-4 / team

Page 48: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Class Organization

alternating format

discussion sessions

lab sessions

• problem and program analysis

• discussion of strategy and coding tips

• deciding on functional decomposition, data structures, language facilities, and algorithms to use in teams of 2-3

• teams should use 1 terminal per person (only the mock contest adheres to ACM rules)

• these problems count for each member of the group• sometimes new problems, other times with known ones

• ~1 problem per week per person…

Page 49: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course webpage

reference links

administrative info

problem statements and test data

problems your team has solved

Page 50: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Grading

CS 189 is graded individually... (it’s possible to take it P/F, too)

Coding Guidelines• problems can be done any time

during the semester

• discussion of algorithms always OK

• coding should be within teams

• you may use any references except an existing solution or partial solution…

• one person should take the lead on each problem

• use /cs/ACM/acmSubmit <file> to submit

• try things out !

the reason for ACM!

Page 51: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Choose your language…

• extensive library of data structures and algorithms available

Java is almost the universal choice for the competition…

• I/O made simpler with 1.5’s Scanner and printf

the C in CS!

Input from stdin

Output to stdout

Page 52: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Choose your language…

Python is nice

C#

Whatever language you choose needs to be able to run on the Macs in

the CS labs (and preferably knuth, as

well…)

I’ll likely need your help to get things set

up for testing…

def floyd_warshall(W, infinity): n = matrix.get_num_rows(W) D = matrix.clone(W) DD = matrix.make(n,n) for k in xrange(n): for i in xrange(n): for j in xrange(n): DD[i][j] = min(D[i][j], D[i][k] + D[k][j]) DD, D = D, DD return D

Others ?Marty: prolog!

Page 53: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

4 4 tow cat row care ... .#. ... .## 0 0

# of words in the puzzle (to follow)

# of rows in the puzzle (after the words)

the words

the puzzle

this indicates the end of the input…

Page 54: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

6 5 1

1 2 2 3 4 4 5 1 3 2

1 4 2 1 0 0 0

# of empty boxes on the form

# of clerks in the office (three lines each)

clerk #0

this indicates the end of the input…

the box(es) CHECKED

the box(es) ERASED the clerks who get a copy

clerk #1

clerk #2

clerk #3

clerk #4

0 1 2 3 4 5

the form

Output1 3 4 5

the boxes checked the last time it leaves clerk #0's

desk…

Page 55: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Input

RDDR Speedy M 0101 Jumper F 0101 Slowpoke M 1101 Terror F 1100 Shadow F 1001 *** Frisky 0101 Sleepy 1101***

list of traits, R == "recessive" D == "dominant"

D traits are passed if EITHER parent has themR traits are passed if BOTH parents have them

all of the parents, gender, and traits

the baby shrews…

Deduce their possible parents!

Output

Frisky by Jumper-Slowpoke or Jumper-Speedy or ______Sleepy by _________

Page 56: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(6 probs, 3 wks)

Decide which problem is the easiest and which one is the hardest …

(to code, not to compute!)

Read these three problems… then

Page 57: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Coaches’ Room

Page 58: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Choose your language…

• extensive library of data structures and algorithms available

Java/Cthe universal choice for the competition…

• I/O made simpler with 1.5’s Scanner and printf

the C in CS!

Input from stdin

Output to stdout

Page 59: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Choose your language…

Python is nice

def floyd_warshall(W, infinity): n = matrix.get_num_rows(W) D = matrix.clone(W) DD = matrix.make(n,n) for k in xrange(n): for i in xrange(n): for j in xrange(n): DD[i][j] = min(D[i][j], D[i][k] + D[k][j]) DD, D = D, DD return D

Ruby :-)

Marty: prolog!

Postscript!

Page 60: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Welcome to Programming Practicum“Putting the C

into CS”

You aren’t here

writing clinic reports

clinic liaison phone call

coding chunky strings

rebooting knuth (or turing or…)

installing

Debian 3.1

Engineering dept.

the dumpster

University of St. Petersburg

On the 405, in traffic, being chased by police (and TV) helicopters.

Mailing something at the Claremont Post Office

Waiting for the snow enveloping you on Route 5 N to melt

Krispy Kreme’s drive-through

Teaching Honors English for Janice Barbee at

Pomona High School

Worldcom Headquarters

Leading a Gray Davis / Gary Coleman / Arnold “T-800” Schwarzenegger gubernatorial fundraiser

exploring martian soil

Being dragged off-course 18 miles into a marathon race by a crazed spectator

Massey University Palmerston North, NZ

Pittsburgh

Driving N on the Dalton Highway… (though it feels like it!)

Victorville, for DARPA's Urban Granc Challenge

Waiting in line to vote in the Florida primaries…

Waiting in line to vote in the Florida primaries…

Page 61: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

What is this course about?

• A chance to “improve” your programming skillsAlgorithm analysis and

insightProgram design and implementation

optimizing coding time

ACM programming contest

What

Why

Research/prototype programming

Hands-on practice with algorithms and techniques

Unofficial course name: CS -70

Familiarity with Java’s libraries OR your choice of language

Page 62: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Class Organization

alternating format

discussion sessions

lab sessions

• problem and program analysis

• discussion of strategy and coding tips

• deciding on functional decomposition, data structures, language facilities, and algorithms to use in teams of 2-3

• teams should use 1 machine per person (only the mock contest adheres to ACM rules)

• these problems count for each member of the group• sometimes new problems, other times with known ones

• ~3 problems per week per person…

Page 63: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Class Organization

Feedback from prior semesters…

• make individual vs. team-based work clear, lectures vs. labs

• problems are, in general, individually completed, except

• there should be an opportunity to start coding “cold”

• snacks and jotto!

• problems per person per week?

• ~2 in the fall

• ~3 in the spring

• those done during the lab "mock contest" sessions

• submit for each person (or email me…)

• provide the code to all team members

• you may or may not choose to work as a team afterwards

Page 64: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course Organization

Jan 29 Welcome! Review of dynamic programming: 4 problemsFeb 5 Lab/Mock contest session: 4 problems

Feb 12 Discussion session on geometry problems: 4 problemsFeb 19 Lab/Mock contest session: 4 problems

Feb 26 Lab/Mock contest session: 4 problems

Mar 4 Discussion session on search problems: 4 problems

Mar 11 No class… need to be away

Mar 18 No class - Spring breakMar 23 Mock ACM contest, 9pm – midnight, 6 problems

Mar 25 Discussion and wrap-up of the semester

You may submit problems until the

end of exams…

Sat. Mar 8 and Sat. Apr 19external

competitions…

Page 65: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Competition Options

www.ccsc.org/southwestern/2008/contest.html

www.ieee.org/web/membership/students/scholarshipsawardscontests/ieeextreme.html

Sat. Mar 8 and Sat. Apr 19external

competitions…

Page 66: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Course webpage

references

administrative info

problem statements and test data

problems you have solved

Page 67: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Grading

CS 189 is graded individually... (it’s possible to take it P/F, too)

Coding Guidelines• problems can be done any time

during the semester

• discussion of algorithms always OK

• coding should be within teams

• you may use any references except an existing solution or partial solution…

• one person should take the lead on each problem

• use /cs/ACM/acmSubmit <file> to submit

• try things out !

the reason for ACM!

Page 68: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem multipliers

Problems are worth double if

• You solve them during the 4:15 - 5:30 lab sessions

• You are the first person to use a particular language - though there is an additional responsibility here: to set up the testing system to handle that language!

• It's one of the "extra difficult" problems, which will be determined as we go…

languages already used:

the team gets credit, up to 3 people

python 56

ruby 12

java 6

c++ 11

perl 2

postscript 2

c# 8

haskell 1

prolog 2

c 5

php 1

These multipliers may be accumulated…

Page 69: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

When a seemingly intractable problem has large amounts of repeated or redundant substructure, DP can sometimes provide an efficient solution.

Build a table of partial results.

Replace computation with table look-up when possible

For example:

263190

Numbers, N, up to 106

Input

0 marks the end of the input

10111011111001

the smallest decimal multiple of N with only

the digits 0 and 1 !

Output

Ideas?

Page 70: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

One way…

Count up to the solution, starting from 1…

Page 71: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Dynamic programming

Storing intermediate results in a table for fast look-up:input N = 6

possible remainders upon dividing by N (6)

# of digits in answer

0 1 2 3 4 5

2

1

3

4

1

111110 10 111

10 111

1110 111110 10 111

Page 72: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

DP!

Only checking values for which a remainder has not yet been used…

Page 73: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Problem Set #1(4 problems)

In teams of ~3, think about

- how would you solve this problem?

- how could you most simplify the programming ?- think of a 5-letter jotto word… !

- is it a dynamic programming problem?

- divide up with one problem per group -

Page 74: Welcome to Programming Practicum “Putting the C into CS” You aren’t here writing clinic reports clinic liaison phone call coding chunky strings rebooting

Competition Options

www.ccsc.org/southwestern/2008/contest.html

www.ieee.org/web/membership/students/scholarshipsawardscontests/ieeextreme.html

Sat. Mar 8 and Sat. Apr 19external

competitions…