Ahmed
Ahmed
CC#
Created by Ahmed on 11/12/2023 in #help
✅ Morse Code Decoder
using System.Collections.Generic;


class MorseCodeDecoder
{
public static string Decode(string morseCode)
{

string[] morse_code_holder = morseCode.Split(' ');

Dictionary<char, string> _morseCode = new Dictionary<char, string>()
{
{'A', ".-"},
{'B', "-..."},
{'C', "-.-."},
{'D', "-.."},
{'E', "."},
{'F', "..-."},
{'G', "--."},
{'H', "...."},
{'I', ".."},
{'J', ".---"},
{'K', "-.-"},
{'L', ".-.."},
{'M', "--"},
{'N', "-."},
{'O', "---"},
{'P', ".--."},
{'Q', "--.-"},
{'R', ".-."},
{'S', "..."},
{'T', "-"},
{'U', "..-"},
{'V', "...-"},
{'W', ".--"},
{'X', "-..-"},
{'Y', "-.--"},
{'Z', "--.."},
{'0', "-----"},
{'1', ".----"},
{'2', "..---"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{'9', "----."},
{'.', ".-.-.-"},
{',', "--..--"},
{'?', "..--.."},
{'\'', ".----."},
{'!', "-.-.--"},
{'/', "-..-."},
{'(', "-.--."},
{')', "-.--.-"},
{'&', ".-..."},
{':', "---..."},
{';', "-.-.-."},
{'=', "-...-"},
{'+', ".-.-."},
{'-', "-....-"},
{'_', "..--.-"},
{'\"', ".-..-."},
{'$', "...-..-"},
{'@', ".--.-."},
{' ', "/"}
};

foreach ( var kvp in _morseCode )
{
char kvpk = kvp.Key;
int i = 0;

if (morse_code_holder[i].Contains(kvpk))
{
morse_code_holder[i] = kvp.Value;
}
}

string sumOfMorseCode = string.Join(" ", morse_code_holder);

Console.WriteLine(sumOfMorseCode);

throw new System.NotImplementedException("Please provide some code.");
}
}
using System.Collections.Generic;


class MorseCodeDecoder
{
public static string Decode(string morseCode)
{

string[] morse_code_holder = morseCode.Split(' ');

Dictionary<char, string> _morseCode = new Dictionary<char, string>()
{
{'A', ".-"},
{'B', "-..."},
{'C', "-.-."},
{'D', "-.."},
{'E', "."},
{'F', "..-."},
{'G', "--."},
{'H', "...."},
{'I', ".."},
{'J', ".---"},
{'K', "-.-"},
{'L', ".-.."},
{'M', "--"},
{'N', "-."},
{'O', "---"},
{'P', ".--."},
{'Q', "--.-"},
{'R', ".-."},
{'S', "..."},
{'T', "-"},
{'U', "..-"},
{'V', "...-"},
{'W', ".--"},
{'X', "-..-"},
{'Y', "-.--"},
{'Z', "--.."},
{'0', "-----"},
{'1', ".----"},
{'2', "..---"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{'9', "----."},
{'.', ".-.-.-"},
{',', "--..--"},
{'?', "..--.."},
{'\'', ".----."},
{'!', "-.-.--"},
{'/', "-..-."},
{'(', "-.--."},
{')', "-.--.-"},
{'&', ".-..."},
{':', "---..."},
{';', "-.-.-."},
{'=', "-...-"},
{'+', ".-.-."},
{'-', "-....-"},
{'_', "..--.-"},
{'\"', ".-..-."},
{'$', "...-..-"},
{'@', ".--.-."},
{' ', "/"}
};

foreach ( var kvp in _morseCode )
{
char kvpk = kvp.Key;
int i = 0;

if (morse_code_holder[i].Contains(kvpk))
{
morse_code_holder[i] = kvp.Value;
}
}

string sumOfMorseCode = string.Join(" ", morse_code_holder);

Console.WriteLine(sumOfMorseCode);

throw new System.NotImplementedException("Please provide some code.");
}
}
47 replies
CC#
Created by Ahmed on 11/10/2023 in #help
❔ ✅ A word with the length of > 5 will be reversed, e.g. hello -> olleh
Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. Examples:
spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw"
spinWords( "This is a test") => returns "This is a test"
spinWords( "This is another test" )=> returns "This is rehtona test"
spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw"
spinWords( "This is a test") => returns "This is a test"
spinWords( "This is another test" )=> returns "This is rehtona test"
my code:
using System.Collections.Generic;
using System.Linq;
using System;
using System.Text;



public class Kata
{
public static string SpinWords(string sentence)
{
string[] words = sentence.Split(" ");
foreach (string word in words){
if (word.Length() >= 5){
StringBuilder sb = new StringBuilder(word);
words[word] = sb.Reverse();
}
string connected_string = words.join(' ');
return connected_string;

}

string sen = SpinWords("this is a trial sentence.");
Console.WriteLine(sen);

}
}
using System.Collections.Generic;
using System.Linq;
using System;
using System.Text;



public class Kata
{
public static string SpinWords(string sentence)
{
string[] words = sentence.Split(" ");
foreach (string word in words){
if (word.Length() >= 5){
StringBuilder sb = new StringBuilder(word);
words[word] = sb.Reverse();
}
string connected_string = words.join(' ');
return connected_string;

}

string sen = SpinWords("this is a trial sentence.");
Console.WriteLine(sen);

}
}
error :
src/Solution.cs(14,16): error CS1955: Non-invocable member 'string.Length' cannot be used like a method.
src/Solution.cs(16,13): error CS0029: Cannot implicitly convert type 'string' to 'int'
src/Solution.cs(16,24): error CS1061: 'StringBuilder' does not contain a definition for 'Reverse' and no accessible extension method 'Reverse' accepting a first argument of type 'StringBuilder' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(18,39): error CS1061: 'string[]' does not contain a definition for 'join' and no accessible extension method 'join' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(10,24): error CS0161: 'Kata.SpinWords(string)': not all code paths return a value
src/Solution.cs(14,16): error CS1955: Non-invocable member 'string.Length' cannot be used like a method.
src/Solution.cs(16,13): error CS0029: Cannot implicitly convert type 'string' to 'int'
src/Solution.cs(16,24): error CS1061: 'StringBuilder' does not contain a definition for 'Reverse' and no accessible extension method 'Reverse' accepting a first argument of type 'StringBuilder' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(18,39): error CS1061: 'string[]' does not contain a definition for 'join' and no accessible extension method 'join' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)
src/Solution.cs(10,24): error CS0161: 'Kata.SpinWords(string)': not all code paths return a value
108 replies
CC#
Created by Ahmed on 11/9/2023 in #help
❔ ✅ Mind explaining a code to me?
public static int? Closest(int[] arr)
{
var min = arr.Distinct().Where(x => Math.Abs(x) == arr.Min(Math.Abs));
return min.Count() == 1 ? min.First() : (int?) null;
}
public static int? Closest(int[] arr)
{
var min = arr.Distinct().Where(x => Math.Abs(x) == arr.Min(Math.Abs));
return min.Count() == 1 ? min.First() : (int?) null;
}
132 replies
CC#
Created by Ahmed on 11/9/2023 in #help
❔ ✅ denary -> binary
using System.Data;

static void Main(string[] args)
{
string ans = AddBinary(1, 2);
Console.WriteLine(ans);
Console.ReadLine();
}
static string AddBinary(int a, int b)
{
string string_combiner = "";
int number = a + b;

for (int i = 1; i <= 32; i++)
{

int powered_number = (int)Math.Pow(number, i);
if (number % powered_number == 0)
{
string_combiner.Insert(0, "1");
}


else
{
string_combiner.Insert(0, "0");
}

}

return string_combiner;

}
using System.Data;

static void Main(string[] args)
{
string ans = AddBinary(1, 2);
Console.WriteLine(ans);
Console.ReadLine();
}
static string AddBinary(int a, int b)
{
string string_combiner = "";
int number = a + b;

for (int i = 1; i <= 32; i++)
{

int powered_number = (int)Math.Pow(number, i);
if (number % powered_number == 0)
{
string_combiner.Insert(0, "1");
}


else
{
string_combiner.Insert(0, "0");
}

}

return string_combiner;

}
60 replies
CC#
Created by Ahmed on 10/22/2023 in #help
❔ ✅ Return
How do I return a dictionary
106 replies
CC#
Created by Ahmed on 10/22/2023 in #help
❔ ✅ c#
No description
104 replies
CC#
Created by Ahmed on 10/22/2023 in #help
❔ ✅ It's not writing to the console that car1 is driving
Car car1 = new Car("ford", "mustang", 2022, "red");
Car car2 = new Car("idk", "idk", 2001, "idk");
Console.WriteLine();
Console.ReadLine();

car1.Drive();


class Car
{
string make;
string model;
int year;
string colour;
public static int numberOfCars;


public Car(string make, string model, int year, string colour)
{
this.make = make;
this.model = model;
this.year = year;
this.colour = colour;
numberOfCars++;
}

public void Test()
{
Console.WriteLine(numberOfCars);
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
Console.ReadLine();
}

}
Car car1 = new Car("ford", "mustang", 2022, "red");
Car car2 = new Car("idk", "idk", 2001, "idk");
Console.WriteLine();
Console.ReadLine();

car1.Drive();


class Car
{
string make;
string model;
int year;
string colour;
public static int numberOfCars;


public Car(string make, string model, int year, string colour)
{
this.make = make;
this.model = model;
this.year = year;
this.colour = colour;
numberOfCars++;
}

public void Test()
{
Console.WriteLine(numberOfCars);
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
Console.ReadLine();
}

}
8 replies
CC#
Created by Ahmed on 10/20/2023 in #help
❔ ✅ Static
What does static do in classes? I need demos
31 replies
CC#
Created by Ahmed on 10/20/2023 in #help
❔ ✅ Incorrect use of Round()?
Been trying for a bit now
11 replies
CC#
Created by Ahmed on 10/20/2023 in #help
❔ ✅ Fruit Machine Game
No description
15 replies