Created
February 18, 2019 07:11
-
-
Save katzkb/0bdf794642ee4da80aa5f099bb15f6e6 to your computer and use it in GitHub Desktop.
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
import scala.math.abs | |
// 気温リスト1~12月 | |
val temperatureSeq:Seq[Int] = | |
Seq(4, 5, 11, 17, 19, 22, 28, 28, 22, 19, 14, 7) | |
def diffTemperature1(tSeq: Seq[Int]) = { | |
@scala.annotation.tailrec | |
def f(diffSeq:Seq[Int], tSeq: Seq[Int]): Seq[Int] = { | |
tSeq match { | |
case head +: second +: tail => | |
f(diffSeq :+ abs(head - second), second +: tail) | |
case _ => | |
diffSeq | |
} | |
} | |
f(Seq.empty, temperatureSeq) | |
} | |
diffTemperature1(temperatureSeq) | |
// -> res0: Seq[Int] = List(1, 6, 6, 2, 3, 6, 0, 6, 3, 5, 7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment