You are viewing a single comment's thread. Return to all comments →
Instead of keeping the dimensions and replacing ones at specific positions, I reduced the whole array to half size and then worked with it.
For example, consider a part of a triangle:
Remove all even positions (zero based), both row- and column-wise.
Put three copies of it at appropriate positions, padding with _.
If you apply the same function again, then you get the base triangle
and the final result
which is exactly part of what we want.
Implementation in Haskell. The core algorithm is inside iter.
main = do
n <- readLn :: IO Int
putStrLn $ unlines $ solve n
base = [[if r + c >= 33 && c - r <= 31 then '1' else '_' | c <- [1..63]] | r <- [1..32]]
dropEven s = map fst $ filter snd $ zip s $ cycle [False, True]
iter s = top ++ bot where
half = map dropEven $ dropEven s
padding = replicate 16 '_'
top = map (\x -> padding ++ x ++ padding) half
bot = map (\x -> x ++ "_" ++ x) half
solve n = (iterate iter base) !! n