Lab 0(L): I Can, Therefore I Must JUnit: P2J12Test.java A jovial old grandpa mathematician straight out of central casting often appearing in Numberphile videos, Neil Sloane is behind the Online Encyclopedia of Integer Sequences, a wonderful tool for combinatorial explorations. This lab has you implement two methods to generate elements of two interesting integer sequences whose chaotic behaviour emerges from iteration of a deceptively simple rule. Both sequences are filled in ascending order in a greedy fashion, so that each element is always the smallest number that avoids creating a conflict with the previously generated elements in the sequence. Note that being defined by mathematicians, these sequences start from the position one instead of the position zero, the way how sequences work for us budding computer scientists who have to actually get our hands dirty and therefore prefer zero-based indexing. When asked to produce the first n elements of the sequence, these methods should create an array with n + 1 elements. The zeroth element that we don’t really care about is set to zero, after which all the fun begins. public static int[] forestFire(int n) Explained in the YouTube video “Amazing Graphs II”, the first two elements are both equal to one. Then, each element a[i] is the smallest positive integer for which no positive integer offset j creates an arithmetic progression of three equally spaced elements backwards in the sequence from the position i. More formally, the difference a[i]-a[i-j] may never equal the difference a[i-j]-a[i-2*j], even if your worst enemy got to pick the position i and the offset j. public static int[] remySigrist(int n) As explained in the YouTube video “Amazing Graphs III”, this sequence devised by Ré my Sigrist assigns to every positive integer a colour, encoded as a natural number. After the first colour assignment a[1]=0, each a[i] is the smallest natural number c for which the binary representation of any earlier position j that has already been assigned the colour c has any bits turned on common with the binary representation of the position i. This can be checked quickly with the expression i&j == 0, where & is the bitwise and operator of Java. This problem can be solved with two nested for-loops. The outer loop iterates through the positions of a. The inner loop counts upwards through the colours until it finds one that does not create a conflict. However, you should not be a “Shlemiel” who uses a third level inner loop to determine whether the current colour candidate c creates a conflict. Instead, you should trade space for time with a second integer array taken whose each element taken[c] gathers all the bits that are on in any previous position that was assigned the colour c. Then, whenever you to assign a[i]=c, update this lookup table with the assignment taken[c] |= i, where | is the bitwise or operator of Java, and |= is its assignment shorthand analogous to += and other such more familiar forms.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Lab 0(L): I Can, Therefore I Must
JUnit: P2J12Test.java
A jovial old grandpa mathematician straight out of central casting often appearing in Numberphile
videos, Neil Sloane is behind the Online Encyclopedia of Integer Sequences, a wonderful tool for
combinatorial explorations. This lab has you implement two methods to generate elements of two
interesting integer sequences whose chaotic behaviour emerges from iteration of a deceptively
simple rule. Both sequences are filled in ascending order in a greedy fashion, so that each element
is always the smallest number that avoids creating a conflict with the previously generated
elements in the sequence.
Note that being defined by mathematicians, these sequences start from the position one instead of
the position zero, the way how sequences work for us budding computer scientists who have to
actually get our hands dirty and therefore prefer zero-based indexing. When asked to produce the
first n elements of the sequence, these methods should create an array with n + 1 elements. The
zeroth element that we don’t really care about is set to zero, after which all the fun begins.
public static int[] forestFire(int n)
Explained in the YouTube video “Amazing Graphs II”, the first two elements are both equal to one.
Then, each element a[i] is the smallest positive integer for which no positive integer offset j
creates an arithmetic progression of three equally spaced elements backwards in the sequence
from the position i. More formally, the difference a[i]-a[i-j] may never equal the difference
a[i-j]-a[i-2*j], even if your worst enemy got to pick the position i and the offset j.
public static int[] remySigrist(int n)
As explained in the YouTube video “Amazing Graphs III”, this sequence devised by Ré my Sigrist
assigns to every positive integer a colour, encoded as a natural number. After the first colour
assignment a[1]=0, each a[i] is the smallest natural number c for which the binary
representation of any earlier position j that has already been assigned the colour c has any bits
turned on common with the binary representation of the position i. This can be checked quickly
with the expression i&j == 0, where & is the bitwise and operator of Java.
This problem can be solved with two nested for-loops. The outer loop iterates through the positions
of a. The inner loop counts upwards through the colours until it finds one that does not create a
conflict. However, you should not be a “Shlemiel” who uses a third level inner loop to determine
whether the current colour candidate c creates a conflict. Instead, you should trade space for time
with a second integer array taken whose each element taken[c] gathers all the bits that are on
in any previous position that was assigned the colour c. Then, whenever you to assign a[i]=c,
update this lookup table with the assignment taken[c] |= i, where | is the bitwise or operator
of Java, and |= is its assignment shorthand analogous to += and other such more familiar forms.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY