Skip to content

Commit d9c9b88

Browse files
committed
Solución Reto mouredev#1 C#
1 parent 2118149 commit d9c9b88

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Challenge #1
3+
* IS IT AN ANAGRAM?
4+
* Difficulty: MEDIUM
5+
*
6+
* Statement: Write a function that receives two words (String) and returns true or false (Boolean) depending on whether or not they are anagrams.
7+
* An Anagram consists of forming a word by rearranging ALL the letters of another initial word.
8+
* It is NOT necessary to check that both words exist.
9+
* Two exactly the same words are not anagram.
10+
11+
* Reto #1
12+
* ¿ES UN ANAGRAMA?
13+
* Dificultad: MEDIA
14+
*
15+
* Enunciado: Escribe una función que reciba dos palabras (String) y retorne verdadero o falso (Boolean) según sean o no anagramas.
16+
* Un Anagrama consiste en formar una palabra reordenando TODAS las letras de otra palabra inicial.
17+
* NO hace falta comprobar que ambas palabras existan.
18+
* Dos palabras exactamente iguales no son anagrama.
19+
*/
20+
bool IsAnagram(string word1, string word2)
21+
{
22+
if (word1.ToLower().Trim() == word2.ToLower().Trim() || word1.Length != word2.Length) return false;
23+
else return word1.ToLower().Trim().ToCharArray().OrderBy(c => c).SequenceEqual(word2.ToLower().Trim().ToCharArray().OrderBy(c => c));
24+
}
25+
Console.Write("Enter the first word: ");
26+
string word1 = Console.ReadLine()!;
27+
Console.Write("Enter the second word: ");
28+
string word2 = Console.ReadLine()!;
29+
Console.WriteLine($"Is the second word an anagram? {IsAnagram(word1, word2)}");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

0 commit comments

Comments
 (0)