2015年8月17日月曜日

開発環境

Learning Scala: Practical Functional Programming for the JVM (Jason Swartz (著)、O'Reilly Media)のPart Ⅰ. (Core Scala)、Chapter 4.(Functions)、Exercises 6.(No. 1471)を解いてみる。

その他参考書籍

Exercises 6.(No. 1471)

コード(Emacs)

def difference(x:(Double, Double), y:(Double, Double)):(Double, Double) =
  (y._1 - x._1, y._2 - x._2)

for (x1 <- 0 to 2) {
  for (y1 <- 0 to 2) {
    for (x2 <- 0 until 2) {
      for (y2 <- 0 until 2) {
        println(s"($x1, $y1), ($x2, $y2): ${difference((x1, y1), (x2, y2))}")
      }
    }
  }
}

入出力結果(Terminal, REPL(Read, Eval, Print, Loop))

$ scala-2.11 sample6.scala
(0, 0), (0, 0): (0.0,0.0)
(0, 0), (0, 1): (0.0,1.0)
(0, 0), (1, 0): (1.0,0.0)
(0, 0), (1, 1): (1.0,1.0)
(0, 1), (0, 0): (0.0,-1.0)
(0, 1), (0, 1): (0.0,0.0)
(0, 1), (1, 0): (1.0,-1.0)
(0, 1), (1, 1): (1.0,0.0)
(0, 2), (0, 0): (0.0,-2.0)
(0, 2), (0, 1): (0.0,-1.0)
(0, 2), (1, 0): (1.0,-2.0)
(0, 2), (1, 1): (1.0,-1.0)
(1, 0), (0, 0): (-1.0,0.0)
(1, 0), (0, 1): (-1.0,1.0)
(1, 0), (1, 0): (0.0,0.0)
(1, 0), (1, 1): (0.0,1.0)
(1, 1), (0, 0): (-1.0,-1.0)
(1, 1), (0, 1): (-1.0,0.0)
(1, 1), (1, 0): (0.0,-1.0)
(1, 1), (1, 1): (0.0,0.0)
(1, 2), (0, 0): (-1.0,-2.0)
(1, 2), (0, 1): (-1.0,-1.0)
(1, 2), (1, 0): (0.0,-2.0)
(1, 2), (1, 1): (0.0,-1.0)
(2, 0), (0, 0): (-2.0,0.0)
(2, 0), (0, 1): (-2.0,1.0)
(2, 0), (1, 0): (-1.0,0.0)
(2, 0), (1, 1): (-1.0,1.0)
(2, 1), (0, 0): (-2.0,-1.0)
(2, 1), (0, 1): (-2.0,0.0)
(2, 1), (1, 0): (-1.0,-1.0)
(2, 1), (1, 1): (-1.0,0.0)
(2, 2), (0, 0): (-2.0,-2.0)
(2, 2), (0, 1): (-2.0,-1.0)
(2, 2), (1, 0): (-1.0,-2.0)
(2, 2), (1, 1): (-1.0,-1.0)
$

0 コメント:

コメントを投稿

Comments on Google+: