AdventOfCode2018

Mes tentatives pour l'AdventOfCode2018 !!
Log | Files | Refs

commit 475f8ffafca1fb1aa7c0871f55c48adfbdde406e
parent b3ce22ce023a7c5cf768fe806d1f3f481347a839
Author: Doshirae <doshirae@doshirae.fr>
Date:   Sun,  2 Dec 2018 18:50:27 +0100

Day 02

Diffstat:
Jour2/day2.hs | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/Jour2/day2.hs b/Jour2/day2.hs @@ -30,8 +30,30 @@ part1 = mult . zipSum (0,0) . fmap processWord . lines -- }}} -- part2 {{{ -- Beaucoup trop dur omg, même avec le code de typochon et ses commentaires je comprends pas :/ + +check2 :: [Char] -> [Char] -> Bool +check2 (h1:t1) (h2:t2) = + if h1 == h2 + then check2 t1 t2 + else t2 == t1 +check2 [] [] = False + +cartProd xs ys = [(x,y) | x <- xs, y <- ys, x /= y] +cartSquare xs = cartProd xs xs + +filterDiffering :: [Char] -> ([Char], [Char]) -> [Char] +filterDiffering res (x:xs,y:ys) + | x == y = filterDiffering (res++[x]) (xs,ys) + | x /= y = filterDiffering res (xs,ys) +filterDiffering res ([],[]) = res + +filterDiff = filterDiffering "" + +part2 = head . fmap filterDiff . filter (uncurry check2) . cartSquare . lines + -- }}} main = do input <- readFile "input.txt" print $ part1 input + print $ part2 input