val numbers = "0123456789".mapTo(hashSetOf()) { it } val lowercase = "abcdefghijklmnopqrstuvwxyz".mapTo(hashSetOf()) { it } val uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".mapTo(hashSetOf()) { it } val specials = "!@#$%^&*()-+".mapTo(hashSetOf()) { it } fun main(args: Array) { readLine() val password = readLine()!! // If password is strong, return 0. // If password is not strong, return r. // If password size < 6, return 6. // Otherwise: // - If it doesn't contain any lowercase chars, r plus 1. // - If it doesn't contain any uppercase chars, r plus 1. // - If it doesn't contain any special char, r plus 1. fun String.isStrong(): Boolean { return this.length >= 6 && !this.any { !numbers.contains(it) || !lowercase.contains(it) || !uppercase.contains(it) || !specials.contains(it) } } fun Boolean.toInt() = if (this) 1 else 0 fun String.getStrongCharCount(): Int = setOf(numbers, lowercase, uppercase, specials) .map { x -> this.none { x.contains(it) } } .map { it.toInt() } .sum() when { password.isStrong() -> println(0) else -> println(Math.max( password.getStrongCharCount(), 6 - password.length )) } }