Haskell solution:
import Numeric (showIntAtBase) import Data.Char (intToDigit) clamp :: (Ord a) => a -> a -> a -> a clamp mi ma x = minimum [maximum [x, mi], ma] padStart :: Int -> a -> [a] -> [a] padStart l x = until ((>=l) . length) (x:) rgb2num :: (Int, Int, Int) -> Int rgb2num (r, g, b) = clampColor r * 65536 + clampColor g * 256 + clampColor b where clampColor = clamp 0 255 rgb2hex :: (Int, Int, Int) -> String rgb2hex n = padStart 6 '0' $ showIntAtBase 16 intToDigit (rgb2num n) ""
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell solution: