Day 14 - condensed some stuff, it's fine
This commit is contained in:
parent
ade0446c62
commit
6a26332994
10
14.hs
10
14.hs
|
@ -2,7 +2,8 @@ import Data.List.Split (chunksOf)
|
||||||
import Data.Char (ord)
|
import Data.Char (ord)
|
||||||
import Data.Bits (xor)
|
import Data.Bits (xor)
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import Data.Graph (graphFromEdges, scc)
|
import Data.Graph (scc, graphFromEdges)
|
||||||
|
import Data.Tuple.Select (sel1, sel2)
|
||||||
import Data.Sequence (Seq, index, fromList)
|
import Data.Sequence (Seq, index, fromList)
|
||||||
|
|
||||||
type Length = Int
|
type Length = Int
|
||||||
|
@ -46,8 +47,5 @@ getEdges ind (str, edges) = if str ! ind == '0' then (str, edges) else
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let hashes = concat $ map (sparseHash . (++ [17, 31, 73, 47, 23]) . map ord . ("ffayrhll-" ++) . show) [0..127]
|
let hashes = concat $ map (sparseHash . (++ [17, 31, 73, 47, 23]) . map ord . ("ffayrhll-" ++) . show) [0..127]
|
||||||
used = length . filter (== '1') $ hashes
|
print $ length . filter (== '1') $ hashes
|
||||||
(_, edges) = foldr getEdges (fromList hashes, []) [0..128 * 128 - 1]
|
print $ length . scc . sel1 . graphFromEdges . sel2 $ foldr getEdges (fromList hashes, []) [0..128 * 128 - 1]
|
||||||
(graph, _, _) = graphFromEdges edges
|
|
||||||
print $ used
|
|
||||||
print $ length . scc $ graph
|
|
Loading…
Reference in New Issue