-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence_analyzer.py
28 lines (23 loc) · 974 Bytes
/
sequence_analyzer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
import ipywidgets as widgets
import pandas as pd
class SequenceComparison:
def __init__(self, max_length):
self.max_length = max_length
def generate_collatz(self, start):
sequence = [start]
while start != 1 and len(sequence) < self.max_length:
start = start // 2 if start % 2 == 0 else 3 * start + 1
sequence.append(start)
return sequence[:self.max_length]
def generate_arithmetic(self, start, difference):
return [start + i * difference for i in range(self.max_length)]
def generate_geometric(self, start, ratio):
return [start * (ratio ** i) for i in range(self.max_length)]
def generate_fibonacci(self):
sequence = [0, 1]
while len(sequence) < self.max_length:
sequence.append(sequence[-1] + sequence[-2])
return sequence[:self.max_length]