Wrack and rack are etymologically distinct, meaning they come from different words. Many usage guides will advise that you should use wrack for meanings such as "to utterly ruin," and rack for "to cause to suffer torture, pain, anguish, or ruin." If you follow this advice, the proper choice for what you do to your brain when thinking very hard is rack. However, wrack has long been used as a variant of rack, and numerous fine writers have avowedly wracked their brains or found something nerve-wracking.