Functional Problem Solving (CSC 151 2015F) : EBoards

CSC151.01 2015F, Class 24: Recursion Basics


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit Opportunities

Academic

Peer Support

Miscellaneous

How would you like to read a fanfic made by one of the most prominent friendly AI researchers in the entire world? And how would you like to learn about existential risk, rationality, and effective altruism through the medium of HARRY POTTER? (included at bottom of the email)

Check out the first chapter, and come to the first meeting (10/10) of Harry Potter and the Methods of Rationality club! Saturdays, 3pm in the CS commons.

We're hosting a hackathon for Spring 2016 that involves teaching people about the HPMOR fanfic through the medium of apps and websites.

http://hpmor.com/chapter/1

There's a shared Google doc for comments

https://docs.google.com/document/d/1qwx7qn3I0GviOElEoTYVVLkVKgFBPB685HbyRPW1hQE/edit

Also, like the FB page to get updates.

https://www.facebook.com/HPMORHackathon?fref=ts

Contact [wuruth17] to get more information.

Other Good Things

Questions

Reminder: The Components of Algorithms

We've seen all of these, including repetition

Some Challenges

You are given a problem.

Task one: You get a LIST of employees, you have to determine if NAME is an employee

    If the list is empty
      return false
    Otherwise, If (car lst) is "Sam"
      return true
    Otherwise
      Ask your assistant if Sam is in the (cdr of the list)
      Return whatever your executive assistant said

Task two: You get a list of employees, you want to determine how many employees you have, numEmployees(LIST)

    If the list is empty
      return 0
    Otherwise
      Ask your assistant to count the cdr of the list 
      Add 1

Task three: You get a list of employees, you want to determine how many employees have a name that starts with LETTER

    If the list is empty
      return 0
    Otherwise, If the car of the list starts with LETTER
      Ask your assistant to count the number of names that start with LETTER in the cdr of the list 
      Add 1 to that number
    Otherwise
      Ask your assistant to count the number of names that start with LETTER in the cdr of the list 
      Return that number

    If the list is empty
      return 0
    Otherwise
      Ask your assistant to count the number of names that start with LETTER in the cdr of the list
      If your card starts with LETTER, add 1 to that number
      Otherwise, just give back that number

Recursion: Key Ideas

Model

Expressing recursion in Scheme

(define contains?
  (lambda (lst name)
    (cond
      [(null? lst)
       #f]
      [(equal? (car lst) name)
       #t]
      [else
       (contains? (cdr lst) name)])))

Lab