Question

Suppose we select some initial number ? and then build the sequence of values by the...

Suppose we select some initial number ? and then build the sequence of values by the following 0
Hint: each time you find a multiple of each picked number in the initial list [1:n], make it zero. Elements
not equal to zero are primes. This works a lot better than trying to ‘erase’ the element. Because each
time you erase an element the remaining indexes roll over, i.e., they change.
1. Find the possible ranges of a and b for which a+b+c is around 300 (include the paper & pencil analysis at the end of your report)
2. Compute c for each combination of a and b
3. Verifyif?+?+?=300 and?2 +?2 =?2 and?<?<?
4. Print results
rules:
? =1? forvaluesof? even ? 2?−1 ?−1
? =1(3? +1)forvaluesof ? odd ? 2 ?−1 ?−1
As long as you reach 1 the sequence must stop. If ? is odd, the next element in the sequence grows, and if it is ?−1
even, the next element in the sequence decreases. With different starting values, examples of the generated sequences are:
111 22,1 2
3 3, 5, 8, 4, 2, 1 8
4 4, 2, 1 4
Starting value
? 0
?? ?? ?? ?? ...
Maximum value in the sequence
Page | 5

5 5, 8, 4, 2, 1 8
6 6, 3, 5, 8, 4, 2, 1 8
7 7, 11, 17, 26, 13, 20, 10, 5, 8, 4, 2, 1 26
If you decide not to stop, after the sequence reaches 1 the sequence enters the infinite loop as 1 2 1 2 1 2. You need to avoid this effect in your code. You don’t want an infinite loop.
Write code to
1. Compute the elements of the sequence for starting values from 1 to 25. Make a plot of the starting value
versus the number of elements in the sequence to get 1. E.g., if the starting ? = 7, the number of 0
elements in the sequence are 12, these are: 7, 11, 17, 26, 13, 20, 10, 5, 8, 4, 2, 1. An example of the plot is:
2. Calculate what is the maximum value reached in the sequence for each starting value.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Pythogoreon Triplets
sum = 300
# For all values of a from (0, 300)
for a in range(sum + 1):
    # For all values of b > a and b < 300
    for b in range(a + 1, sum + 1):
        # For all values of c > b and c < 300
        for c in range(b + 1, sum + 1):
            # If sum(a + b + c) == 300 and a^2 + b^2 = c^2
            if (a + b + c == sum) and (a**2 + b**2 == c**2):
                # Print the numbers
                print(f'A : {a}, B : {b}, C : {c}')

# functions to calculate T based on odd or even
def calculateTEven(Ti):
    return int(Ti * 0.5)
def calculateTOdd(Ti):
    return int(0.5 * (3 * Ti + 1))


sequences = []
for T in range(1, 26):
    T0 = T
    seq = []
    while True:
        seq.append(T0)
        if T0 == 1:
            break
        if(T0 % 2 == 0):
            T0 = calculateTEven(T0)
        else:
            T0 = calculateTOdd(T0)
    sequences.append(seq)

print(f'T0\tMaximum\t\tSeries')
for i in range(1, 26):
    print(f'{i}\t   {max(sequences[i - 1])}\t\t{sequences[i - 1]}')

import matplotlib.pyplot as plt
# get the number of elements in each sequence
seq_lengths = [len(seq) for seq in sequences]
# get the T0 (1 to 25)
starting_numbers = [i for i in range(1, 26)]
# plot the graph
plt.plot(starting_numbers, seq_lengths)
# Add title
plt.title("Starting Number VS Number of Elements in Seq")
# Add X label
plt.xlabel("Starting Number")
# Add Y Label
plt.ylabel("Number of Elements per sequence")
# Display the plot
plt.show()

Add a comment
Know the answer?
Add Answer to:
Suppose we select some initial number ? and then build the sequence of values by the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is using MATLAB 2. Fibonacci sequence: A Fibonacci sequence is composed of elements created by...

    this is using MATLAB 2. Fibonacci sequence: A Fibonacci sequence is composed of elements created by adding the two previous elements. The simplest Fibonacci sequence starts with 1,1 and proceeds as follows: 1, 1, 2, 3, 5, 8, 13, . However, a Fibonacci sequence can be created with any two starting numbers. Create a MATLAB function called FL_fib_seq' (where F and L are your first and last initials) that creates a Fibonacci sequence. There should be three inputs. The first...

  • The Syracuse sequence is generated by starting with a natural number and repeatedly applying the following...

    The Syracuse sequence is generated by starting with a natural number and repeatedly applying the following function until reaching 1: ???(?) = { ?/2 if x is even { 3? + 1 if x is odd For example, the Syracuse sequence starting with 5 is: 5, 16, 8, 4, 2, 1. It is an open question in mathematics whether this sequence will always go to 1 for every possible starting value. Write a function in Python (called syracuse) that gets...

  • IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we...

    IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we do the following: If the integer is odd, we multiply by 3 and add 1. If the integer is even, we divide by 2. It is hypothesized that the above sequence will always converge to the value of 1, regardless of any valid initial choice. This hypothesis is known as the Collatz Conjecture. For example, if we start at 5, the numbers generated by...

  • Fibonacci numbers – for loops We’ll define the Fibonacci numbers to be an integer sequence starting...

    Fibonacci numbers – for loops We’ll define the Fibonacci numbers to be an integer sequence starting with 1, 1, and where each subsequent element is got by adding the previous two elements: 1, 1, 2, 3, 5, 8, . . . (Mathematicians start with 0, 1, . . . , but we want to avoid zeros because you can’t take their log. ) Write a python programme in a Jupyter notebook which uses a for-loop to fill an array with...

  • Suppose an array contains the sequence of values 4, 5, 6, 7, 8, and 10. If...

    Suppose an array contains the sequence of values 4, 5, 6, 7, 8, and 10. If the binary search algorithm is used to search the array, how many elements must be visited to determine that element 3 is not in the array? Select one: a. 4 b. 6 c. 3 d. 5

  • In this assignment we are asking the user to enter two number values, the starting and...

    In this assignment we are asking the user to enter two number values, the starting and ending numbers for our application. Having these values, we then construct a loop that will increment by one (1) from the starting number through (and including) the ending number. Within this loop we will check the current value of our number to see if it is evenly divisible by 3, then by 5, and then by both 3 and 5. We will output all...

  • Let's say you are given a sequence of distinct positive numbers. We want to find a...

    Let's say you are given a sequence of distinct positive numbers. We want to find a subsequence with the maximum possible sum, with the restriction that we are not allowed to take three consecutive elements from the original sequence. For example, for input 1, 6, 5, 2, 7, 9, 3, 4, the subsequence with the maximum possible sum is 6, 5, 7, 9, 4 (we have two pairs of consecutive elements 6, 5 and 7, 9 but not three consecutive...

  • In this assignment we are asking the user to enter two number values, the starting and...

    In this assignment we are asking the user to enter two number values, the starting and ending numbers for our application. Having these values, we then construct a loop that will increment by one (1) from the starting number through (and including) the ending number. Within this loop we will check the current value of our number to see if it is evenly divisible by 3, then by 5, and then by both 3 and 5. We will output all...

  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous...

    USING MATLAB 7. A Fibonacci sequence is composed of elements created by adding the two previous elements. The simplest Fibonacci sequence starts with 1, 1 and proceeds as follows: 1,1,2,3,5,8,13, So, if f(1)-1 and f(2) -1, then f(3)-2)+f(1) We can represent this pattern as f(x) - f(x-1)+f(x-2). A Fibonacci sequence can be created with any two numbers. Prompt the user to enter the first two numbers in a Fibonacci sequence and the total number of elements requested in the sequence....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT