Some ruby algorithms