Given an integer , generate the first terms of the Aronson’s sequence.
Aronson’s sequence is an infinite sequence of integers obtained from the index of T (or t) in the sentence:
“T is the first, fourth, eleventh, sixteenth, … letter in this sentence.”
- The first occurrence of T in the sentence is at index 1 (1-based indexing) and the number mentioned first is first i.e. 1
- Similarly, the second occurrence of t in the sentence is at index 4 and the number mentioned second is fourth i.e. 4
- Similarly, the third occurrence of t in the sentence is at index 11 and the number mentioned third is eleventh i.e. 11
- Likewise, The series continues as 1, 4, 11, 16, …
Input: n = 3
Output: 1, 4, 11
Input: n = 6
Output: 1, 4, 11, 16, 24, 29
Approach: A simple idea is to store the string “T is the” to get the first two terms of the sequence. For each of these terms, convert it to words in the ordinal form and append to the string and calculate the value of the next higher terms. Repeat this process for each of the subsequent higher terms generated for n-2 times to generate the first n terms of the Aronson’s sequence.
For converting a number to words refer here.
Below is the implementation of the above approach:
1, 4, 11, 16, 24, 29,
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count Possible Decodings of a given Digit Sequence
- Look-and-Say Sequence
- Farey Sequence
- G-Fact 21 | Collatz Sequence
- Complete the sequence generated by a polynomial
- Juggler Sequence
- Padovan Sequence
- Aliquot Sequence
- Recaman's sequence
- Thue-Morse sequence
- Sum of the sequence 2, 22, 222, .........
- Sylvester's sequence
- Golomb sequence
- Digit - Product - Sequence
- Find n-th term in sequence 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, ....
- k-th number in the Odd-Even sequence
- Newman-Conway Sequence
- Sum of Arithmetic Geometric Sequence
- Connell Sequence
- Stern-Brocot Sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : 29AjayKumar