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 array seq

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

Stats:

CreatedFeb 8, 2017
PublishedFeb 8, 2017
Warriors Trained1828
Total Skips28
Total Code Submissions2879
Total Times Completed688
JavaScript Completions233
C# Completions93
Python Completions329
Ruby Completions50
Crystal Completions12
Haskell Completions45
Total Stars24
% of votes with a positive feedback rating93% of 212
Total "Very Satisfied" Votes186
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes5
Total Rank Assessments6
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • GiacomoSorbi Avatar
  • smile67 Avatar
  • JohanWiltink Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad