7 kyu
Simple Fun #106: Is Thue Morse?
233 of 688myjinxin2015
Description:
Task
Given a sequence of 0s and 1s, determine if it is a prefix of Thue-Morse sequence.
The infinite Thue-Morse sequence is obtained by first taking a sequence containing a single 0 and then repeatedly concatenating the current sequence with its binary complement.
A binary complement of a sequence X is a sequence Y of the same length such that the sum of elements X_i and Y_i on the same positions is equal to 1 for each i.
Thus the first few iterations to obtain Thue-Morse sequence are:
0
0 1
0 1 1 0
0 1 1 0 1 0 0 1
...
Examples
For seq=[0, 1, 1, 0, 1]
, the result should be true
.
For seq=[0, 1, 0, 0]
, the result should be false
.
Inputs & Output
[input]
integer arrayseq
A non-empty array.
Constraints:
1 <= seq.length <= 1000
seq[i] ∈ [0,1]
[output]
a boolean value
true
if it is a prefix of Thue-Morse sequence. false
otherwise.
Puzzles
Similar Kata:
Stats:
Created | Feb 8, 2017 |
Published | Feb 8, 2017 |
Warriors Trained | 1828 |
Total Skips | 28 |
Total Code Submissions | 2879 |
Total Times Completed | 688 |
JavaScript Completions | 233 |
C# Completions | 93 |
Python Completions | 329 |
Ruby Completions | 50 |
Crystal Completions | 12 |
Haskell Completions | 45 |
Total Stars | 24 |
% of votes with a positive feedback rating | 93% of 212 |
Total "Very Satisfied" Votes | 186 |
Total "Somewhat Satisfied" Votes | 21 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 6 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |