CS106X
Handout 11
Autumn 2010
September 26
th
, 2010
Section Handout
Problem 1: Look And Say
The lookandsay sequence is the sequence of numbers beginning as:
1
11
21
1211
111221
312211
13112221
Each number in the sequence is generated by "reciting" its predecessor, and then capturing
what was said in a number format that should be clear from the example below.
Reciting 111221 out loud, you’d look and say: 3 ones, followed by 2 twos, followed by 1
one, or 312211.
Reading 312211 aloud, you’d say: 1 three, 1 one, 2 twos, 2 ones, or
13112221.
Even if a number doesn’t fall in the actual sequence, it should be clear how to generate its
lookandsay successor.
Write a function called
LookAndSay
, which takes a number in
string form, and returns its lookandsay form.
You can assume the incoming string
contains only digits, and that the longest run of any single digit will be less than or equal to
9.
/**
* Accepts the incoming string and generates the
* the number that would follow it in a lookandsay
* sequence.
*
* Examples:
*
LookAndSay("22") returns "22"
*
LookAndSay("132224444") returns "11133244"
*
LookAndSay("111119913333333") returns "51291173"
*/
string LookAndSay(string before);
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
Problem 2:
http://tinyurl.com
tinyurl.com
is a small website that constructs small, more easily managed URLs on
behalf of long, unwieldy ones.
As an example, here’s a link leading to a page that outlines
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 Cain,G
 Numerical digit, Natural number, Numeral system, URL redirection, URL shortening

Click to edit the document details