Skip to content

Commit b302809

Browse files
committed
follow the required format
1 parent 5b45cde commit b302809

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

2022/src/day07.scala

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,36 @@ import locations.Directory.currentDir
44
import inputs.Input.loadFileSync
55

66
@main def part1: Unit =
7-
val root: Directory = Directory("/")
8-
run(loadInput(), List(root))
9-
val solution =
10-
allSubdirs(root)
11-
.map(totalSize)
12-
.filter(_ <= 100_000L)
13-
.sum
14-
println(s"The solution is $solution")
7+
println(s"The solution is ${part1(loadInput())}")
158

169
@main def part2: Unit =
17-
val root: Directory = Directory("/")
18-
run(loadInput(), List(root))
19-
val sizeNeeded = totalSize(root) - 40_000_000L
20-
val solution =
21-
allSubdirs(root)
22-
.map(totalSize)
23-
.filter(_ >= sizeNeeded)
24-
.min
25-
println(s"The solution is $solution")
26-
27-
def loadInput(): List[Command] =
28-
loadFileSync(s"$currentDir/../input/day07")
10+
println(s"The solution is ${part2(loadInput())}")
11+
12+
def loadInput(): String = loadFileSync(s"$currentDir/../input/day07")
13+
14+
def parse(input: String): List[Command] =
15+
input
2916
.linesIterator
3017
.map(Command.fromString)
3118
.toList
3219

20+
def part1(input: String): Long =
21+
val root: Directory = Directory("/")
22+
run(parse(input), List(root))
23+
allSubdirs(root)
24+
.map(totalSize)
25+
.filter(_ <= 100_000L)
26+
.sum
27+
28+
def part2(input: String): Long =
29+
val root: Directory = Directory("/")
30+
run(parse(input), List(root))
31+
val sizeNeeded = totalSize(root) - 40_000_000L
32+
allSubdirs(root)
33+
.map(totalSize)
34+
.filter(_ >= sizeNeeded)
35+
.min
36+
3337
// data model & parsing: directory tree
3438

3539
import collection.mutable.ListBuffer

0 commit comments

Comments
 (0)