Shortest Code: Collatz Array(Split or merge)
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
- Bug in Apple
- Father and Son
- Jumping Dutch act
- Planting Trees
- Reading a Book
- Eat watermelon
- Special factor
- Symmetric Sort
- Are they symmetrical?
- Guess the Hat
- Find the murderer
- Give me the equation
- Balance Attraction
- Max Value
- Regular expression compression
- Remove screws I
- Remove screws II
- Collatz Array(Split or merge)
- Trypophobia
- Virus in Apple
- Waiting for a Bus
- Tidy up the room
Similar Kata:
Stats:
Created | Mar 31, 2016 |
Published | Mar 31, 2016 |
Warriors Trained | 193 |
Total Skips | 3 |
Total Code Submissions | 869 |
Total Times Completed | 75 |
JavaScript Completions | 71 |
Python Completions | 6 |
Total Stars | 4 |
% of votes with a positive feedback rating | 90% of 40 |
Total "Very Satisfied" Votes | 33 |
Total "Somewhat Satisfied" Votes | 6 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |