Implement dominoes push simulation#5
Merged
Subhosjx merged 1 commit intoSubhosjx:mainfrom Oct 27, 2025
Merged
Conversation
Subhosjx
approved these changes
Oct 27, 2025
🎉 Congrats on getting your PR merged in, @SjxSubham! 🙌🏼Thanks for your contribution every effort helps improve the project. Looking forward to seeing more from you! 🥳✨ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intuition
Imagine each domino can be affected by forces coming from the left and right:
• 'R' pushes a positive (rightward) force to its right.
• 'L' pushes a negative (leftward) force to its left.
• '.' just receives forces from both sides and falls accordingly.
Over time, forces from 'R' and 'L' spread outward but weaken (because distance reduces influence).
So we can think of this as:
Each domino experiences a net force = (right force) + (left force).
• If net force > 0 → falls to the right ('R')
• If net force < 0 → falls to the left ('L')
• If net force = 0 → remains upright ('.')
Approach
• It will store the net force experienced by each domino.
• Keep a running force variable.
• If you meet 'R', set force = n (max push).
• If you meet 'L', reset force = 0.
• For each '.', force = max(force - 1, 0) (force weakens by 1).
• Add this force to forces[i].
• Same logic but reversed.
• If you meet 'L', set force = -n (negative force).
• If you meet 'R', reset force = 0.
• For '.', force = min(force + 1, 0) (force weakens by 1).
• Add this force to forces[i] (now we combine both left and right effects).
For each i:
• if forces[i] > 0 → 'R'
• if forces[i] < 0 → 'L'
• if forces[i] == 0 → '.'