Skip to content

Instantly share code, notes, and snippets.

@cb372
Created February 9, 2012 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cb372/1778448 to your computer and use it in GitHub Desktop.
Save cb372/1778448 to your computer and use it in GitHub Desktop.
Time until the musical kills Andy :(
scala> def step(an: Int, xn: Double): Stream[(Int, Double)] = Stream.cons((an, xn), step(an + 1, xn - (0.2 * 365)))
step: (an: Int, xn: Double)Stream[(Int, Double)]
scala> val ageNow = 28
ageNow: Int = 28
scala> val lifeExpectancy = 80
lifeExpectancy: Int = 80
scala> val marchOfTime = step(ageNow * 365, lifeExpectancy * 365)
marchOfTime: Stream[(Int, Double)] = Stream((10220,29200.0), ?)
scala> val tillDeath = marchOfTime takeWhile {x => x._1 < x._2.toInt}
tillDeath: scala.collection.immutable.Stream[(Int, Double)] = Stream((10220,29200.0), ?)
scala> tillDeath.length
res0: Int = 257
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment