Skip to content

Instantly share code, notes, and snippets.

View RMGiroux's full-sized avatar

Mike Giroux RMGiroux

  • Bloomberg L.P.
  • New York, NY
View GitHub Profile
#!/usr/bin/perl -w
# Simulate the "will you get your seat on a plane if a rude passenger
# picks a seat at random at the start of boarding" puzzle posed here:
# http://fivethirtyeight.com/features/will-someone-be-sitting-in-your-seat-on-the-plane/
# My spoilery attempt to explain the unexpected result this script generates is at
# https://gist.github.com/RMGiroux/dd8856e68dd0ed5f3064
use strict;
// Copyright 2015, Mike Giroux
// Licensed under Apache License 2.0 : http://www.apache.org/licenses/LICENSE-2.0
// Permission is explicitly granted to aggregate this solution with any other
// solutions to the Regehr Nibble-sort Challenge (http://blog.regehr.org/archives/1213)
// for benchmarking or pedagogical purposes, or any other purposes allowed by AL2.0.
unsigned long nibble_sort_word(unsigned long word) {
char nibble_counts[16] = {0};
unsigned long result = 0;
unsigned char nibble_index = 15;