Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
def isPalindrome(s: String): Boolean = (s.size >= 2) && s == s.reverse
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def isPalindromeSentence(s: String): Boolean =
|
||||
(s.size >= 2) && {
|
||||
val p = s.replaceAll("[^\\p{L}]", "").toLowerCase
|
||||
p == p.reverse
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import scala.annotation.tailrec
|
||||
|
||||
def isPalindromeRec(s: String) = {
|
||||
@tailrec
|
||||
def inner(s: String): Boolean =
|
||||
(s.length <= 1) || (s.head == s.last) && inner(s.tail.init)
|
||||
|
||||
(s.size >= 2) && inner(s)
|
||||
}
|
||||
23
Task/Palindrome-detection/Scala/palindrome-detection-4.scala
Normal file
23
Task/Palindrome-detection/Scala/palindrome-detection-4.scala
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Testing
|
||||
assert(!isPalindrome(""))
|
||||
assert(!isPalindrome("z"))
|
||||
assert(isPalindrome("amanaplanacanalpanama"))
|
||||
assert(!isPalindrome("Test 1,2,3"))
|
||||
assert(isPalindrome("1 2 1"))
|
||||
assert(!isPalindrome("A man a plan a canal Panama."))
|
||||
|
||||
assert(!isPalindromeSentence(""))
|
||||
assert(!isPalindromeSentence("z"))
|
||||
assert(isPalindromeSentence("amanaplanacanalpanama"))
|
||||
assert(!isPalindromeSentence("Test 1,2,3"))
|
||||
assert(isPalindromeSentence("1 2 1"))
|
||||
assert(isPalindromeSentence("A man a plan a canal Panama."))
|
||||
|
||||
assert(!isPalindromeRec(""))
|
||||
assert(!isPalindromeRec("z"))
|
||||
assert(isPalindromeRec("amanaplanacanalpanama"))
|
||||
assert(!isPalindromeRec("Test 1,2,3"))
|
||||
assert(isPalindromeRec("1 2 1"))
|
||||
assert(!isPalindromeRec("A man a plan a canal Panama."))
|
||||
|
||||
println("Successfully completed without errors.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue