December 0x10th - Patches

December 16th, the perfect day for a hex based puzzle.

The elves are making Santa a Christmas present to celebrate all his hard work! Each year they make him a warm winter quilt from all the swatches of coloured fabric left over from making presents. The elves only like red and green, so your first job is to sort through the list of hex-colour swatches for the ones where the colours red or green are dominant. Last year's quilt just said 'SANTA ♥ ♡ ♥ ' but this year they're making a quilt with his favourite number on it.

Part 1

Import the data found in the patches.txt file below. Make it useful by removing the # 

You'll need to then convert these hex values into decimal RGB values and work out how many contain dominant red or dominant green values. Dominant means that their values are 50 or more than the other two values (50 in decimal).

Example:

FF0000 = 255, 0, 0 (full red, no green, no blue), so red is at least 50 more dominant than green and blue.

#683dBa
#EcFee3
#813533
#eD6dc7
#8084F0
#2EfDf1
#31C70a
#68F67D
#E681Dc
#e4Ef34


Cleaned and converted to decimal 0-255 (red, green, blue), the values look like this:

104 61 186
236 254 227
129 53 51
237 109 199
128 132 240
46 253 241
49 199 10
104 246 125
230 129 220
228 239 52


The list below shows the instances where red and green were the dominant colours:

104 61 186
236 254 227
129 53 51
237 109 199
128 132 240
46 253 241
49 199 10
104 246 125
230 129 220
228 239 52



All the other patches would be removed from the list, leaving just 3 patches for the quilt:

129 53 51
49 199 10
104 246 125

patches

Part Two

Now the Elves have determined which swatches are 'mostly green' and 'mostly red' they want to stitch them all together to make a giant winter duvet as a present for Santa.

Remember 'Bits'? Work out the correct width & height that turns the 'random' red & green swatches into a picture (of the password number). If your Python has access to the Turtle module, you can use that to 'draw' .color'ed pixels for each swatch, with .setpos(x,y)

Alternatively if you're working in an environment that can't do graphics, so not turtle module (eg command line, Google Colab* or similar), you can use the unicode characters for 'red square' 🟥 chr(int(1F7E9)) and 'green square' 🟩  chr(int('1F7E9', 16)).

*It turns out there IS a turtle drawing module for Google Colab: https://github.com/tolgaatam/ColabTurtle