Color $27$ unit cube so that by rearranging, they could form a blue $3\times3$ cube, a green one, and a red one?
For the $3 \times 3 \times 3$ case it is possible:
Haskell code:
{-# LANGUAGE FlexibleContexts #-}
import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine (defaultMain)
v x = [x,x,x]
e x = [x,x]
f x = [x]
cubes =
[ v red ++ v green
, v green ++ v blue
, v blue ++ v red
]
++
concatMap (replicate 6)
[ v red ++ e green ++ f blue
, v green ++ e blue ++ f red
, v blue ++ e red ++ f green
]
++
replicate 6 ( e red ++ e green ++ e blue )
draw [a,b,c,d,e,f] = pad 1.1 . centerXY $
((strutX 1 ||| square 1 # fc a)
===
(square 1 # fc b ||| square 1 # fc c ||| square 1 # fc d ||| square 1 # fc e)
===
(strutX 3 ||| square 1 # fc f))
chunk _ [] = []
chunk n xs = let (ys, zs) = splitAt n xs in ys : chunk n zs
diagram = bg white . centerXY . vcat . map hcat . chunk 4 . map draw $ cubes
main = defaultMain diagram