Skip to content

Day 5 - some improvements #1

@narimiran

Description

@narimiran

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions