[Tutor] writing a function

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Jan 22 19:36:06 EST 2004



On Thu, 22 Jan 2004, Christopher Spears wrote:

> This is a programming problem that I have been given:

Hi Christopher,


Before we go further, we have to state outright that we are prohibited
from giving much help on homework problems.  We'll try to point you toward
tutorial resources that should make a concept more clear.


If you find yourself getting really stuck, we suggest you take a look at
G. Polya's "How To Solve It":

    http://www.math.utah.edu/~alfeld/math/polya.html

His cookbook approach to solving difficult problems is invaluable.  His
target audience was mathematicians, but his advice applies remarkably well
for programmers too.



> Write a function that accepts an arbitrary number of lists and returns a
> single list with exactly one occurrence of each element that appears in
> any of the input lists.
>
> For some reason, this problem has left me stumped.  Suggestions, anyone?

Tell us what about the problem is getting you stuck.  You've stated the
problem, but you've neglected to tell us what you're having difficulty
with.  What have you tried so far?



Have you tried to simplify the problem?  If you're having problem with the
word "arbitrary" in:

    "Write a function that accepts an arbitrary number of lists..."

then you may want to modify the problem slightly.  Modifying the problem
is often a good strategy in solving problems.  It gives you more leeway to
experiment with solutions, and the progress you make on the modified
problem may be very helpful when you're solving the original.


One way to simplify it is:

    "Write a function that accepts two lists..."


Can you make progress on this version of the problem?




Good luck to you.




More information about the Tutor mailing list