Skip to content

Conversation

Arpita23r
Copy link
Contributor

  • 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.

@siriak siriak requested a review from Copilot October 11, 2025 09:26
Copy link

@Copilot Copilot AI left a 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) {
Copy link

Copilot AI Oct 11, 2025

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.

Suggested change
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check

Copy link
Member

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

@Arpita23r
Copy link
Contributor Author

Issues resolved

@siriak siriak requested a review from Copilot October 11, 2025 10:46
Copy link

@Copilot Copilot AI left a 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.

Comment on lines +16 to +23
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
Copy link

Copilot AI Oct 11, 2025

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.

@Arpita23r Arpita23r closed this Oct 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants