SHARE
TWEET

sdagdsagsdagsdag

a guest Sep 3rd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import scala.io.Source
  2. import scala.collection.mutable
  3.  
  4. object Application extends App {
  5.     val fileReader = Source.fromFile("src/main/input/puzzle1")
  6.     val lines = fileReader.getLines.toList
  7.  
  8.     // Lag et brett som er strippet for unødvendige whitespaces
  9.     // Lag en verdi-matrise ut i fra denne
  10.     // Lag en nabo-matrise ut i fra denne
  11.  
  12.     fileReader.close()
  13.  
  14.     val size_string = lines.slice(1, 2)(0).toString
  15.     val puzzle = lines.slice(2, lines.length)
  16.  
  17.     var character_matrix:List[List[Char]] = List[List[Char]]()
  18.  
  19.     for(line <- puzzle) {
  20.         var row:List[Char] = List[Char]()
  21.  
  22.         for(char <- line) {
  23.             if(char != " ") {
  24.                 row = row :+ char
  25.             }
  26.         }
  27.  
  28.         character_matrix +:= row
  29.     }
  30.  
  31.     var value_matrix:List[List[Char]] = List[List[Char]]()
  32.  
  33.     for(y <- 0 until character_matrix.length by 2) {
  34.         var row:List[Char] = List[Char]()
  35.  
  36.         for(x <- 0 until character_matrix(0).length by 4) {
  37.             val current = character_matrix(y)(x)
  38.             row = row :+ current
  39.         }
  40.  
  41.         value_matrix +:= row
  42.     }
  43.  
  44.     var value_matrix_2 = List[List[List[Int]]]()
  45.  
  46.     for(y <- 0 until value_matrix.length) {
  47.         val row:List[List[Int]] = List[List[Int]]()
  48.  
  49.         for(x <- 0 until value_matrix(y).length) {
  50.             if(value_matrix(y)(x) == "_") {
  51.                 val l:List[Int] = List(1, 2, 3, 4)
  52.  
  53.                 row(0) = l
  54.             }
  55.         }
  56.     }
  57.  
  58.     value_matrix_2.foreach(println)
  59. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top