Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Consider the sequence of integers: 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ... It is referred to as the look-and-say sequence with seed
2. Consider the sequence of integers: 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ... It is referred to as the look-and-say sequence with seed 1. The seed refers to the first element of the sequence. Each subsequent element in the sequence is generated from its predecessor as follows: group adjacent occurrences of the same digit and then use two digits to indicate, for each group, how many are in it and which digit it contains, respectively. For example, the seed, 1, is read as "one 1", which translates to the second element, 11. We read that as "two 1's", which translates to the third element, 21. Moving forward to the fourth element, 1211, we read it as "one 1, then one 2, then two 1's", which translates to the fifth element, 111221. Of course, each different choice of a seed results in Updated January 26, 2020 COSC 2436 520 a different sequence. Write a program that, given as input a non-negative integer j ( to 1,000,000) and a positive integer k, produces as output the first k elements of the look-and-say sequence with seed j. Assume k is a single digit 1 - 9. Error check. For each look-and-say sequence described in the input, the program should generate as output a single line containing the elements of that sequence. Finally, ask the user if he/she wishes to run the program again. Error check. Use any data structure of your choice. Refer to the sample output below. Sample Run: Enter the integer seed: 1 Enter the terms to generate: 8 The look-and-say sequence is: 1 11 21 1211 111221 312211 13112221 1113213211 Run Again (Y/N): y Enter the integer seed: 34 Enter the terms to generate: 1 The look-and-say sequence is: 34 Run Again (Y/N): N Name the program: SeeAndSayxx.java or SeeAnd Say XX.cpp, where XX are your initials
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started