Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Determine if a string is Sturmian

+2
−0

A finite binary string is "Sturmian" if for every two contiguous substrings $x$ and $y$ of the same length, the number of $0$s in $x$ and $y$ differs by at most 1.

Your program should take a finite binary string and output one of two distinct values. The first if the input is Sturmian the other if the input is not Sturmian.

This is code-golf so the goal is to minimize the size of your source code as measured in bytes.

Bonus

This problem is solvable in worst-case linear time complexity. I encourage people to submit linear time solutions. Although it is not necessary, I give my official blessing for linear time solutions to be scored separately from slower solutions. Just as different programming languages are not competing against each other

In fact I consider this in some sense the real challenge. There seems to me more dimension for golfing strategy in the linear time case.

In order for this to work on the leader board I suggest that submissions append "linear" to the language name. e.g. Elm linear, 240 bytes

Test cases

Please do not try to guess the property based on the test-cases. Please read the description, and if something is unclear ask about it.

I have included the falsifying substrings in the Non-Sturmian cases. Your solution is not required to, or even permitted to, output these extra strings.

0110 -> Sturmian
0011 -> Non-Sturmian (00, 11)
100001000100001 -> Sturmian
1000001000010001 -> Non-Sturmian (00000, 10001)
10010100100101001001010010 -> Sturmian
10010100100100101001010010 -> Non-Sturmian (00100100, 10100101)
History

1 comment thread

Separating the 2 challenges in the leaderboard (2 comments)

Sign up to answer this question »