Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lagged Fibonacci Digits The Fibonacci sequence is a sequence of integer values, beginning with 0 and 1, where each term (after the first two) is

Lagged Fibonacci Digits

The Fibonacci sequence is a sequence of integer values, beginning with 0 and 1, where each term (after the first two) is equal to the sum of the two preceding terms. For example, the first few terms of the Fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, etc.

This type of behavior can be used to develop a type of pseudorandom number generator called an Additive Lagged Fibonacci Generator (used in things like the Soviet VIC cipher from the 1950s). The process described below is often called chain addition.

Each number or term in the sequence is a single digit. To generate the next term in the sequence, we add two adjacent digits from the sequence, modulo 10, and append the new digit to the end of the sequence. We always begin with the first two digits (elements) of the starting sequence.

Example: 1. Consider the starting list 7; 2; 9; 1; 6; 7 The first two digits are 7 and 2. 7 + 2 modulo 10 is 9, so we append 9 to the end of the list to get 7; 2; 9; 1; 6; 7; 9 2. Next, we examine the second and third digits. 2 + 9 is 11. 11 modulo 10 is 1, so we append 1 to the end of the list to get 7; 2; 9; 1; 6; 7; 9; 1 3. For the third step, we examine the third and fourth digits. 9 + 1 is 10; 10 modulo 10 is 0, so we append 0 to our list to get 7; 2; 9; 1; 6; 7; 9; 1; 0 4. Subsequent terms (digits) in the sequence follow the same general pattern.

Complete the alfg() function, which takes two arguments: a list containing an initial integer sequence with at least 2 digits, and a positive integer representing the number of rounds of chained addition to perform. The function returns a new list: either the last five digits of the sequence after all of the requested rounds are complete, or the entire list if it has fewer than five terms (digits).

Examples:

Function Call Return Value

alfg([5,0,2], 1) [5,0,2,5] alfg([1,2,3,4], 5) [3,5,7,7,8] alfg([2,6,5,3,9,1], 20) [1,7,6,7,1] alfg([6,7,3,4,5], 40) [3,9,4,7,5]

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

List and describe the five most common types of personal computers.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago