Inkyrius

The Girl Anachronism

 


 
This place is not a place of honour. No highly esteemed deed is commemorated here. Nothing valued is here.

 
Inkyrius or Inky or Kyrie are all fine.
Girl with a dash of Void.

 
Queer Trans Nerd. Mostly Harmless.
Interests include programming, formerly Minecraft modding, conlangs, worldbuilding, maps, typography, etc.

 




I let tumblr choose my what book I should read next because I couldn't decide, some expected results here but also some surprising ones.

I sort of expected that Invisible Cities and This Is How You Lose the Time War would be in the top few places, just based on what sort of books I know my followers would read. I definitely thought the results would be flatter though, I didn't think any single book would have this much support.

I can understand Ancillary Sword doing well, though I didn't expect third. I thought for sure Schild's Ladder would make the top three, but it's only ended up in sixth.

The one that surprised me the most was Serious Weakness getting no votes; I know some of my followers are Porpentine fans, did they really not want me to read the fucked up boys book?



quat
@quat
This page's posts are visible only to users who are logged in.


Inkyrius
@Inkyrius

I think the obvious solution is to switch between what I would consider the two “intuitive” answers (1st and 5th on your list) based on the characteristics of the numbers. (a + b) can only fail in cases when both numbers are of the same sign, while (high - low) can only fail in cases where both numbers have different signs.

It would be nicer to have a single equation for it though. I'm going to be thinking about this all day aren't I, damn.


Inkyrius
@Inkyrius

Hmm, just checked and (low + (high - low) / 2) also fails in certain other cases (when both are negative and one is odd I think, but it might be more specific), however it works if you get low and high with the absolute min and max (position relative to zero) rather than just the regular min and max (position relative to -inf).


Inkyrius
@Inkyrius

Realised I was going to add my code and then never did, but I'm pretty sure this works for all cases unless one of the numbers is INT_MIN (abs(INT_MIN) == INT_MAX + 1 which obviously breaks. Pretty easy to fix, you can find closest to zero without abs because it will always be fed numbers of the same sign, but I can't be bothered at the moment):

#include <stdio.h>
#include <stdlib.h>

int absmax(int a, int b) { return (abs(a) > abs(b)) ? a : b; }
int absmin(int a, int b) { return (abs(a) < abs(b)) ? a : b; }

int signedAvg(int a, int b) {
  if ((a < 0) != (b < 0)) {
    return (a + b) / 2;
  }
  else {
    int low = absmin(a, b);
    int high = absmax(a, b);
    return low + ((high - low) / 2);
  }
}
syntax highlighting by codehost