Sam and I (mostly Sam) wrote algorithm which solves Shut the Box problem