package pl.polgrabia.demos.crackingcodeinterview.t17x6

import org.slf4j.Logger
import org.slf4j.LoggerFactory

var logger : Logger = LoggerFactory.getLogger("ProgramKt")

fun countOfDigit(n: Int, digit: Int): Int {
    var t = n
    var counter = 0
    while (t > 0) {
        if (t % 10 == digit) {
            counter++
        }
        t /= 10
    }
    logger.info("Counter of {} digit in {} is {}", digit, n, counter)
    return counter
}

fun main() {
    print("Give n: ")
    val n = readln().toInt()
    var count = 0
    for (i in 1..n) {
        count += countOfDigit(i, 2)
    }
    println("Count is: $count")
}