function examples announcements hog contest rules
play

Function Examples Announcements Hog Contest Rules Up to two people - PowerPoint PPT Presentation

Function Examples Announcements Hog Contest Rules Up to two people submit one entry; Fall 2011 Winners Max of one entry per person Kaylee Mann Your score is the number of entries Yan Duan & Ziming Li Brian Prike & Zhenghao


  1. Function Examples

  2. Announcements

  3. Hog Contest Rules • Up to two people submit one entry; Fall 2011 Winners Max of one entry per person Kaylee Mann • Your score is the number of entries Yan Duan & Ziming Li Brian Prike & Zhenghao Qian against which you win more than Parker Schuh & Robert Chatham 50.00001% of the time • Strategies are time-limited Fall 2012 Winners • All strategies must be deterministic, Chenyang Yuan pure functions of the players' scores Joseph Hui • Winning entries will receive a paltry Fall 2013 Winners amount of extra credit Paul Bramsen • The real prize: honor and glory Sam Kumar & Kangsik Lee • See website for detailed rules Kevin Chen Fall 2014 Winners Alan Tong & Elaine Zhao Zhenyang Zhang Adam Robert Villaflor & Joany Gao Zhen Qin & Dian Chen Zizheng Tai & Yihe Li 3 cs61a.org/proj/hog_contest

  4. Hog Contest Winners Fall 2017 Winners Alex Yu and Tanmay Khattar Spring 2015 Winners Your name could be here FOREVER! James Li Sinho Chewi & Alexander Nguyen Tran Justin Yokota Zhaoxi Li Spring 2018 Winners Stella Tao and Yao Ge Eric James Michaud Ziyu Dong Fall 2015 Winners Xuhui Zhou Micah Carroll & Vasilis Oikonomou Fall 2018 Winners Matthew Wu Rahul Arya Anthony Yeung and Alexander Dai Jonathan Bodine Sumer Kohli and Neelesh Ramachandran Spring 2016 Winners Fall 2019 Winners Michael McDonald and Tianrui Chen Jet Situ and Lucas Schaberg Andrei Kassiantchouk Anthony Han and Hongyi Huang Benjamin Krieges Arthur Pan and Qingyuan Liu Spring 2020 Winners Fall 2016 Winners Andy Dong Cindy Jin and Sunjoon Lee Theodor Sion and Anish Kar Anny Patino and Christian Vasquez Shaun Diem-Lane Asana Choudhury and Jenna Wen Fall 2020 Winners Michelle Lee and Nicholas Chew 4

  5. Describing Functions

  6. Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery1(n): likes = is_prime One approach: n = 8 k = 1 1. Read the code while k < n: 2. Read the description options if likes(n): 3. Consider an example print(k) k = k + 2 all odd numbers but only if George likes n mystery1 prints ______ less than n ______ . mystery1 prints all odd numbers less than n that George likes. 6

  7. Boolean Favorites def likes(n): """Returns whether George Boole likes the non-negative integer n.""" ... def mystery2(n): One approach: i, j, k = 0, None, None 1. Read the code while i < n: 2. Read the description options if likes(i): 3. Consider an example if j != None and (k == None or i - j < k): k = i - j j = i i = i + 1 return k the smallest difference between There are no two two positive integers below n such integers that George likes mystery 2 returns ______ or returns None if ______ . 7

  8. Generating Environment Diagram

  9. A Day at the Beach def flip(flop): not true for flop == 1 flop>2 if ______: true for flop == 3 return None ______ lambda flip: 3 flip = ______ return flip def flop(flip): return flop flip, flop = flop, flip ______ flip(____)(3) flop(1)(2) 9

  10. Implementing Functions

  11. Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 4 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. 1 1 >>> remove(231, 3) Read the template 21 + 20 + 30 >>> remove(243132, 2) Implement without the template, then change 4313 + 200 your implementation to match the template. """ OR 21 231 kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: **digits 10* kept + last *10 Did you really return the right thing? kept = _______________________ digits + 1 231 21 digits = _____________________ Check your solution with the other examples kept return _______________________________ 11

  12. Implementing a Function def remove(n, digit): Read the description """Return all digits of non-negative N that are not DIGIT, for some 231 3 Verify the examples & pick a simple one non-negative DIGIT less than 10. >>> remove(231, 3) Read the template 21 >>> remove(243132, 2) Implement without the template, then change 4313 your implementation to match the template. """ OR kept, digits = 0, 0 If the template is helpful, use it. n > 0 while ________________________________: Annotate names with values from your chosen example n, last = n // 10, n % 10 last != digit Write code to compute the result if _______________________________: kept + last /10 Did you really return the right thing? kept = _______________________ digits + 1 21 digits = _____________________ Check your solution with the other examples round( kept * 10 ** (digits-1) ) return _______________________________ 12

  13. Decorators

  14. Function Decorators (Demo) Function decorator @trace1 Decorated def triple(x): function return 3 * x is identical to Why not just def triple(x): use this? return 3 * x triple = trace1(triple) 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend