Simpler(?) version of numerical decomposition#182
Simpler(?) version of numerical decomposition#182Tibo-lg wants to merge 1 commit intodiscreetlogcontracts:masterfrom
Conversation
| This optimization is called the **endpoint optimization**. | ||
| while value > 0 { | ||
| res.push(value % base); | ||
| value = ((value as f64) / (base as f64)).floor() as usize; |
There was a problem hiding this comment.
maybe should just make value and base f64s insted of casting them since it is just an example
There was a problem hiding this comment.
Mmmmm I'm a bit hesitant because I feel it's quite important to return integers and not floats and I'd be worried that someone just copy pasting that thinks that they can just manipulate floats all over and be fine (tbh I'm not sure if it's actually fine or not, but I think it's just better to avoid it).
| startDigits.last.to(endDigits.last).toVector.map { lastDigit => | ||
| prefixDigits :+ lastDigit | ||
|
|
||
| // All the single digits in ]start[0]; end[0][ are sufficient to cover their respective intervals. |
There was a problem hiding this comment.
]start[0]; end[0][
I think this is meant to be [start[0]; end[0]]
There was a problem hiding this comment.
I think ] start[0]; end[0] [ is correct. If it were [start[0]; end[0]] then in the example it would include 1 and 4 which are covered in the loops above and under. Let me know if maybe something is unclear (or if maybe I'm just missing something).
Happy to hear :) |
This PR proposes an update to the numerical decomposition document, to try to make things a bit easier to understand. I think "easy to understand" is a subjective notion though and so if people don't think this version is simpler I'll happily close this PR.
One thing to note is that unless I'm mistaken, the stated
O(B*log_B(L))seems incorrect to me as the worst case is above it.Also if people think rust is not easy to read I could change it to typescript. I hope the code comments are enough to understand the code though.