package aoc2022

import listOfIntegerLists
import println
import readInput

/*
--- Day 1: Calorie Counting ---
https://adventofcode.com/2022/day/1
*/
fun main() {

    val inlineTestInput = """
1000
2000
3000

4000

5000
6000

7000
8000
9000

10000
"""

    fun part1(input: List<String>): Int {
        return listOfIntegerLists(input).map { it.sum() }.max()
    }

    fun part2(input: List<String>): Int {
        return listOfIntegerLists(input).map { it.sum() }.sortedDescending().take(3).sum()
    }

    // test if implementation meets criteria from the description, like:
    val testInput = inlineTestInput.trim().reader().readLines()
    //val testInput = readInput("aoc2022/Day01_test")
    println("Part 1 Test: " + part1(testInput))
    println("Part 2 Test: " + part2(testInput))
    check(part1(testInput) == 24000)
    check(part2(testInput) == 45000)

    val input = readInput("aoc2022/Day01")
    part1(input).println()
    part2(input).println()
}
