Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dec_to_bin :: Int -> [Int]
- dec_to_bin x |x > 256 || x < 1 = []
- |x == 0 = take 8 (repeat 0)
- |x == 255 = take 8 (repeat 1)
- |otherwise = dec_to_bin (div x 2) ++ [mod x 2]
- bin_to_unicode :: [Int] -> [Char]
- bin_to_unicode l |not head l = []
- |head l == 0 = [' '] ++ bin_to_unicode (tail l)
- |head l == 1 = ['█'] ++ bin_to_unicode (tail l)
- -- r rule, i input sequence, n number of iterations
- automaton :: Int -> [Int] -> Int -> [[Char]]
- automaton r i n |not head i || 255 < r || r < 0 = []
- |r == 0 = [take (len i) (repeat ' ')] ++ automaton r (take (len i) (repeat ' ')) (n - 1)
- |r == 255 = [take (len i) (repeat '█')] ++ automaton r (take (len i) (repeat '█')) (n - 1)
- |otherwise = [aux (dec_to_bin r) i] ++ automaton r (aux r i) (n - 1)
- aux :: [Int] -> [Int] -> [Char]
- aux r i |not head i = []
- |take 3 i == [1, 1, 1] = [head r] ++ aux r (drop 3 i)
- |take 3 i == [1, 1, 0] = (r !! 1) ++ aux r (drop 3 i)
- |take 3 i == [1, 0, 1] = (r !! 2) ++ aux r (drop 3 i)
- |take 3 i == [1, 0, 0] = (r !! 3) ++ aux r (drop 3 i)
- |take 3 i == [0, 1, 1] = (r !! 4) ++ aux r (drop 3 i)
- |take 3 i == [0, 1, 0] = (r !! 5) ++ aux r (drop 3 i)
- |take 3 i == [0, 0, 1] = (r !! 6) ++ aux r (drop 3 i)
- |take 3 i == [0, 0, 0] = [tail r] ++ aux r (drop 3 i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement