• + 0 comments

    Elixir solution:

    defmodule Solution do
        def colorize(input) do
            cp = String.codepoints(input)
            Enum.reduce(cp, {0,0,0,0}, fn x, {r,g,b,y} -> 
                case x do
                    "R" when abs(r+1-g) < 2 -> {r+1,g,b,y}
                    "G" when abs(g+1-r) < 2 -> {r,g+1,b,y}
                    "B" when abs(b+1-y) < 2 -> {r,g,b+1,y}
                    "Y" when abs(y+1-b) < 2 -> {r,g,b,y+1}
                    _ -> {False, False, False, False}
                end
            end)
            |> fn {r,g,b,y} -> case {r,g,b,y} do
                    {False, False, False, False} -> "False"
                    _ when r-g != 0 -> "False"
                    _ when y-b != 0 -> "False"
                    _ -> "True"
                end
            end.()
        end
    end
    
    input = IO.read(:stdio, :all)
      |> String.split("\n")
      
    [_ | elements] = input
    Enum.map(elements, fn x -> Solution.colorize(x) end)
    |> Enum.each(fn x -> IO.puts(x) end)