package aoc2015

import println
import readInput

/*
--- Day 2: I Was Told There Would Be No Math ---
https://adventofcode.com/2015/day/2
*/
fun main() {

    val inlineTestInput = """
2x3x4
1x1x10
"""

    fun part1(input: List<String>): Int {
        return input.sumOf {
            val dims = it.split("x").map(String::toInt).sorted()
            2 * dims[0] * dims[1] + 2 * dims[1] * dims[2] + 2 * dims[0] * dims[2] + dims[0] * dims[1]
        }
    }

    fun part2(input: List<String>): Int {
        return input.sumOf {
            val dims = it.split("x").map(String::toInt).sorted()
            2 * (dims[0] + dims[1]) + dims.reduce(Int::times)
        }
    }

    // test if implementation meets criteria from the description, like:
    val testInput = inlineTestInput.trim().reader().readLines()
    //val testInput = readInput("aoc2015/Day02_test")
    val testInputPart1Result = part1(testInput)
    println("Part 1 Test: $testInputPart1Result")
    val testInputPart2Result = part2(testInput)
    println("Part 2 Test: $testInputPart2Result")
    check(testInputPart1Result == 58 + 43)
    check(testInputPart2Result == 34 + 14)

    val input = readInput("aoc2015/Day02")
    part1(input).println()
    part2(input).println()
}
