package aoc2015

import md5
import println
import readInput

/*
--- Day 4: The Ideal Stocking Stuffer ---
https://adventofcode.com/2015/day/4
*/
fun main() {

    val inlineTestInput = """
abcdef
"""

    fun part1(input: List<String>): Int {
        return IntRange(0, 10000000).first { (input.single() + it.toString()).md5().startsWith("00000") }
    }

    fun part2(input: List<String>): Int {
        return IntRange(0, 10000000).first { (input.single() + it.toString()).md5().startsWith("000000") }
    }

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

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