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

Post History

60%
+1 −0
Challenges Prove commutativity on this monoid presentation.

Python 3.8, 64 bytes lambda s,_:((n:=s.count("1"))*"1"+"0"+n*"1010")*(len(s)-n)+n*"1" Try it online! Let Tn consist of (2n+1) 0s and 2n 1s alternating. Tn can consume a 1 on either side and ...

posted 7d ago by m90‭

Answer
#1: Initial revision by user avatar m90‭ · 2025-04-12T08:32:23Z (7 days ago)
# [Python 3.8], 64 bytes

<!-- language-all: lang-python -->

    lambda s,_:((n:=s.count("1"))*"1"+"0"+n*"1010")*(len(s)-n)+n*"1"

[Try it online!][TIO-m9dy2job]

[Python 3.8]: https://docs.python.org/3.8/
[TIO-m9dy2job]: https://tio.run/##bZLBTsMwDIbPzVNYOSVrViUgJFTRC@LMC4wJZTQVRcWtkkzqNO3Zi9NuMBCX9P/t@KtddzjE9x5v7wc/NdXL1NnPXW0hqNdSCCyrULz1e4yCGy7lis6ca54jKW00lyvRORRBrlHOQT5ZqKDFYR@FZLsrbUNwPkJwUVgJDxUcCaSo4gQWawi9j65Oqaq6mJ1kjXeBII2wCsgOvqVeUlAyVrsG0IUoRgUHBShLlnkX9x5hhBUg5HBIT9b0HgI1AptE2aZrxNxsWeas71rnDVnNss7GRV8PzbJU/pbKA1VmbUOGeqRcsj@IvAKTAmfK@mx9YYfBYS04GEi4zHXBlb9S8xR8Q3kFHDTQzfnckl9wUv5h6YX1D@O7fobNjEuPiZJG57z46FsUnvzySZM6b8gX0VsM6b3iqMcbXcJzj06BHu8er/TTok/zxtJKJmO01oz@C22@AA "Python 3.8 (pre-release) – Try It Online"

Let T<sub><i>n</i></sub> consist of (2<i>n</i>+1) `0`s and 2<i>n</i> `1`s alternating. T<sub><i>n</i></sub> can consume a 1 on either side and become T<sub><i>n</i>-1</sub>:
```` lang-none
[1 0101]01010
    01010[1010 1]
````
Repeating this, T<sub><i>n</i></sub> can consume <i>n</i> 1s in total from both sides and become T<sub>0</sub> = `0`.

The output alternates <i>m</i>+1 runs of <i>n</i> 1s with <i>m</i> copies of T<sub><i>n</i></sub>.  
This can be reduced to any string of <i>m</i> 0s and <i>n</i> 1s.