Skip to content

Instantly share code, notes, and snippets.

@gliush
Last active August 29, 2015 14:05
Show Gist options
  • Save gliush/e8241e5237f62244abf1 to your computer and use it in GitHub Desktop.
Save gliush/e8241e5237f62244abf1 to your computer and use it in GitHub Desktop.
aug fp content
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
011101100111011101010111011101110111011100111011001110111010101110111011101110111001110110011101110101011101110111011101110
010100100001000101010100010000010101010100101001000010001010101000100000101010101001010010000100010101010001000001010101010
010100100111011101110111011100110111011100101001001110111011101110111001101110111001010010011101110111011101110011011101110
010100100100000100010001010100100101000100101001001000001000100010101001001010001001010010010000010001000101010010010100010
011101110111011100010111011100100111011100111011101110111000101110111001001110111001110111011101110001011101110010011101110
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000
0111011001110111010101
0101001000010001010101
0101001001110111011101
0101001001000001000100
0111011101110111000101
0000000000000000000000
0111011001110111010101
0101001000010001010101
0101001001110111011101
0101001001000001000100
0111011101110111000101
000000000000
011101100111
010100100001
010100100111
010100100100
011101110111
import qualified Data.Array as Array
import Data.Char (digitToInt)
import Numeric (readInt)
import Data.IntMap.Strict (fromList, member, IntMap, (!))
import System.Environment (getArgs)
type Mindex = (Int, Int)
type Symbol = Int
type MData a = Array.Array (Int, Int) a
data Matrix a = Matrix { mResX :: Int, mResY :: Int, mData :: MData a } deriving Show
readMatrix :: String -> Matrix Int
readMatrix str = Matrix resX resY array
where
ls = lines str
resY = length ls - 1
resX = length (head ls) - 1
array = Array.array ((0,0),(resX,resY)) [ ((x,y), digitToInt (ls !! y !! x)) | x <- [0..resX], y <- [0..resY] ]
readMatrixFile :: FilePath -> IO (Matrix Int)
readMatrixFile name = do
str <- readFile name
return $ readMatrix str
symbolRaw :: Symbol -> String
symbolRaw 0 = "111\n101\n101\n101\n111"
symbolRaw 1 = "110\n010\n010\n010\n111"
symbolRaw 2 = "111\n001\n111\n100\n111"
symbolRaw 3 = "111\n001\n111\n001\n111"
symbolRaw 4 = "101\n101\n111\n001\n001"
symbolRaw 5 = "111\n100\n111\n001\n111"
symbolRaw 6 = "111\n100\n111\n101\n111"
symbolRaw 7 = "111\n001\n011\n010\n010"
symbolRaw 8 = "111\n101\n111\n101\n111"
symbolRaw 9 = "111\n101\n111\n001\n111"
symbolRaw _ = undefined
symbol :: Symbol -> Matrix Int
symbol = readMatrix . symbolRaw
symbolRepr :: Symbol -> Int
symbolRepr = readBin . reverse . filter (`elem` "01") . symbolRaw
readBin :: String -> Int
readBin = fst . head . readInt 2 (const True) digitToInt
symbols :: IntMap Symbol
symbols = fromList $ zip (map symbolRepr [0..9]) [0..9]
process :: Matrix Int -> [ (Mindex,Int) ]
process m1 = [ ((x,y), v x y) | y <- [0..newY], x <- [0..newX] ]
where
newX = mResX m1 - 2
newY = mResY m1 - 4
v x y = sum [ (mData m1 Array.! (x+i,y+j) ) * 2^(j*3+i) | j <- [0..4], i <- [0..2]]
scan :: Matrix Int -> [ (Mindex,Symbol) ]
scan m = foldr replaceElem [] elems
where
elems = process m
replaceElem (ix,s) acc | s `member` symbols = (ix,symbols ! s) :acc
replaceElem _ acc = acc
df i = (snd $ head $ process $ symbol i, symbolRepr i)
df1 = and $ map ((\(a,b) -> a == b) . df) [0..9]
main = do
args <- getArgs
m <- readMatrixFile (args !! 0)
mapM_ print $ scan m
((1,1),0)
((5,1),1)
((9,1),2)
((13,1),3)
((17,1),4)
((21,1),5)
((25,1),6)
((29,1),7)
((33,1),8)
((37,1),9)
((42,1),0)
((46,1),1)
((50,1),2)
((54,1),3)
((58,1),4)
((62,1),5)
((66,1),6)
((70,1),7)
((74,1),8)
((78,1),9)
((83,1),0)
((87,1),1)
((91,1),2)
((95,1),3)
((99,1),4)
((103,1),5)
((107,1),6)
((111,1),7)
((115,1),8)
((119,1),9)
((1,7),0)
((5,7),1)
((9,7),2)
((13,7),3)
((17,7),4)
((21,7),5)
((25,7),6)
((29,7),7)
((33,7),8)
((37,7),9)
((42,7),0)
((46,7),1)
((50,7),2)
((54,7),3)
((58,7),4)
((62,7),5)
((66,7),6)
((70,7),7)
((74,7),8)
((78,7),9)
((83,7),0)
((87,7),1)
((91,7),2)
((95,7),3)
((99,7),4)
((103,7),5)
((107,7),6)
((111,7),7)
((115,7),8)
((119,7),9)
((1,13),0)
((5,13),1)
((9,13),2)
((13,13),3)
((17,13),4)
((21,13),5)
((25,13),6)
((29,13),7)
((33,13),8)
((37,13),9)
((42,13),0)
((46,13),1)
((50,13),2)
((54,13),3)
((58,13),4)
((62,13),5)
((66,13),6)
((70,13),7)
((74,13),8)
((78,13),9)
((83,13),0)
((87,13),1)
((91,13),2)
((95,13),3)
((99,13),4)
((103,13),5)
((107,13),6)
((111,13),7)
((115,13),8)
((119,13),9)
((1,19),0)
((5,19),1)
((9,19),2)
((13,19),3)
((17,19),4)
((21,19),5)
((25,19),6)
((29,19),7)
((33,19),8)
((37,19),9)
((42,19),0)
((46,19),1)
((50,19),2)
((54,19),3)
((58,19),4)
((62,19),5)
((66,19),6)
((70,19),7)
((74,19),8)
((78,19),9)
((83,19),0)
((87,19),1)
((91,19),2)
((95,19),3)
((99,19),4)
((103,19),5)
((107,19),6)
((111,19),7)
((115,19),8)
((119,19),9)
((1,25),0)
((5,25),1)
((9,25),2)
((13,25),3)
((17,25),4)
((21,25),5)
((25,25),6)
((29,25),7)
((33,25),8)
((37,25),9)
((42,25),0)
((46,25),1)
((50,25),2)
((54,25),3)
((58,25),4)
((62,25),5)
((66,25),6)
((70,25),7)
((74,25),8)
((78,25),9)
((83,25),0)
((87,25),1)
((91,25),2)
((95,25),3)
((99,25),4)
((103,25),5)
((107,25),6)
((111,25),7)
((115,25),8)
((119,25),9)
((1,31),0)
((5,31),1)
((9,31),2)
((13,31),3)
((17,31),4)
((21,31),5)
((25,31),6)
((29,31),7)
((33,31),8)
((37,31),9)
((42,31),0)
((46,31),1)
((50,31),2)
((54,31),3)
((58,31),4)
((62,31),5)
((66,31),6)
((70,31),7)
((74,31),8)
((78,31),9)
((83,31),0)
((87,31),1)
((91,31),2)
((95,31),3)
((99,31),4)
((103,31),5)
((107,31),6)
((111,31),7)
((115,31),8)
((119,31),9)
((1,37),0)
((5,37),1)
((9,37),2)
((13,37),3)
((17,37),4)
((21,37),5)
((25,37),6)
((29,37),7)
((33,37),8)
((37,37),9)
((42,37),0)
((46,37),1)
((50,37),2)
((54,37),3)
((58,37),4)
((62,37),5)
((66,37),6)
((70,37),7)
((74,37),8)
((78,37),9)
((83,37),0)
((87,37),1)
((91,37),2)
((95,37),3)
((99,37),4)
((103,37),5)
((107,37),6)
((111,37),7)
((115,37),8)
((119,37),9)
((1,43),0)
((5,43),1)
((9,43),2)
((13,43),3)
((17,43),4)
((21,43),5)
((25,43),6)
((29,43),7)
((33,43),8)
((37,43),9)
((42,43),0)
((46,43),1)
((50,43),2)
((54,43),3)
((58,43),4)
((62,43),5)
((66,43),6)
((70,43),7)
((74,43),8)
((78,43),9)
((83,43),0)
((87,43),1)
((91,43),2)
((95,43),3)
((99,43),4)
((103,43),5)
((107,43),6)
((111,43),7)
((115,43),8)
((119,43),9)
((1,49),0)
((5,49),1)
((9,49),2)
((13,49),3)
((17,49),4)
((21,49),5)
((25,49),6)
((29,49),7)
((33,49),8)
((37,49),9)
((42,49),0)
((46,49),1)
((50,49),2)
((54,49),3)
((58,49),4)
((62,49),5)
((66,49),6)
((70,49),7)
((74,49),8)
((78,49),9)
((83,49),0)
((87,49),1)
((91,49),2)
((95,49),3)
((99,49),4)
((103,49),5)
((107,49),6)
((111,49),7)
((115,49),8)
((119,49),9)
((1,55),0)
((5,55),1)
((9,55),2)
((13,55),3)
((17,55),4)
((21,55),5)
((25,55),6)
((29,55),7)
((33,55),8)
((37,55),9)
((42,55),0)
((46,55),1)
((50,55),2)
((54,55),3)
((58,55),4)
((62,55),5)
((66,55),6)
((70,55),7)
((74,55),8)
((78,55),9)
((83,55),0)
((87,55),1)
((91,55),2)
((95,55),3)
((99,55),4)
((103,55),5)
((107,55),6)
((111,55),7)
((115,55),8)
((119,55),9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment