-
-
Notifications
You must be signed in to change notification settings - Fork 331
feat: added string rotation #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Arpita23r
commented
Oct 9, 2025
- Implemented String Rotation Check algorithm in R to determine if one string is a rotation of another.
- Uses the concatenation method, checking if the second string is a substring of the first string repeated twice.
- Efficient linear-time solution for strings of any length.
- Handles case-insensitive input for flexible comparison.
- Interactive input allows users to test different string pairs easily.
- Provides clear output indicating whether the second string is a rotation of the first.
- Stored file under string_manipulation/string.rotation.check.R following project structure conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a string rotation check algorithm in R that determines if one string is a rotation of another using the concatenation method. The implementation provides an efficient solution with interactive user input and case-insensitive comparison.
- Added string rotation detection function using concatenation approach
- Implemented interactive input with case-insensitive handling
- Created complete script with user-friendly output formatting
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
# String Rotation Check in R | ||
# Checks if one string is a rotation of another string. | ||
|
||
is_rotation <- function(s1, s2) { |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't handle empty strings correctly. When both strings are empty, nchar()
returns 0 for both, they pass the length check, and grepl('', '', fixed = TRUE)
returns TRUE, which is incorrect since empty strings should not be considered rotations of each other.
is_rotation <- function(s1, s2) { | |
is_rotation <- function(s1, s2) { | |
# Explicitly handle both strings empty case | |
if (nchar(s1) == 0 && nchar(s2) == 0) { | |
return(FALSE) | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the result? You haven't changed anything and haven't responded to the comment
Issues resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
s1 <- tolower(readline("Enter first string: ")) | ||
s2 <- tolower(readline("Enter second string: ")) | ||
|
||
if (is_rotation(s1, s2)) { | ||
cat("Yes, '", s2, "' is a rotation of '", s1, "'.\n", sep = "") | ||
} else { | ||
cat("No, '", s2, "' is not a rotation of '", s1, "'.\n", sep = "") | ||
} No newline at end of file |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file name should use a lowercase .r
extension instead of .R
. According to the project guidelines, all code file names must use lowercase .r
extension.
Copilot generated this review using guidance from repository custom instructions.