Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help making this equation a generator. It should count the numbers in the previous number to generate a new number. So 2, 12,

I need help making this equation a generator. It should count the numbers in the previous number to generate a new number. So 2, 12, 1112, 3112, 132112, 1113122112, 311311222112, 13211321322112, ect. Mine works when I enter a hard number, but i cant figure out how to make it a generator that takes no parameters. The first 2 numbers can be hard coded. So if 1, returns 2, if 2 returns 2. Then the generator should do the rest.

def generate(number): repeated = 1 lst = [int(d) for d in str(number)] repeat_list = [] if number == 2: pass pos = 1 while pos <= len(lst)-1: value = lst[pos] last = lst[pos - 1] if value == last: repeated += 1 pos += 1 print(True) elif value != last: repeat_list.append(repeated) repeat_list.append(last) repeated = 1 pos += 1 repeat_list.append(repeated) repeat_list.append(lst[len(lst)-1]) s = [str(i) for i in repeat_list] num = int("".join(s)) return num print(generate(12)) print(generate(1112))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago