Skip to content

Instantly share code, notes, and snippets.

@LOZORD
Last active November 19, 2015 06:03
Show Gist options
  • Save LOZORD/3d730ac46f6ea9246e04 to your computer and use it in GitHub Desktop.
Save LOZORD/3d730ac46f6ea9246e04 to your computer and use it in GitHub Desktop.
The programmatic representation of whether or not you are a Badger who takes WildHacks by storm.
// Whether Passenger p (you) can get on the bus at Time t
public boolean attemptToGetOnBus(Passenger p, Time t) throws HustleError {
if (!p.location().equal("CS Building")) {
return false; // what are you doing, kiddo?
} else if (!p.isRegisteredForWildHacks()) {
return false;
}
Time startTime = Time.earliestOf(LEO.arrival(), Time.FIVE_THIRTY);
if (!t.isBetween(startTime, Time.SIX_SHARP)) {
return false;
}
// Now for the interesting part...
if (p.hasBusTicket()) {
if (t.isBefore(Time.FIVE_FIFTY)) {
return true; // welcome aboard!
} else {
// run! there may still be a seat for you!
throw new HustleError();
}
} else if (p.isWaitlisted()) {
if (t.isBefore(Time.FIVE_FIFTY)) {
this.waitListQueue().enqueue(p);
p.waitUntil(Time.FIVE_FIFTY);
} else {
if (this.hasSeatsOpen() && this.waitListQueue().peek().equals(p)) {
this.waitListQueue.dequeue();
return true;
}
else {
return false;
}
}
} else {
return false; // wat?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment