Sort by

recency

|

36 Discussions

|

  • + 0 comments

    This problem of balancing colors in sequences is quite fascinating, focusing on maintaining equality and controlled differences. This color scheme has greatly inspired my website creation by offering a structured approach to visually balance elements, similar to how the code manages color sequences.

  • + 0 comments

    UIUA well..

    a  = /+"G":/+"R".x
    b  = /+"Y":/+"B".x
    c  =0/+=0⊂≥¯1:1.\++¯⌕"G":"R".x
    d  =0/+=0⊂≥¯1:1.\++¯⌕"Y":"B".x
    Sol  ("False"|"True")=0/+0[a b c d]
    
  • + 0 comments

    f# solution

    open System
    
    let rec check r g y b =
        function
        | [] -> r = g && y = b
        | _ when (abs (r - g) > 1) -> false
        | _ when (abs (y - b) > 1) -> false
        | 'R' :: xs -> check (r + 1) g y b xs
        | 'G' :: xs -> check r (g + 1) y b xs
        | 'Y' :: xs -> check r g (y + 1) b xs
        | 'B' :: xs -> check r g y (b + 1) xs
    
    [<EntryPoint>]
    let main _ =
        let n = Console.ReadLine() |> int
    
        [ 1..n ]
        |> List.iter (fun _ ->
            Console.ReadLine()
            |> Seq.map char
            |> List.ofSeq
            |> check 0 0 0 0
            |> Console.WriteLine)
    
        0
    
  • + 0 comments

    haskell

    import Control.Monad (forM_)
    
    full r g b y "" = r == g && y == b
    full r g b y ('R':cs) = r <= g && full (r+1) g b y cs
    full r g b y ('G':cs) = r >= g && full r (g+1) b y cs
    full r g b y ('B':cs) = y >= b && full r g (b+1) y cs
    full r g b y ('Y':cs) = y <= b && full r g b (y+1) cs
    
    main = do
      ns <- getLine
      forM_ [1..(read ns)] $ \  _ -> do
        seq <- getLine
        print $ full 0 0 0 0 seq
    
  • + 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)