JSFiddle - React, Tailwind, and code Playground

JavaScript

// Note:
// I collected data on my true combination but added a random integeger
// to all the numbers so I don't need to change my lock combination. 
// The answer here is 7,8,7,0, but this is not related to my true combination.
var nums = [
[5,7,7,1],
[4,6,0,0],
[5,8,7,1],
[9,9,9,2],
[7,7,5,9],
[7,9,9,0],
[8,8,5,8],
[8,0,1,4],
[6,3,4,9],
[8,8,5,9],
[4,6,4,5],
[8,9,8,2],
[4,3,9,4],
[9,0,5,8]
];

var wheel = [0,1,2,3,4,5,6,7,8,9];

function l1(num1, num2) {
  return Math.min( 
    Math.abs(num1-num2),
    Math.abs(Math.abs(num1 - num2) - wheel.length) );
}

function minL1(idx) {
  var curDistance = Infinity;
  var guess = 0;
  for(var i = 0; i < wheel.length; i++) {
    var newL1 = 0;
    for(var j = 0; j < nums.length; j++) {
      newL1 += l1(i, nums[j][idx]);
    }
    if(newL1 < curDistance) {
      curDistance = newL1;
      guess = i;
    }
  }
  return guess;
}

function solve() {
    var answer = [0,0,0,0];
    answer.forEach(function(elem, idx, arr){
      answer[idx] = minL1(idx);
    });
    alert(answer);
}
solve();