11-Section-Handout - CS106X Autumn 2010 Handout 11...

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

View Full Document Right Arrow Icon
CS106X Handout 11 Autumn 2010 September 26 th , 2010 Section Handout Problem 1: Look And Say The look-and-say 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 look-and-say successor. Write a function called LookAndSay , which takes a number in string form, and returns its look-and-say 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 look-and-say * sequence. * * Examples: * LookAndSay("22") returns "22" * LookAndSay("132224444") returns "11133244" * LookAndSay("111119913333333") returns "51291173" */ string LookAndSay(string before);
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 4

11-Section-Handout - CS106X Autumn 2010 Handout 11...

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

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