From 2e15a21206540763585dc82d55181da06c9e0ce6 Mon Sep 17 00:00:00 2001 From: Divlo Date: Fri, 10 Sep 2021 22:37:50 +0200 Subject: [PATCH] feat(solutions): add `is-prime-number/cs/function ` --- .../solutions/python/function/solution.py | 6 +-- .../first-non-repeating-character/README.md | 2 +- .../solutions/cs/function/README.md | 3 ++ .../solutions/cs/function/Solution.cs | 49 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 challenges/is-prime-number/solutions/cs/function/README.md create mode 100644 challenges/is-prime-number/solutions/cs/function/Solution.cs diff --git a/challenges/defibrillators/solutions/python/function/solution.py b/challenges/defibrillators/solutions/python/function/solution.py index 78a4d96..189cc58 100644 --- a/challenges/defibrillators/solutions/python/function/solution.py +++ b/challenges/defibrillators/solutions/python/function/solution.py @@ -13,8 +13,8 @@ def convert_string_to_float(string: str) -> float: class Position: def __init__(self, longitude: float, latitude: float) -> None: - self.longitude = self.convert_degrees_to_radien(longitude) - self.latitude = self.convert_degrees_to_radien(latitude) + self.longitude = self.convert_degrees_to_radian(longitude) + self.latitude = self.convert_degrees_to_radian(latitude) @staticmethod def calculation_distance(pointA: 'Position', pointB: 'Position') -> float: @@ -23,7 +23,7 @@ class Position: y = pointB.latitude - pointA.latitude return math.sqrt(math.pow(x, 2) + math.pow(y, 2)) * 6371 - def convert_degrees_to_radien(self, degrees: float) -> float: + def convert_degrees_to_radian(self, degrees: float) -> float: return degrees * (math.pi / 180) diff --git a/challenges/first-non-repeating-character/README.md b/challenges/first-non-repeating-character/README.md index f5969a3..46fad70 100644 --- a/challenges/first-non-repeating-character/README.md +++ b/challenges/first-non-repeating-character/README.md @@ -6,7 +6,7 @@ Created by [@Divlo](https://github.com/Divlo) on 15 November 2020. Write a function that takes a string input, and returns the first character that is not repeated anywhere in the string. -For example, if given the input `'stress'`, the function should return `'t'`, since the letter _t_ only occurs once in the string, and occurs first in the string. +For example, if given the input `'stress'`, the function should return `'t'`, since the letter `'t'` only occurs once in the string, and occurs first in the string. If a string contains all repeating characters, it should return an empty string (`""`). diff --git a/challenges/is-prime-number/solutions/cs/function/README.md b/challenges/is-prime-number/solutions/cs/function/README.md new file mode 100644 index 0000000..2e099fc --- /dev/null +++ b/challenges/is-prime-number/solutions/cs/function/README.md @@ -0,0 +1,3 @@ +# is-prime-number/cs/function + +Created by [@Divlo](https://github.com/Divlo) on 10 September 2021. diff --git a/challenges/is-prime-number/solutions/cs/function/Solution.cs b/challenges/is-prime-number/solutions/cs/function/Solution.cs new file mode 100644 index 0000000..f86d576 --- /dev/null +++ b/challenges/is-prime-number/solutions/cs/function/Solution.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; + +namespace Solution +{ + class Program + { + static void Main() + { + int number = int.Parse(Console.ReadLine()); + if (IsPrime(number)) + { + Console.WriteLine("true"); + } + else + { + Console.WriteLine("false"); + } + } + + /// + /// Checks if a number is prime. + /// + /// The number to check. + /// True if the number is prime, false otherwise. + static public bool IsPrime(int number) + { + return GetDividers(number).Length == 2; + } + + /// + /// Gets the dividers of a number. + /// + /// The number to get the dividers of. + /// An array of the dividers of the number. + static public int[] GetDividers(int number) + { + List dividers = new List(); + for (int index = 1; index <= number; index++) + { + if (number % index == 0) + { + dividers.Add(index); + } + } + return dividers.ToArray(); + } + } +}