Arithmetic Sequence - find hidden
Description:
This is part of what will be a series based around code that finds arithmetic sequences embedded within a group of unique numbers. It was inspired by a puzzle in a publication titled Giant Book of Mensa Mind Challenges.
This first kata is to create an algorithm to identify such sequences. It's expected that this algorithm can be used for some of the subsequent, more complex katas.
An "Arithmetic Sequence" for this kata is defined as a sequence of 3 integers such that the difference of any two successive members of the sequence is a constant. Specifically:
- given three distinct integers a, b and c
- where a < b < c then to be considered a valid Arithmetic Sequence:
- b - a must equal c - b.
In this kata, you are given an array of unique integers. Your code should find the first valid Arithmetic Sequence that can be constructed from any 3 integers in the group.
- The response must be in sequence order (lowest to highest integer)
- By first, that means processing should preserve order of the array, such that the first located member of the sequence will have the lowest indexed first member from the array, or the lowest indexed second located member should two sequences start with the same first member
- If no valid sequence is found, the function should return an empty array. An input group containing less than 3 numbers is considered as not found.
Examples:
- [1,4,7,9,13] returns [1,4,7]
- the only valid sequence
- [4,13,9,1,7] returns [1,4,7]
- the only valid sequence
- [1,4,7,9,11] returns [1,4,7]
- the first valid sequence
- member 1 at index 0 for set[1,4,7]
- member 7 at index 2 for set[7,9,11]
- the first valid sequence
- [99,11,4,7,9,1] returns [7,9,11]
- the first valid sequence
- member 11 at index 1 for set[7,9,11]
- member 4 at index 2 for set[1,4,7]
- the first valid sequence
- [13,20,17,9,27] returns [13,20,27]
- the first valid sequence
- member 13 at index 0 for both valid sets [9,13,17] and [13,20,27]
- second member 20 at index 1 for set [13,20,27]
- second member 17 at index 2 for set [9,13,17]
- the first valid sequence
- [1,2,4,9,25] returns []
- no sequence found
Similar Kata:
Stats:
Created | Dec 4, 2019 |
Published | Dec 4, 2019 |
Warriors Trained | 240 |
Total Skips | 65 |
Total Code Submissions | 324 |
Total Times Completed | 42 |
Python Completions | 33 |
JavaScript Completions | 12 |
Total Stars | 3 |
% of votes with a positive feedback rating | 76% of 23 |
Total "Very Satisfied" Votes | 14 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 18 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |