A new optimization algorithm called sperm whale algorithm (SWA) is proposed to solve production optimization problems. This algorithm is based on the sperm whale's lifestyle. Like other population-based algorithms, SWA uses a population of solutions to find the optimum answer. One of the advantages of this method over others is that it uses two contradictory types of answers: it uses the worst and the best answers to reach the optimum point. The SWA algorithm was tested on 26 benchmarks and three benchmarks in several dimensions and one production optimization problem. The results and comparison of its performance with other algorithms show that SWA's performance is superior to other algorithms and it could be confidently used in optimization tasks.