Created
March 11, 2019 18:44
-
-
Save s5bug/0758d77e1d2e54a07c59154eb5afee9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Main extends IOApp { | |
val coordReg = """(\d+) (\d+)""".r | |
override def run(args: List[String]): IO[ExitCode] = { | |
implicit val ec: ExecutionContextExecutor = ExecutionContext.global | |
program[IO].compile.drain.as(ExitCode.Success) | |
} | |
def program[F[_]: Monad : ContextShift](implicit ec: ExecutionContext, sync: Sync[F]): Stream[F, Unit] = { | |
val control = RectangleControl[F](10, 10, 10) | |
val lineIn = io.stdin[F](1024, ec).filter(_ != '\r').split(_ == '\n'.toByte) | |
val boards = lineIn.scan(control.empty)((board, in) => board.flatMap { b => | |
val line = in.map(_.toChar).toList.mkString | |
if(line.matches(coordReg.regex)) { | |
val coordReg(x, y) = line | |
control.unearth(Vec2[F](x.toInt, y.toInt))(b) | |
} else { | |
Stream.eval(sync.delay(println("Invalid input!"))).map(_ => b) | |
} | |
}).flatten | |
boards.flatMap(control.show).evalMap(s => sync.delay(println(s))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment