View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Question 1(String to Factorial)

1. (20) String to Factorial

Write a method stringToFactorial: that takes as input a string of positive integers separated by spaces (e.g. 12 13 14) and returns a collection of the factorials of each of the numbers in the string (e.g., an OrderedCollection(479001600 6227020800 87178291200)). Hints: Strings understand findTokens: which inputs a string of delimeters (e.g., to specify a space) and returns a collection of strings that were separated by any of those delimeters (e.g., (12 13 14). Hint2: Integers understand factorial.

Answer (simplest version):

stringToFactorial: integers
^(integers findTokens: ' ') collect: [ :int | int asNumber factorial]

6 points for breaking the string into tokens
3 points for doing something to convert the tokens into numbers (don't worry if they got they exact method name - as Number)
8 points for doing something with the resulting collection to apply factorial to each of the elements
3 points for getting the results into a new collection and returning it

Link to this Page