6 kyu

Find the integer sequences

285 of 430myjinxin2015

Description:

When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said

Description:

Complete function findSequences. It accepts a positive integer n. Your task is to find such integer sequences:

Continuous positive integer and their sum value equals to n

For example, n = 15 
valid integer sequences:
[1,2,3,4,5]  (1+2+3+4+5==15)
[4,5,6]          (4+5+6==15)
[7,8]              (7+8==15)

The result should be an array [sequence 1,sequence 2...sequence n], sorted by ascending order of the length of sequences; If no result found, return [].

Some examples:


findSequences(3) === [[1,2]]

findSequences(15) === [[7,8],[4,5,6],[1,2,3,4,5]]

findSequences(20) === [[2, 3, 4, 5, 6]]

findSequences(100) === [[18, 19, 20, 21, 22], [9, 10, 11, 12, 13, 14, 15, 16]]

findSequences(1) === []
Mathematics
Algorithms

Stats:

CreatedNov 15, 2016
PublishedNov 15, 2016
Warriors Trained1155
Total Skips40
Total Code Submissions1341
Total Times Completed430
JavaScript Completions285
Haskell Completions27
Python Completions129
Total Stars33
% of votes with a positive feedback rating97% of 83
Total "Very Satisfied" Votes78
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes0
Total Rank Assessments4
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • mauro-1 Avatar
Ad