From 74eefb9eb25f294050ce394825e9e76712201572 Mon Sep 17 00:00:00 2001 From: Abdelilah Khossan <49311230+akhossanX@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:38:03 +0100 Subject: [PATCH] docs(rust piscine): Add is_anagram optional exercise subject (#2223) --- subjects/is_anagram/README.md | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 subjects/is_anagram/README.md diff --git a/subjects/is_anagram/README.md b/subjects/is_anagram/README.md new file mode 100644 index 00000000..ba6a744d --- /dev/null +++ b/subjects/is_anagram/README.md @@ -0,0 +1,43 @@ +## is_anagram + +### Instructions + +Write a function called `is_anagram` that checks if one string is an anagram of another string. An anagram is a word or phrase formed by rearranging the letters of another, such as "listen" and "silent." + +```rust +pub fn is_anagram(s1: &str, s2: &str) -> bool { + // Your code goes here +} +``` + +- `s1: &str`: The first input string. +- `s2: &str`: The second input string. + +The function should return `true` if `s1` is an anagram of `s2`, and `false` otherwise. +Your task is to implement the `is_anagram` function to determine whether the two input strings are anagrams of each other. + +### Usage + +Here is a possible runner to test your function: + +```rust +use is_anagram::is_anagram; + +fn main() { + let s1 = "listen"; + let s2 = "silent"; + + if is_anagram(s1, s2) { + println!("{} and {} are anagrams!", s1, s2); + } else { + println!("{} and {} are not anagrams.", s1, s2); + } +} +``` + +And its output: + +```console +$ cargo run +listen and silent are anagrams! +```