projects
/
advent-of-code-16.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8c37e8b
)
Better implementation of ABBA finding, from Reddit
author
Neil Smith
<neil.git@njae.me.uk>
Thu, 8 Dec 2016 10:01:38 +0000
(10:01 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Thu, 8 Dec 2016 10:01:38 +0000
(10:01 +0000)
advent07.hs
patch
|
blob
|
history
diff --git
a/advent07.hs
b/advent07.hs
index 08bac0ef7bae515e02bfdbd17a6c449af2e105ce..a82177eed381220d0de75d9c513bef3615580bdc 100644
(file)
--- a/
advent07.hs
+++ b/
advent07.hs
@@
-38,12
+38,10
@@
part2 :: String -> IO ()
part2 text = do
print $ length $ filter (supportsSSL) $ successfulParse $ parseI7f text
part2 text = do
print $ length $ filter (supportsSSL) $ successfulParse $ parseI7f text
-
allowsAbba :: [ChunkV] -> Bool
allowsAbba chunks = (any (chunkValueV) includeChunks) && (not (any (chunkValueV) excludeChunks))
where (includeChunks, excludeChunks) = partition (isIncludeV) chunks
allowsAbba :: [ChunkV] -> Bool
allowsAbba chunks = (any (chunkValueV) includeChunks) && (not (any (chunkValueV) excludeChunks))
where (includeChunks, excludeChunks) = partition (isIncludeV) chunks
-
i7file = i7line `endBy` newline
i7line = many1 (includeChunk <|> excludeChunk)
i7file = i7line `endBy` newline
i7line = many1 (includeChunk <|> excludeChunk)
@@
-55,14
+53,21
@@
includeChunk = Include <$> chunk
hasABBA = preambleAbba <* (many alphaNum)
preambleAbba = (try abba) <|> (alphaNum >> preambleAbba)
hasABBA = preambleAbba <* (many alphaNum)
preambleAbba = (try abba) <|> (alphaNum >> preambleAbba)
+-- abba =
+-- do a <- alphaNum
+-- b <- alphaNum
+-- if a == b then
+-- fail "Identical"
+-- else do char b
+-- char a
+-- return [a, b, b, a]
+
abba =
do a <- alphaNum
abba =
do a <- alphaNum
- b <- alphaNum
- if a == b then
- fail "Identical"
- else do char b
- char a
- return [a, b, b, a]
+ b <- noneOf [a]
+ char b
+ char a
+ return [a, b, b, a]
i7filev = i7linev `endBy` newline
i7linev = many1 (includeChunkv <|> excludeChunkv)
i7filev = i7linev `endBy` newline
i7linev = many1 (includeChunkv <|> excludeChunkv)