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,
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Sum of the sequence 2, 22, 222, .........
- Look-and-Say Sequence
- Increasing sequence with given GCD
- k-th number in the Odd-Even sequence
- Find F(n) when F(i) and F(j) of a sequence are given
- Connell Sequence
- Gould's Sequence
- Scala Sequence
- Golomb sequence
- Sylvester's sequence
- Aliquot Sequence
- Recaman's sequence
- Padovan Sequence
- Juggler Sequence
- Farey Sequence
- Beatty sequence
- Gijswijt's Sequence
- Alcuin's Sequence
- Program to find sum of the given sequence
- Sum of first N terms of Quadratic Sequence 3 + 7 + 13 + ...
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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