Created
April 3, 2012 19:37
-
-
Save ryanoneill/2295008 to your computer and use it in GitHub Desktop.
Ninety-Nine Scala Problems: Problem 06 - Find out whether a list is a palindrome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://aperiodic.net/phil/scala/s-99/ | |
// P06 (*) Find out whether a list is a palindrome. | |
// Example: | |
// scala> isPalindrome(List(1, 2, 3, 2, 1)) | |
// res0: Boolean = true | |
object Problem06 { | |
def main(args: Array[String]) { | |
val values = List(1, 2, 3, 2, 1) | |
println(isPalindrome(values)) | |
} | |
// considering the reverse function was written | |
// in Problem 05, it's fair to use the builtin one here. | |
def isPalindrome[T](values: List[T]) : Boolean = | |
values == values.reverse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment