This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isValidSudoku(board: List<CharArray>): Boolean { | |
if (board.isEmpty()) return false | |
val boardSize = board.size | |
val baseGrid = kotlin.math.sqrt(boardSize.toDouble()).toInt() | |
board.forEach { row -> if (boardSize != row.size || row.size <= 1) return false } | |
val seenInRow = Array(boardSize) { HashSet<Char>() } | |
val seenInColumn = Array(boardSize) { HashSet<Char>() } | |
val seenInGrid = Array(boardSize) { HashSet<Char>() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isValidIPv4Address(ipAddress: String): Boolean { | |
val segments = ipAddress.split('.') | |
val maxNumberOfSegments = 4 | |
if (ipAddress.isEmpty() || segments.count() != maxNumberOfSegments) return false | |
segments.forEach { item -> | |
if (!item.all { it.isDigit() }) return false | |
val rangeOfSegment = 0..255 | |
val segment = item.toIntOrNull() ?: return false | |
if ((item.count() > 1 && item.startsWith('0')) || segment !in rangeOfSegment) return false | |
} |