Skip to content

Instantly share code, notes, and snippets.

@ryanoneill
Created April 3, 2012 19:37
Show Gist options
  • Save ryanoneill/2295008 to your computer and use it in GitHub Desktop.
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.
// 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