19-Section-Handout

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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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....
View Full Document

This note was uploaded on 01/13/2011 for the course CS 106X taught by Professor Cain,g during the Fall '08 term at Stanford.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online