Hex Triplets

A list of all possible hex trpliets.

by bryandowning

HTML

<textarea id="results"></textarea>
<div id="details">Number of combinations: </div>

CSS

#results {
    width: 100%;
    height: 200px;
    box-sizing: border-box;
    display: block;
}

CoffeeScript

#chars = '0123456789ABCDEF'
chars = '01'
charList = chars.split('')




            
buildCombinations = ( chars, length ) ->

    items = []
    combinations = []
    charList = chars.split ''
    position = 1
    

    for char in charList
        item = []
        item.push char while item.length < length
        items.push item
        combinations.push item.join('')
    

    replaceChar = ( position ) ->
        for item in items
            for char in charList
                newItem = item[..]
                if newItem[position] isnt char
                    newItem[position] = char
                    items.push newItem
                    combinations.push newItem.join('')
                    
    while position < length
        replaceChar position
        position++
        
    return combinations

combinations = buildCombinations chars, 3

$('#results').val JSON.stringify combinations

$('#details').append combinations.length