import scala.collection.mutable.LinkedHashMap

val range = 1 to 10000
val maxIter = 500;

def lychrelSeq( seed:BigInt ) : Stream[BigInt] = { 
  def reverse( v:BigInt ) = BigInt(v.toString.reverse)
  def isPalindromic( v:BigInt ) = { val s = (v + reverse(v)).toString; s == s.reverse }

  def loop( v:BigInt ):Stream[BigInt] = v #:: loop( v + reverse(v) )
  val seq = loop(seed)

  seq.take( seq.take(maxIter).indexWhere( isPalindromic(_) ) match { 
    case -1 => maxIter
    case n => n + 1
  })
}