(no title)
wenderen | 3 months ago
Rust newbie q - why use `x.wrapping_sub()` instead of regular old `x - 1`? Seems like we're never going to underflow `usize` for any of the 3 formulae?
wenderen | 3 months ago
Rust newbie q - why use `x.wrapping_sub()` instead of regular old `x - 1`? Seems like we're never going to underflow `usize` for any of the 3 formulae?
throwaway81523|3 months ago
cbarrick|3 months ago
Now that we know the start of the sequence, we can just dump it into OEIS to look up the answer! :)
The sequence is A046180 (https://oeis.org/A046180) titled "Hexagonal pentagonal numbers" with a nice and easy recurrence relation:
Also, according to the comments on OEIS, all hexagonal numbers are triangular, so we could have just skipped that requirement entirely.cbarrick|3 months ago
Because I coded it to start at x=0, which will underflow and will panic in debug mode.