fork download
  1. import Element.elem
  2.  
  3. import Element.elem
  4.  
  5. abstract class Element {
  6. def contents: Array[String]
  7.  
  8. def width: Int = contents(0).length
  9.  
  10. def height: Int = contents.length
  11.  
  12. def above(that: Element): Element = {
  13. val this1 = this widen that.width
  14. val that1 = that widen this.width
  15. elem(this1.contents ++ that1.contents)
  16. }
  17.  
  18. def beside(that: Element): Element = {
  19. val this1 = this heighten that.height
  20. val that1 = that heighten this.height
  21. elem(
  22. for ((line1, line2) <- this1.contents zip that1.contents)
  23. yield line1 + line2)
  24. }
  25.  
  26. def widen(w: Int): Element =
  27. if (w <= width) this
  28. else {
  29. val left = elem(' ', (w - width) / 2, height)
  30. var right = elem(' ', w - width - left.width, height)
  31. left beside this beside right
  32. }
  33.  
  34. def heighten(h: Int): Element =
  35. if (h <= height) this
  36. else {
  37. val top = elem(' ', width, (h - height) / 2)
  38. var bot = elem(' ', width, h - height - top.height)
  39. top above this above bot
  40. }
  41.  
  42. override def toString = contents mkString "\n"
  43. }
  44.  
  45. object Element {
  46.  
  47. private class ArrayElement(
  48. val contents: Array[String]
  49. ) extends Element
  50.  
  51. private class LineElement(s: String) extends Element {
  52. val contents = Array(s)
  53. override def width = s.length
  54. override def height = 1
  55. }
  56.  
  57. private class UniformElement(
  58. ch: Char,
  59. override val width: Int,
  60. override val height: Int
  61. ) extends Element {
  62. private val line = ch.toString * width
  63. def contents = Array.make(height, line)
  64. }
  65.  
  66. def elem(contents: Array[String]): Element =
  67. new ArrayElement(contents)
  68.  
  69. def elem(chr: Char, width: Int, height: Int): Element =
  70. new UniformElement(chr, width, height)
  71.  
  72. def elem(line: String): Element =
  73. new LineElement(line)
  74. }
  75.  
  76. class ArrayElement(val contents: Array[String]) extends Element {
  77.  
  78. }
  79.  
  80. class LineElement(s: String) extends Element {
  81. val contents = Array(s)
  82. override def width = s.length
  83. override def height = 1
  84. }
  85.  
  86. class UniformElement(
  87. ch: Char,
  88. override val width: Int,
  89. override val height: Int
  90. ) extends Element {
  91. private val line = ch.toString * width
  92. def contents = Array.make(height, line)
  93. }
  94.  
  95. object Main extends App {
  96. val space = elem(" ")
  97. val corner = elem("+")
  98. def spiral(nEdges: Int, direction: Int): Element = {
  99. if (nEdges == 1)
  100. elem("+")
  101. val sp = spiral(nEdges - 1,
  102. (direction + 3) % 4)
  103. def verticalBar = elem('|', 1, sp.height)
  104. def horizontalBar = elem('-', sp.width, 1)
  105. if (direction == 0)
  106. (corner beside horizontalBar) above (sp beside space)
  107. else if (direction == 1)
  108. (sp above space) beside (corner above verticalBar)
  109. else if (direction == 2)
  110. (space beside sp) above (horizontalBar beside corner)
  111. (verticalBar above corner) beside (space above sp)
  112. }
  113. }
  114.  
  115. val nSides = args(0).toInt
  116. println(spiral(nSides, 0))
  117. }
Compilation error #stdin compilation error #stdout 0.33s 322240KB
stdin
4
compilation info
Main.scala:63: error: value make is not a member of object Array
    def contents = Array.make(height, line)
                         ^
Main.scala:92: error: value make is not a member of object Array
  def contents = Array.make(height, line)
                       ^
two errors found
Usage: scalac <options> <source files>
where possible standard options include:
  -Dproperty=value                Pass -Dproperty=value directly to the runtime system.
  -J<flag>                        Pass <flag> directly to the runtime system.
  -P:<plugin>:<opt>               Pass an option to a plugin
  -X                              Print a synopsis of advanced options.
  -bootclasspath <path>           Override location of bootstrap class files.
  -classpath <path>               Specify where to find user class files.
  -d <directory|jar>              destination for generated classfiles.
  -dependencyfile <file>          Set dependency tracking file.
  -deprecation                    Emit warning and location for usages of deprecated APIs.
  -encoding <encoding>            Specify character encoding used by source files.
  -explaintypes                   Explain type errors in more detail.
  -extdirs <path>                 Override location of installed extensions.
  -feature                        Emit warning and location for usages of features that should be imported explicitly.
  -g:<level>                      Set level of generated debugging info. (none,source,line,vars,notailcalls) default:vars
  -help                           Print a synopsis of standard options
  -javabootclasspath <path>       Override java boot classpath.
  -javaextdirs <path>             Override java extdirs classpath.
  -language:<_,feature,-feature>  Enable or disable language features: `_' for all, `-language:help' to list
  -no-specialization              Ignore @specialize annotations.
  -nobootcp                       Do not use the boot classpath for the scala jars.
  -nowarn                         Generate no warnings.
  -optimise                       Generates faster bytecode by applying optimisations to the program
  -print                          Print program with Scala-specific features removed.
  -sourcepath <path>              Specify location(s) of source files.
  -target:<target>                Target platform for object files. All JVM 1.5 targets are deprecated. (jvm-1.5,jvm-1.6,jvm-1.7,jvm-1.8) default:jvm-1.6
  -toolcp <path>                  Add to the runner classpath.
  -unchecked                      Enable additional warnings where generated code depends on assumptions.
  -uniqid                         Uniquely tag all identifiers in debugging output.
  -usejavacp                      Utilize the java.class.path in classpath resolution.
  -usemanifestcp                  Utilize the manifest in classpath resolution.
  -verbose                        Output messages about what the compiler is doing.
  -version                        Print product version and exit.
  @<file>                         A text file containing compiler arguments (options and source files)

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