Tracking Rumors Suppose that we want to track gossip in a rumor mill - - PowerPoint PPT Presentation

tracking rumors
SMART_READER_LITE
LIVE PREVIEW

Tracking Rumors Suppose that we want to track gossip in a rumor mill - - PowerPoint PPT Presentation

Tracking Rumors Suppose that we want to track gossip in a rumor mill Mike Amir Joseph Seiichi Lindsey Derrick 1 Tracking Rumors Simplifying assumption: each person tells at most two others Mike Amir Joseph Seiichi Lindsey Derrick 2


slide-1
SLIDE 1

Tracking Rumors

Suppose that we want to track gossip in a rumor mill Seiichi Mike Lindsey Amir Joseph Derrick

1

slide-2
SLIDE 2

Tracking Rumors

Simplifying assumption: each person tells at most two others Seiichi Mike Lindsey Amir Joseph Derrick

2

slide-3
SLIDE 3

Representing Rumor Mills

Seiichi Mike Lindsey Amir Joseph Derrick

Is a rumor mill simply a list of people? No, because there are relationships among people

3-4

slide-4
SLIDE 4

Representing Rumor Mills

Seiichi Mike Lindsey Amir Joseph Derrick

How about this?: ; A person is ; (make-person image person person) No, because some people don't gossip to anyone else — or they gossip to an empty rumor mill...

5-6

slide-5
SLIDE 5

Representing Rumor Mills

Seiichi Mike Lindsey Amir Joseph Derrick

How about this?:

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

(define-struct gossip (who next1 next2)) This looks promising...

7-8

slide-6
SLIDE 6

Example Rumor Mills

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

empty

9

slide-7
SLIDE 7

Example Rumor Mills

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

(make-gossip empty empty) Joseph

10

slide-8
SLIDE 8

Example Rumor Mills

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

(make-gossip empty (make-gossip empty empty))

Amir Joseph

11

slide-9
SLIDE 9

Example Rumor Mills

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

(make-gossip (make-gossip empty empty) (make-gossip (make-gossip empty (make-gossip empty empty)) (make-gossip empty empty)))

Seiichi Mike Lindsey Amir Joseph Derrick

12

slide-10
SLIDE 10

Example Using Abbreviations

(define joseph-mill (make-gossip empty empty)) (define amir-mill (make-gossip empty joseph-mill)) (define derrick-mill (make-gossip empty empty)) (define lindsey-mill (make-gossip amir-mill derrick-mill)) (define mike-mill (make-gossip empty empty)) (define seiichi-mill (make-gossip mike-mill lindsey-mill))

13

slide-11
SLIDE 11

Programming with Rumors

; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)

(define (func-for-rumor-mill rm) (cond [(empty? rm) ...] [(gossip? rm) ... (gossip-who rm) ... (func-for-rumor-mill (gossip-next1 rm)) ... (func-for-rumor-mill (gossip-next2 rm)) ...]))

14-17

slide-12
SLIDE 12

Rumor Program Examples

  • Implement the function informed? which takes a person image and a

rumor mill and determines whether the person is part of the rumor mill

  • Implement rumor-delay which takes a rumor mill and determines the

maximum number of days required for a rumor to reach everyone, assuming that each person waits a day before passing on a rumor

  • Implement add-gossip which takes a rumor mill and two person

images — one new and one old — and adds the new person to the rumor mill, receiving rumors from the old person; the old person must not already have two next persons

  • Implement rumor-chain which takes a person image and a rumor mill

and returns a list of person images representing everyone who must pass

  • n the rumor for it to reach the given person; return false if the given

person is never informed

18

slide-13
SLIDE 13

More Pipes

  • In the Mid-Term I example, we had all straight pipes in a pipeline
  • Real pipes end in faucets (open or closed) and sometimes branch

19

slide-14
SLIDE 14

More Pipes

  • In the Mid-Term I example, we had all straight pipes in a pipeline
  • Real pipes end in faucets (open or closed) and sometimes branch

20

slide-15
SLIDE 15

More Pipes

  • In the Mid-Term I example, we had all straight pipes in a pipeline
  • Real pipes end in faucets (open or closed) and sometimes branch

21

slide-16
SLIDE 16

More Pipes

  • In the Mid-Term I example, we had all straight pipes in a pipeline
  • Real pipes end in faucets (open or closed) and sometimes branch

22

slide-17
SLIDE 17

More Pipes

  • In the Mid-Term I example, we had all straight pipes in a pipeline
  • Real pipes end in faucets (open or closed) and sometimes branch

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (define-struct straight (kind next)) (define-struct branch (next1 next2))

23-24

slide-18
SLIDE 18

Example Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) false

25

slide-19
SLIDE 19

Example Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) true

26

slide-20
SLIDE 20

Example Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-straight 'copper false)

27

slide-21
SLIDE 21

Example Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-straight 'copper (make-straight 'lead false))

28

slide-22
SLIDE 22

Example Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-branch (make-branch (make-straight 'copper true) false) (make-branch false false))

29

slide-23
SLIDE 23

Programming with Pipelines

; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline)

(define (func-for-pipeline pl) (cond [(boolean? pl) ...] [(straight? pl) ... (straight-kind pl) ... (func-for-pipeline (straight-next pl)) ...] [(branch? pl) ... (func-for-pipeline (branch-next1 pl)) ... (func-for-pipeline (branch-next2 pl)) ...]))

30-33

slide-24
SLIDE 24

Pipeline Examples

  • Implement the function water-running? which takes a pipeline and

determines whether any faucets are open

  • Implement the function modernize which takes a pipeline and converts

all 'lead straight pipes to 'copper

  • Implement the function off which takes a pipeline and turns off all the

faucets

  • Implement the function lead-off which takes a pipeline and turns off

all the faucets that receive water through a lead pipe

  • Implement the function twice-as-long which takes a pipeline and

inserts a 'copper straight pipe before every existing piece of the pipeline

34