Syncopated Rhythm

Published by Matt in

Syncopation means an emphasis on a weak beat of a bar of music; most commonly, beats 2 and 4 (and all other even-numbered beats if applicable).

You will be given a string representing beats, where hashtags # represent emphasized beats. Create a function that returns true if the line of music contains any syncopation, and false otherwise.

Examples

has_syncopation(".#.#.#.#") ➞ true
# There are Hash signs in the second, fourth, sixth and
# eighth positions of the string.

has_syncopation("#.#...#.") ➞ false
# There are no Hash signs in the second, fourth, sixth or
# eighth positions of the string.

has_syncopation("#.#.###.") ➞ true
# There is a Hash sign in the sixth position of the string.

Notes

All other unemphasized beats will be represented as a dot.

Watch a quick demo on how Edabit works.