fork download
  1. package practice
  2.  
  3. object MagicSquare extends App {
  4.  
  5. val res = for (j <- 1 to 5; i <- 0 to 20 by 5) yield {
  6. make(j % 5 + 1, (j + 1) % 5 + 1, (j + 2) % 5 + 1, (j + 3) % 5 + 1, (j + 4) % 5 + 1,
  7. i % 25, (i + 5) % 25, (i + 10) % 25, (i + 15) % 25, (i + 20) % 25)
  8. }
  9.  
  10. for (xs <- res) {
  11. xs.foreach(ys => println(ys.map(y => f"$y%3d").mkString))
  12. println
  13. }
  14.  
  15. def make(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int, i: Int, j: Int) = {
  16. val pat1 = List(List(a, b, c, d, e), List(c, d, e, a, b), List(e, a, b, c, d), List(b, c, d, e, a), List(d, e, a, b, c))
  17. val pat2 = List(List(f, g, h, i, j), List(i, j, f, g, h), List(g, h, i, j, f), List(j, f, g, h, i), List(h, i, j, f, g))
  18. (pat1 zip pat2).map(xs => xs._1 zip xs._2).map(xs => xs.map(xx => xx._1 + xx._2))
  19. }
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/opt/scala/bin/scalac: line 50: /dev/null: Permission denied
spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty