Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

29
Curricularizing the ACM... ? Zach Dodds ~ November 13, 2010

Transcript of Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Page 1: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Curricularizing the ACM... ?

Zach Dodds ~ November 13, 2010

Page 2: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Hard-won lesson #1: at HMC, if you want students to participate in something, curricularize it!

Four undergraduate years

≈ 190 students each

Every student must pass CS 1

Concrete mascot, Wally Wart

Page 3: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Our one-unit CS 189 class...

Tuesdays 4:15-5:30 pm each week...

Page 4: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Our one-unit CS 189 class...

Hard-won lesson #2: at HMC, if you want students to participate in something, provide food!

Page 5: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Running total of problems solvedweekly problem sets of 4-6 problems...

graded via a script that runs diff on our server

worth 2 points, if done by 10pm Tuesday; 1 point otherwise

week 0 week 1 week 2 week 3

Waterloo et al.!

Page 6: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Short lectures

dynamic programming

45 minutes every other Tuesday... Other meetings are lab sessions.No teaching credit for this, but good will credit == at least half the food!

graphs

geometry

Binary Search

Page 7: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This week: cow placement

Input Output

5 212849

1 2 4 8 9

Number of cow stalls in the barn

The locations of stalls

Number of cows to put in the stalls 8The largest

minimum spacing possible after

placing the cows

The barn!

how do we best fit 2 cows? 3 cows? 4?

Page 8: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

# get (N) # of stalls, (C) cows, and (S), the stalls

N = input(); C = input(); S = []; for i in range(N): S += [input()] # list o' stallsS.sort() # sort them!

lo = 0hi = max(S)-min(S)+1

while True:

mid = (lo + hi)/2 # does anyone see the bug here? if mid == hi or mid == lo: break

if CHECKS_OUT( mid, C, S ): lo = mid # it worked! Look higher (set lo to mid) else: hi = mid # it didn't work Look lower (set hi to mid)

print mid # output the result!

cows codeb

inary se

arch

inp

ut

BS setup

Page 9: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.
Page 10: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This bug went undetected in Java's libraries for years...

Page 11: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Our general strategy

Give 75% of the code for one problem...

Allow use of any language...

Keep contest in perspective...If something isn't useful to all CS majors, we don't bother.

• Everyone gets that problem, at least.

• Everyone has a good start on the next problems that use binary search!

Page 12: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

ACM: a light hat to wear...

Thoughts... ?

Problems

+

Food

=

ACM class

Andrew

Lilian

Page 13: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.
Page 14: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

ACM today!

Nice work to everyone in the qualifiers and evening

lab...

Today: BS!

Next 11/2: guest speaker...

On 11/9: final lab session

11/13: regionals

On 11/16: wrap-up

Page 15: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

ACM this week!?

Page 16: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Next week

This talk is optional, but it should be good!

In addition, it's incentivized @ 2 problems...

It may count as a colloquium, too...

Page 17: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Jotto!

Sophs Jrs Srs Profs

pluot 1 pluot 2 pluot 1 pluot 2

squid 2 squid 1 squid 0 squid 1

sophomores remain...

fails 2 fails 2 fails 0 fails 2

cache 1 cache 2 cache 3 cache 0

china 1

quail 1china 2

quail 3

china 3quail 0

china 0quail 2

conch 0 conch 1 conch 5 conch 0

laugh ? laugh 5 laugh x laugh 2

Page 18: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Problem D from the 2009 World Finals in Stockholm:

Pipe PackingGiven a set of four wire diameters:

What is the minimum diameter of pipe that can contain all four wires?

(Constraint: pipes only come in millimeter sizes)

Page 19: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

A lower bound: sum of largest two wire-diameters

An upper bound: sum of all four wire-diameters

Binary search between lower bound and upper bound Given a pipe diameter and four wire diameters, can

you pack the wires inside the pipe? Choose the smallest integer pipe diameter that fits

Intuition: Solve this problem by binary search

Page 20: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Binary search in a sorted list...

What's next... ?

in Python

we want to return True or False: is val in S?

Page 21: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This week's problems…

palpath

city

aggr

cowset

flood2

These three are all examples of problems

for which binary search might be a good

technique…could be used here, too...

Page 22: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Problem D from the 2009 World Finals in Stockholm:

Pipe PackingGiven a set of four wire diameters:

What is the minimum diameter of pipe that can contain all four wires?

(Constraint: pipes only come in millimeter sizes)

Page 23: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

A lower bound: sum of largest two wire-diameters

An upper bound: sum of all four wire-diameters

Binary search between lower bound and upper bound Given a pipe diameter and four wire diameters, can

you pack the wires inside the pipe? Choose the smallest integer pipe diameter that fits

Intuition: Solve this problem by binary search

Page 24: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Enjoy!

Thoughts... ?

Page 25: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Last week: wifi

Input Output

12 31310

The # of access points and the # of houses

The # of test cases...

Locations of the houses...

1 3 10

1.0The smallest max distance achievable

Page 26: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This week: city

Input Output

10 20 3112233

0dist

cost of 1st story

# of people to house

194The minimium cost

to house the specified # of

people

cost per unit distance from (0,0)

maximum # of stories per building

the central station where everyone works is at (0,0)distances to it are considered to be |x|+|y|-1

0dist0dist

0dist

1dist 2dist1dist

1dist

1dist

3dist

Page 27: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This week: cowset

Input Output

3 -1 21-23

ID # for 1st cow

# of cows available, up to 34

5The number of

subsets whose IDs sum between min and

max

minimum ID sum

maximum ID sum

Farmer Ran is willing to play frisbee with any subset of cows whose IDs sum to any value between the min and max...

ID # for 2nd cow

ID # for 3rd cow

Try all subsets...?

Page 28: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

This week: cowset

Input Output

3 -1 21-23

ID # for 1st cow

# of cows available, up to 34

5The number of

subsets whose IDs sum between min and

max

minimum ID sum

maximum ID sum

Farmer Ran is willing to play frisbee with any subset of cows whose IDs sum to any value between the min and max...

ID # for 2nd cow

ID # for 3rd cow

Takes too long to try all subsets...!

How could Bin Search speed it up?

Page 29: Curricularizing the ACM... Zach Dodds ~ November 13, 2010.

Try this week's problems!

Perhaps start with aggr...