{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

19-Section-Handout

19-Section-Handout - CS106X Autumn 2010 Handout 19 October...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS106X Handout 19 Autumn 2010 October 11 th , 2010 Section Handout Problem 1: Generating Expressions Write the computeAllPossibilities function, which given a collection of one-digit numbers, expressed as a digit string (i.e. "14728" ), returns the set of all integers that can be generated by combining all of the one-digit numbers using + , - , * , / , and parentheses. For instance, computeAllPossibilities("1447") would return a set that includes -8 : 1 – 4 * 4 + 7 3 : 4 * 1 – 7 / 4 34 : 7 * 4 – 1 + 7 39 : 7 * (1 + 4) + 4 33 : (7 + 4) * (4 - 1) (Of course, the set of possibilities is larger than the four listed above.) Some clarifications and suggestions: o The digit string will only consist of the characters '0' through '9' , although there may be multiple instances of each digit. o The original digit string will never be empty. o Division is integer division, so that 5 / 4 * 4 equals 4 , not 5 . o Care must be taken to avoid division by zero so that it never contributes to any expression evaluation. o You must use all of the digits in the digit string, including duplicates.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}