diff --git a/.gitignore b/.gitignore index 86b5e58..96f370d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .DS_Store -.idea/shelf +/.idea/ /android.tests.dependencies /confluence/target /dependencies/repo @@ -29,4 +29,4 @@ node_modules/ .rpt2_cache/ libraries/tools/kotlin-test-nodejs-runner/lib/ .idea/jarRepositories.xml -.idea/misc.xml \ No newline at end of file +.idea/misc.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 1bec35e..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123..0000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 15a15b2..0000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4b49563..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/main/kotlin/dynamicProgramming/Factorial.kt b/src/main/kotlin/dynamicProgramming/Factorial.kt index 0eec314..38d9734 100644 --- a/src/main/kotlin/dynamicProgramming/Factorial.kt +++ b/src/main/kotlin/dynamicProgramming/Factorial.kt @@ -1,5 +1,11 @@ package dynamicProgramming +/** + * This is a tail-recursive implementation of factorial calculation. + * @param n - the number to calculate factorial for + * @param accumulator - accumulates the factorial value (default is 1) + * @return factorial of the input number + */ tailrec fun factorial(n: Int, accumulator: Int = 1): Int { if (n == 0) { return accumulator diff --git a/src/main/kotlin/dynamic_programming/PalindromePartitioning.kt b/src/main/kotlin/dynamicProgramming/PalindromePartitioning.kt similarity index 100% rename from src/main/kotlin/dynamic_programming/PalindromePartitioning.kt rename to src/main/kotlin/dynamicProgramming/PalindromePartitioning.kt diff --git a/src/main/kotlin/dynamicProgramming/isPrime.kt b/src/main/kotlin/dynamicProgramming/isPrime.kt index 7959c15..36a2500 100644 --- a/src/main/kotlin/dynamicProgramming/isPrime.kt +++ b/src/main/kotlin/dynamicProgramming/isPrime.kt @@ -1,3 +1,8 @@ package dynamicProgramming -fun Int.isPrime() = this > 1 && (2..(this / 2)).all { this % it != 0 } \ No newline at end of file +/** + * Extension function that checks if an integer is a prime number. + * A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. + * @return true if the number is prime, false otherwise + */ +fun Int.isPrime() = this > 1 && (2..(this / 2)).all { this % it != 0 } diff --git a/src/main/kotlin/other/Palindrome.kt b/src/main/kotlin/other/Palindrome.kt deleted file mode 100644 index 4a2dc13..0000000 --- a/src/main/kotlin/other/Palindrome.kt +++ /dev/null @@ -1,36 +0,0 @@ -package other - -import java.text.Normalizer -import java.util.regex.Pattern - -/** - * A palindrome is a word, number, phrase, or other sequence - * of characters which reads the same backward as forward, - * such as madam, racecar. There are also numeric palindromes, - * particularly date/time stamps using short digits 11/11/11 11:11 - * and long digits 02/02/2020 - * - * This function - * @param text The text to be checked if it is a palindrome - * @return return true if the text is a Palindrome - */ -fun isPalindrome(text: String): Boolean { - - val normalizedText = text.normalize() - for(i in normalizedText.indices) - if(normalizedText[i] != normalizedText[normalizedText.length - (i + 1)]) - return false - return true; -} - - -fun String.normalize(): String { - val nfdNormalizedString = Normalizer.normalize(this, Normalizer.Form.NFD) - return Pattern - .compile("\\p{InCombiningDiacriticalMarks}+") - .matcher(nfdNormalizedString) - .replaceAll("") - .toLowerCase() - .replace(" ", "") - -} \ No newline at end of file