6 kyu
Shortest Code : Special factor
158myjinxin2015
Description:
Shortest Code : Special factor
(Code length limit: 110 chars)
This is the challenge version of coding 3min series. If you feel difficult, please complete the simple version
Task
Give you a positive integer n
, find out the special factor.
What is the special factor? An example: if n has a factor x, we can convert them into binary string, if binary string of n contains binary string of x, we can say, x is a special factor of n.
Return an array, include all of the special factor(Ascending order)
Example
example1:
n = 6 factor of n: 1,2,3,6
convert them to binary string:
n ==> "110"
factors: 1==>"1" 2==>"10" 3==>"11" 6==>"110"
Hmmm... It seems "110" contains all of them.
So, sc(6) should return [1,2,3,6]
example2:
n = 15 factor of n: 1,3,5,15
convert them to binary string:
n ==> "1111"
factors: 1==>"1" 3==>"11" 5==>"101" 15==>"1111"
Hmmm... "1","11","1111" are special factors, but "101" is not.
So, sc(15) should return [1,3,15]
example3:
n = 100 factor of n: 1,2,4,5,10,20,25,50,100
convert them to binary string:
n ==> "1100100"
factors: 1==>"1" 2==>"10" 4==>"100" 5==>"101" 10==>"1010"
20==>"10100" 25==>"11001" 50==>"110010" 100==>"1100100"
Hmmm... "1","10","100","11001","110010","1100100" are special factors,
"101","1010","10100" are not.
So, sc(100) should return [1,2,4,25,50,100]
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
Puzzles
Games
Restricted
Similar Kata:
Stats:
Created | Apr 13, 2016 |
Published | Apr 13, 2016 |
Warriors Trained | 243 |
Total Skips | 2 |
Total Code Submissions | 907 |
Total Times Completed | 158 |
JavaScript Completions | 158 |
Total Stars | 5 |
% of votes with a positive feedback rating | 93% of 60 |
Total "Very Satisfied" Votes | 52 |
Total "Somewhat Satisfied" Votes | 7 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |