fork download
  1. def walkTheLabyrinth: Karel = {
  2. case class Solution(karel: Karel) extends Exception
  3.  
  4. def destinationOpen(k: Karel, n: Int) {
  5. if (k.causesPartition) return
  6.  
  7. var karel = k.pickAllBeepers.turn(rng.nextInt(4))
  8.  
  9. if (n <= 1) throw Solution(karel)
  10.  
  11. val a = Array(karel.beepersIn(0), karel.beepersIn(1), karel.beepersIn(2), karel.beepersIn(3))
  12. karel = karel.pickBeeperIn(0).pickBeeperIn(1).pickBeeperIn(2).pickBeeperIn(3)
  13.  
  14. val twos = a.count(_ == 2)
  15. if (twos == 0) {
  16. for (i <- 0 to 3) {
  17. if (a(i) > 0) {
  18. destinationOpen(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  19. }
  20. karel = karel.turnLeft
  21. }
  22. } else if (twos == 2) {
  23. for (i <- 0 to 3) {
  24. if (a(i) == 2) {
  25. destinationOpen(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  26. }
  27. karel = karel.turnLeft
  28. }
  29. } else if (twos == 1) {
  30. for (i <- 0 to 3) {
  31. if (a(i) == 2) {
  32. destinationOpen(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  33. } else if (a(i) > 0) {
  34. destinationFound(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  35. }
  36. karel = karel.turnLeft
  37. }
  38. }
  39. }
  40.  
  41. def destinationFound(k: Karel, n: Int) {
  42. if (k.causesPartition) return
  43.  
  44. var karel = k.pickAllBeepers.turn(rng.nextInt(4))
  45.  
  46. if (n <= 1) throw Solution(karel)
  47.  
  48. val a = Array(karel.beepersIn(0), karel.beepersIn(1), karel.beepersIn(2), karel.beepersIn(3))
  49. karel = karel.pickBeeperIn(0).pickBeeperIn(1).pickBeeperIn(2).pickBeeperIn(3)
  50.  
  51. val twos = a.count(_ == 2)
  52. if (twos == 0) {
  53. for (i <- 0 to 3) {
  54. if (a(i) > 0) {
  55. destinationFound(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  56. }
  57. karel = karel.turnLeft
  58. }
  59. } else if (twos == 1) {
  60. for (i <- 0 to 3) {
  61. if (a(i) == 2) {
  62. destinationFound(karel.tearDownWall.moveForward.turnAround.tearDownWall.turnAround, n - 1)
  63. }
  64. karel = karel.turnLeft
  65. }
  66. }
  67. }
  68.  
  69. try {
  70. destinationOpen(Karel(1, 1, EAST, labyrinth), N * N)
  71. walkTheLabyrinthStatic
  72. } catch {
  73. case Solution(karel) =>
  74. karel.dropBeeper.copy(x = 1, y = 1).turnAwayFromWall
  75. }
  76. }
  77.  
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
Main.scala:1: error: expected class or object definition
  def walkTheLabyrinth: Karel = {
  ^
one error found
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