diff --git a/src/main/kotlin/CustomAdt.kt b/src/main/kotlin/CustomAdt.kt index c30e0c4..7d404e9 100644 --- a/src/main/kotlin/CustomAdt.kt +++ b/src/main/kotlin/CustomAdt.kt @@ -9,7 +9,18 @@ sealed interface ParseResult { object CustomAdt { fun parseInt(str: String): ParseResult { - TODO() + var res = 0 + val sign = if (str.startsWith("-")) -1 else 1 + val symbolsToSkip = if (sign == -1) 1 else 0 + + for ((i, char) in str.withIndex().drop(symbolsToSkip)) { + if (char !in '0'..'9') + return ParseResult.Failure(i, char) + + res = res * 10 + (char - '0') + } + + return ParseResult.Success(res * sign) } } \ No newline at end of file