Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

X_Soda

  • 2 years ago

The solution zip file for problem set nine appears to be down. This particular problem set is relatively straightforward, but I still like to check my code against that of the pros. Does anyone have a copy of ps9 solutions from the course, or have solutions that they find to be exceedingly elegant?

  • This Question is Closed
  1. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    1 Attachment
  2. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    i wouldn't expect the solutions to be written by 'the pros' they blunder here and there 2011 class right? did you run the test module?

  3. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I've run the modules, but I just want to compare my code with others' to assess efficiency issues. This is for the course with Guttag. The ps9_writeup appears to be for a different course or at least a different problem set that I have yet to get to.

  4. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    which year, 2011 or 2008?

  5. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    2011

  6. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    here is greedy function i wrote - a bit different: http://dpaste.com/810054/

  7. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    another greedy: http://dpaste.com/810055/ and a bruteforce: http://dpaste.com/810056/

  8. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Nice looking function... one question: you take comparator as an argument for a greedy function, but when running the code, what do you pass into it? I'm assuming you're using the comparators that take the arguments subInfo1 and subInfo2, but since sort needs to iterate over all of the subInfo to do its magic, what do you pass into the argument for greedy function? When I just try to pass in the name of, say, cmpWork, it asks me for arguments.

  9. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    so that first function, greedy_sort(), doesn't really use those comparator functions, it just uses them to decide how to sort the list then the last bit picks off the first items in the list till it runs out of work

  10. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I get that, but the way they have set up the greedy_function is that it takes the arguments (subjects, maxWork, comparator), so you have to pass in a comparator function of some sort if you adhere to their original code. But every comparator function requires the arguments (subInfo1, subInfo2); so what should one pass into those when calling the greedy_function?

  11. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    ahh - one of the things they want you to learn is that a function is an object just like a str or an int or a dictionary or a tuple are objects and that you can pass a function as an argument to another function. when you do that you just pass the function object without arguments.

  12. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    when i try to pass it without arguments I get this error: TypeError: cmpValue() takes exactly 2 arguments (0 given)

  13. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    this is what I'm trying to call print greedyAdvisor(loadSubjects(SUBJECT_FILENAME), 30, cmpValue())

  14. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://dpaste.com/810059/ pass it without the parens

  15. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    still get TypeError: cmpValue() takes exactly 2 arguments (1 given)

  16. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://dpaste.com/810060/

  17. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    did you see my examples?

  18. X_Soda
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yeah, there must be something else wrong with the way I'm setting up the code... I'll have to go back and debug the rest of the function. thanks!

  19. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    http://dpaste.com/810061/ when you get it working, here is a function that tests greedy using the same concepts - functions as objects - note it uses a small dictionary with a different name than the one used in the 2011 pset

  20. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.