package aoc2022

import println
import readInput

/*
--- Day 2: Rock Paper Scissors ---
https://adventofcode.com/2022/day/2
*/
fun main() {

    val inlineTestInput = """
A Y
B X
C Z
"""

    fun part1(input: List<String>): Int {
        return input.sumOf {
            val c = it[0] - 'A'
            val r = it[2] - 'X'
            (r + 1) + ((r - c + 4) % 3) * 3
        }
    }

    fun part2(input: List<String>): Int {
        return input.sumOf {
            val c = it[0] - 'A'
            val l = it[2] - 'X'
            val r = (l - c * 2 + 8) % 3
            (r + 1) + ((r - c + 4) % 3) * 3
        }
    }

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

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