Solution to 3n+1 problem