Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day 5 - some improvements #1

Open
narimiran opened this issue Dec 6, 2018 · 1 comment
Open

Day 5 - some improvements #1

narimiran opened this issue Dec 6, 2018 · 1 comment

Comments

@narimiran
Copy link

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)

@tradfursten
Copy link
Owner

@narimiran Thanks for the comment! I am in the process of learning Nim and suggestions like this is welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants