3 ms·
Mmm. I think @m_ou_se is probably the most entertaining at least if we consider that both Saturday Night Live and Nightmare On Elm Street is entertainment. For
by tialaramex 4y ago
Mmm. I think @m_ou_se is probably the most entertaining at least if we consider that both Saturday Night Live and Nightmare On Elm Street is entertainment.
For example, Rust deliberately doesn't have the tertiary operator, and random other types don't get silently coerced as booleans - so you can't write a = x ? 1 : -1; however you can write a = if x != 0 { 1 } else { -1 }; with the same effect. But Mara isn't satisfied with this verbose yet sensible answer, and proposes you could instead, for example:
a = x.count_ones().count_ones().count_ones().count_ones() as i32 * 2 - 1;
Hilarious? Or maybe terrifying? Entertaining certainly. https://twitter.com/m_ou_se/status/1404034056405368833?lang=en https://twitter.com/m_ou_se/status/1404034056405368833?lang=...
Aria is more informative but I'm not going to end up choking and spilling my beverage all over the desk.
- GolDDranks 4y agoThat's a hilarious code crime! I checked it and it turns out that this works for 64-bit integers too. It's 2^128 - 1 that is the first number that requires five calls to count_ones to work!
- pbsd 4y agoYou could also do `1|!((x|-x)>>30)`