Загрузка...

Discovering Infinite Loops, Handling Custom Iteration, Error handling, Debugging, Testing

Problem

Input: a string containing a sequence of commands separated by semicolons; each command is one of:

"ADD x" (add integer x to a running total),

"MUL x" (multiply running total by x),

"IFZERO goto n" (if running total == 0, jump to the nth command, 1-based),

"PRINT" (append current total to output).

Commands may have extra spaces; ignore blank commands; invalid commands should cause an error with a helpful message.

Output: list of printed integers in order, or an error if a jump targets an invalid line or a command is malformed.

Constraints: input length up to ~10k characters, values fit in 64-bit signed.

Why this tests problem-solving

Requires tokenizing and robust parsing (trimming, splitting, number parsing).

Needs control-flow handling (jumps), loop detection/termination care.

Shows use of Kotlin features: sealed classes, data classes, when, extension functions, exception handling, and idiomatic collection usage.

Видео Discovering Infinite Loops, Handling Custom Iteration, Error handling, Debugging, Testing канала Dr Priyanthi Dassanayake
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять