At line 36, you're using multiReplace twice:
let data = input.multiReplace(($x, "")).multiReplace(($(char(ord(x)-32)), ""))
You can simplify (and probably slightly improve speed) it by using just one of them:
let data = input.multiReplace(($x, ""), ($(char(ord(x)-32)), ""))
But, since you already return a string from solve1, much bigger speed improvement can be achieved by re-using that shortened string:
let shortened = solve1(input)
echo shortened.len
echo solve2(shortened)
(After that, if you want even faster solution, I wouldn't directly modify data by using delete in solve1 — that's quite expensive)
At line 36, you're using
multiReplacetwice:You can simplify (and probably slightly improve speed) it by using just one of them:
But, since you already return a string from
solve1, much bigger speed improvement can be achieved by re-using that shortened string:(After that, if you want even faster solution, I wouldn't directly modify
databy usingdeleteinsolve1— that's quite expensive)