Skip to content

Instantly share code, notes, and snippets.

@eburke
eburke / Main.java
Created March 15, 2016 01:42
Unexpected coin toss probability
import java.util.Random;
/*
If Alice tosses a coin until she sees a head followed by a tail, and Bob tosses a coin until he
sees two heads in a row, then on average, Alice will require four tosses while Bob will require
six tosses (try this at home!), even though head-tail and head-head have an equal chance of
appearing after two coin tosses.
https://www.quantamagazine.org/20160313-mathematicians-discover-prime-conspiracy/
*/
@eburke
eburke / SafeViewFlipper.java
Created August 23, 2013 20:33
Workaround for Android Bug 6191
/**
* Works around Android Bug 6191 by catching IllegalArgumentException after
* detached from the window.
*
* @author Eric Burke (eric@squareup.com)
*/
public class SafeViewFlipper extends ViewFlipper {
public SafeViewFlipper(Context context) {
super(context);
}