Trying to reach immutability without success

For the third day of the Advent of Code I’ve been trying to reach immutability without success today.

Any ideas on how I can get rid of these var variables here?

fun part1(input: List<String>): Int { return input.toArray().let {array -> var sum = 0 var isAdjacentToASymbol = false var numberString = "" array.forEachIndexed { i, row -> row.forEachIndexed { j, _ -> val char = array[i][j] if (char in numbers) { if (!isANumberToTheLeft(array, i, j)) { numberString = "" isAdjacentToASymbol = false } numberString += char if (isAdjacentToASymbol(array, i, j)) { isAdjacentToASymbol = true } if (numberString.isNotBlank() && isAdjacentToASymbol && !isANumberToTheRight(array, i, j)) { sum += numberString.toInt() numberString = "" isAdjacentToASymbol = false } } } } sum } } 

submitted by /u/regular-tech-guy
[link] [comments]