File reading
This commit is contained in:
parent
abc35536e4
commit
4652ca7a45
@ -1,5 +1,13 @@
|
|||||||
|
import scala.util.Failure
|
||||||
|
import scala.util.Success
|
||||||
|
|
||||||
object Day01 extends Solution:
|
object Day01 extends Solution:
|
||||||
override def part_01() =
|
override def part_01() =
|
||||||
|
val file = this.read_input("01") match
|
||||||
|
case Success(f) => f
|
||||||
|
case Failure(ex) =>
|
||||||
|
return "Error opening file: " + ex.getMessage()
|
||||||
|
|
||||||
"part 1 :D"
|
"part 1 :D"
|
||||||
|
|
||||||
override def part_02() =
|
override def part_02() =
|
||||||
|
@ -6,4 +6,3 @@ import scala.util.Random
|
|||||||
println("Advent of code 2022 with Scala")
|
println("Advent of code 2022 with Scala")
|
||||||
println(Day01.part_01())
|
println(Day01.part_01())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,21 @@
|
|||||||
|
import java.io.BufferedReader
|
||||||
|
import scala.util.Try
|
||||||
|
import scala.util.Failure
|
||||||
|
import java.io.FileReader
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import scala.util.Success
|
||||||
|
import scala.io.BufferedSource
|
||||||
|
import scala.io.Source
|
||||||
|
|
||||||
|
|
||||||
trait Solution:
|
trait Solution:
|
||||||
def part_01(): String
|
def part_01(): String
|
||||||
def part_02(): String
|
def part_02(): String
|
||||||
|
|
||||||
|
def read_input(day: String): Try[BufferedSource] =
|
||||||
|
try
|
||||||
|
Success(Source.fromFile(s"./inputs/day$day.txt"))
|
||||||
|
catch
|
||||||
|
case ex: java.io.FileNotFoundException =>
|
||||||
|
Failure(ex)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user