COMP302: Programming Languages and Paradigms
Prof. (Sec 01) Francisco Ferreira (Sec 02)
School of Computer Science Mc
Copyright By PowCoder代写 加微信 powcoder
Week 7-1, Fall 2017
Today: Exceptions (cont.)
Primary benefits:
• Force you to consider the exceptional case
• Allows you to segregate the special case from other cases in the code (avoids clutter!)
• Diverting control flow!
COMP302: Programming Languages and Paradigms 2 / 5
Backtracking
• General algorithm for finding all (or some) solutions incrementally – abandons partial candidates as soon as it determines that is cannot lead to a successful solution.
• Important tool to solve constraint satisfaction problems such as crosswords, puzzles, Sudoko, etc.
COMP302: Programming Languages and Paradigms 3 / 5
Todays Example: Got Change?
COMP302: Programming Languages and Paradigms 4 / 5
Todays Example: Got Change?
Implement a function change. It takes as input a list of available coins and an amount amt. It returns the exact change for the amount (i.e. a list of available coins, [c1;c2; … ;cn] such that c1 + c2 + … + cn = amt), if possible; otherwise it raises an exception Change.
COMP302: Programming Languages and Paradigms
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com