Fixed with a complete hack (but it works)

This commit is contained in:
Martin Potier 2020-12-03 22:23:26 +02:00
parent fff23228a4
commit 4ed06fab49

View file

@ -77,7 +77,8 @@ solveDay3Part1 :: Grid -> (Int,Int) -> Int
solveDay3Part1 grid@(Grid lx) (x',y')= solveDay3Part1 grid@(Grid lx) (x',y')=
length $ filter (== SquareSortTree) $ map (getSquareSortAtPosition grid) px length $ filter (== SquareSortTree) $ map (getSquareSortAtPosition grid) px
where where
px = take n $ line x' y' px = take n' $ line x' y'
n' = if y' > 1 then n + 1 else n
n = (length lx) `div` y' n = (length lx) `div` y'
-- Determine the number of trees you would encounter if, for each of the -- Determine the number of trees you would encounter if, for each of the
@ -107,14 +108,14 @@ main = do
putStrLn "Day 3 - Part 1" putStrLn "Day 3 - Part 1"
inputData <- readFile "day3/input" inputData <- readFile "day3/input"
print $ take 5 $ line 3 1 print $ take 5 $ line 3 1
print $ take 5 $ line 7 1 print $ take 6 $ line 1 2
let (Just parsedTestData) = parseInput testData let (Just parsedTestData) = parseInput testData
print parsedTestData print parsedTestData
print $ getSquareSortAtPosition parsedTestData (Position 10 10) print $ getSquareSortAtPosition parsedTestData (Position 5 10)
let (Just parsedInputData) = parseInput (lines inputData) let (Just parsedInputData) = parseInput (lines inputData)
putStrLn "Part 1:" putStrLn "Part 1:"
print $ solveDay3Part1 parsedTestData (3,1) print $ solveDay3Part1 parsedTestData (3,1)
print $ solveDay3Part1 parsedInputData (3,1) print $ solveDay3Part1 parsedInputData (3,1)
putStrLn "Part 2:" putStrLn "Part 2:"
print $ solveDay3Part2 parsedTestData -- This gives the right answer, but print $ solveDay3Part2 parsedTestData
print $ solveDay3Part2 parsedInputData -- This gives the wrong answer :s print $ solveDay3Part2 parsedInputData