I always have this thought. I'm doing it in Rust, so I check if there are negative numbers: if not, use usize. But I'm always terrified there will be an overflow somewhere.
If I were using Kotlin or Java, I might always use BigInteger just out of fear.
That’s a very interesting thought! I was thinking of writing my own Rust data type that would automatically upgrade to big integer, similarly to the int type in Python.
I lost twenty minutes to rewriting everything to deal with BigInts when I saw the data, and then switching it all back when I realised my error. I panicked too soon.
Considered sticking all the values in a set. Considered input. Coalesced the ranges instead. Ran both parts in 0.1 ms.
I'm actually looking forward a bit to 12 days this year. Previous AOC took a bit long to ramp up. Am expecting recursion imminently, dynamic programming next week, and complete head scratching bastardry to round out the week.
7 Comments
hades@programming.dev · 11 pts · 289d
it all fit in int64 tho, so could be worse
cabhan@discuss.tchncs.de · 2 pts · 282d
I always have this thought. I'm doing it in Rust, so I check if there are negative numbers: if not, use
usize. But I'm always terrified there will be an overflow somewhere.If I were using Kotlin or Java, I might always use
BigIntegerjust out of fear.hades@programming.dev · 1 pts · 281d
That’s a very interesting thought! I was thinking of writing my own Rust data type that would automatically upgrade to big integer, similarly to the int type in Python.
GiantTree@feddit.org · 1 pts · 280d
I am doing AOC in Kotlin. Longs are fine. I haven't encountered a puzzle that required ULong or BigInteger.
VegOwOtenks@lemmy.world · 1 pts · 289d
Really this. I fear the day the inputs become that large.
mykl@lemmy.world · 1 pts · 289d
I lost twenty minutes to rewriting everything to deal with BigInts when I saw the data, and then switching it all back when I realised my error. I panicked too soon.
addie@feddit.uk · 6 pts · 289d
Considered sticking all the values in a set. Considered input. Coalesced the ranges instead. Ran both parts in 0.1 ms.
I'm actually looking forward a bit to 12 days this year. Previous AOC took a bit long to ramp up. Am expecting recursion imminently, dynamic programming next week, and complete head scratching bastardry to round out the week.