package aoc2015

import println
import readInput

/*
--- Day 1: Not Quite Lisp ---
https://adventofcode.com/2015/day/1
*/
fun main() {

    val inlineTestInput = """
(()(()(
"""

    fun part1(input: List<String>): Int {
        return input.single().count { it == '(' } - input.single().count { it == ')' }
    }

    fun part2(input: List<String>): Int {
        var floor = 0
        for ((i, c) in input.single().withIndex()) {
            if (c == '(') floor++ else floor--
            if (floor < 0) return i + 1
        }
        return 0
    }

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

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