Created
February 9, 2012 08:27
-
-
Save cb372/1778448 to your computer and use it in GitHub Desktop.
Time until the musical kills Andy :(
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
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