JSFiddle - React, Tailwind, and code Playground

by Alex Shnayder

HTML

<p>Очки — среднее число пустых ячеек за 1000 запусков, меньше — лучше.</p>

<table id="scoretable">
    <thead>
        <tr>
            <td></td>
            <td>Участник</td>
            <td>Очки</td>
            <td>Ошибки</td>
        </tr>
    </thead>
</table>

CSS

#scoretable {
    font-size: 16px;
    line-height: 1.4;
    border-collapse: collapse;
}

#scoretable thead td {
    font-weight: 700;
    border-bottom: 1px solid #ccc;
}

#scoretable td {
    padding: 5px 30px 5px 5px;
}

#scoretable tr:nth-child(even) {
    background: #f5f5f5;
}

JavaScript

var contenders = {
    'tigerforce': function(w, h, cols) {
        function calculateScore(col) {
            if (cols[col] + h > 20 || col + w > 10) {
                return 999;
            }
            
            var score = 0;
            
            for (var i = col; i < col + w; i++) {
                if (cols[i] > cols[col]) {
                    return 999;
                }
                
                score += cols[col] - cols[i];
            }
            
            return score;
        }
        
        var bestMatch = {
            col: 0,
            score: cols[0]
        },
            colScore = 0;
        
        for (var i = 0; i <= cols.length - w; i++) {
            colScore = calculateScore(i);
            
            if (colScore < bestMatch.score || (colScore == bestMatch.score && cols[i] < cols[bestMatch.col])) {
                bestMatch.col = i;
                bestMatch.score = colScore;
            }
        }
        
        return bestMatch.col + 1;
    },
    
    'H3kra': function(w, h, cols) {
        var starts = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1], //contains the beginnings of straight levels
            heights = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1], // contains straight levels heights
            lengths = [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]; //contains straight levels lengths
        
        var currentCol = 0;
        
        starts[currentCol] = currentCol;
        heights[currentCol] = cols[0];
        lengths[currentCol] = 1;
        
        for (var i=1; i < 10; i++)
        {
            if (cols[i-1] == cols[i])
            {
                lengths[currentCol]++;
            }
            else
            {
                currentCol++;
                starts [currentCol] = i;
                heights[currentCol] = cols[i];
                lengths[currentCol] = 1;
            }
        }
        
        var minH = heights[0],
            minCol = 0;
        
        for (var i=1; i < 10 || starts[i] > 0; i++)
 ...