Skip to content

Instantly share code, notes, and snippets.

@thejoshwolfe
Created August 25, 2017 23:28
Show Gist options
  • Save thejoshwolfe/6df79a3c5b3e7b30ae184ced0f7eb9c0 to your computer and use it in GitHub Desktop.
Save thejoshwolfe/6df79a3c5b3e7b30ae184ced0f7eb9c0 to your computer and use it in GitHub Desktop.

Revisions

  1. thejoshwolfe created this gist Aug 25, 2017.
    17 changes: 17 additions & 0 deletions main.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    int median3(int a, int b, int c) {
    int index =
    ((a < b) << 0) |
    ((b < c) << 1) |
    ((c < a) << 2);
    switch (index) {
    case 0: unreachable();
    case 1: return c;
    case 2: return a;
    case 3: return b;
    case 4: return b;
    case 5: return a;
    case 6: return c;
    case 7: unreachable();
    }
    unreachable();
    }