(a)
12월 31일 말한 사람 승
12월 1일 말한 사람 패
11월 30일 말한 사람 승
(최소 시간)
= (2t.1 + t.2 + t.3 + t.4)
t는 각각 1, 2, 5, 10 이므로 대입하면 17분이다.
1번 사람이 더 빠른 경우는 1번 사람 3번 사람의 건너는 시간의 합이 2번 사람 건너는 시간의 두 배보다 작은 경우이므로
object Pegman extends App { | |
def minArrows(grid: IndexedSeq[IndexedSeq[Char]]): Option[Int] = { | |
val (row, column) = (grid.size, grid(0).size) | |
def isArrow: ((Int, Int)) => Boolean = { case (r, c) => "^v><" contains grid(r)(c) } | |
implicit class Grids(grids: Seq[(Int, Int)]) { | |
lazy val containsArrow: Boolean = grids map isArrow exists identity | |
} |
package lascala.aoc2021.day1_10.day9 | |
case class Point(row: Int, column: Int) | |
case class HeightMap( | |
map: Map[Point, Int], | |
numberOfRows: Int, | |
numberOfColumns: Int, | |
) |
package lascala.aoc2021.day1_10.day8 | |
opaque type Digit = Set[Char] | |
opaque type SignalPattern = Set[Digit] | |
def parse(s: String): (SignalPattern, Seq[Digit]) = | |
val Array(pattern, digits) = s.split(" \\| ") | |
def parsePart(s: String): Seq[Digit] = | |
s.split(" ").map(_.toSet).toSeq | |
(parsePart(pattern).toSet, parsePart(digits)) |
package lascala.aoc2021.day1_10.day7 | |
def findMinCost(from: Int, to: Int, cost: Int => Int): Int = | |
val mid = (from + to) / 2 | |
val fromCost = cost(from) | |
val toCost = cost(to) | |
if (from + 1) >= to then (fromCost min toCost) | |
else if fromCost >= toCost then findMinCost(mid, to, cost) | |
else findMinCost(from, mid, cost) |