5 kyu

Shortest Code: Collatz Array(Split or merge)

71 of 75myjinxin2015

Description:

Shortest code: Collatz Array(Split or merge)

(Code length limit: 130)

This is the challenge version of coding 3min series. If you feel difficult, please complete the simple version

Task

Give you an number array arr, and a number n(n>=0), In accordance with the rules of kata, returns the array after n times changes .

Rules: In every time of change, when the element of array is an odd number, it changed by x*3+1(element is x), and merge with next element arr[i]+arr[i+1](i is index of element, if it's the last element of array, do not merge with other element);when the element is a even number, changed by x=x/2,and split to two element.

Example:

arr=[3,4,5]
n=0: [3,4,5]
n=1: [14,16] 
element1=>3*3+1==10, then merge element2, 10+4=14; 
element2 merged by element1, so element2 disappeared;
element3=>5*3+1==16, no element merge
n=2: [7,7,8,8]
element1 split into 7,7; element1 split into 8,8;
n=3: [29,4,4,4,4]
n=4: [92,2,2,2,2,2,2]
n=5: [46,46,1,1,1,1,1,1,1,1,1,1,1,1]
n=6: [23,23,23,23,5,5,5,5,5,5]
n=... [...]

Code length calculation

In javascript, we can't get the user's real code, we can only get the system compiled code. Code length calculation is based the compiled code.

For example:

If you typed sc=x=>x+1
after compile, it will be:sc=function(x){return x+1;}

Series

Puzzles
Games
Restricted

Stats:

CreatedMar 31, 2016
PublishedMar 31, 2016
Warriors Trained193
Total Skips3
Total Code Submissions869
Total Times Completed75
JavaScript Completions71
Python Completions6
Total Stars4
% of votes with a positive feedback rating90% of 40
Total "Very Satisfied" Votes33
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • mauro-1 Avatar
  • dfhwze Avatar
Ad