Reorganizing files into folders
This commit is contained in:
parent
a0df5a759c
commit
6b1960cb97
|
@ -1,6 +0,0 @@
|
|||
*
|
||||
!.gitignore
|
||||
!*.hs
|
||||
!*.c
|
||||
!*.js
|
||||
!*.txt
|
|
@ -2,9 +2,9 @@
|
|||
Hopefully most of these solutions are fairly self-explanatory. I'll write longer-length explanations for more complex questions.
|
||||
|
||||
## Posts
|
||||
[Day 3: Spiral Memory](https://medium.com/@nonphatic/advent-of-code-day-3-30db5599e914) ([problem description](http://adventofcode.com/2017/day/3))
|
||||
[Day 3: Spiral Memory](https://ionathan.ch/2017/12/04/advent-of-code-2017-day-3) ([problem description](http://adventofcode.com/2017/day/3))
|
||||
|
||||
[Day 23: Coprocessor Conflagration](https://medium.com/@nonphatic/advent-of-code-2017-day-23-a29ee2d4bab8) ([problem description](http://adventofcode.com/2017/day/23))
|
||||
[Day 23: Coprocessor Conflagration](https://ionathan.ch/2017/12/25/advent-of-code-2017-day-23) ([problem description](http://adventofcode.com/2017/day/23))
|
||||
|
||||
## Runtimes
|
||||
These are the runtimes of only one trial but the variances are fairly small and the focus is on the differences in runtime among the different solutions to see which have comparatively worse performance.
|
||||
|
|
|
@ -8,6 +8,6 @@ halfwaySum ns =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
nums <- map (read . pure) <$> readFile "01.txt"
|
||||
nums <- map (read . pure) <$> readFile "../input/01.txt"
|
||||
print $ circularSum nums
|
||||
print $ halfwaySum nums
|
|
@ -10,6 +10,6 @@ divline ns =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
grid <- map (map read . words) . lines <$> readFile "02.txt"
|
||||
grid <- map (map read . words) . lines <$> readFile "../input/02.txt"
|
||||
print $ sum . map (\line -> maximum line - minimum line) $ grid
|
||||
print $ sum . map divline $ grid
|
|
@ -6,7 +6,7 @@ isPassphraseValid ws = sort ws == (toAscList . fromList) ws
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
passphrases <- map words . lines <$> readFile "04.txt"
|
||||
passphrases <- map words . lines <$> readFile "../input/04.txt"
|
||||
let valids = sum $ map (fromEnum . isPassphraseValid) passphrases
|
||||
let stillValids = sum $ map (fromEnum . isPassphraseValid . (map sort)) passphrases
|
||||
print $ valids
|
|
@ -15,7 +15,7 @@ getExitSteps len f state@(!steps, i, _) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
jumpsList <- map read . lines <$> readFile "05.txt"
|
||||
jumpsList <- map read . lines <$> readFile "../input/05.txt"
|
||||
let jumpsMap = fromList $ zip [0..] jumpsList
|
||||
print $ getExitSteps (length jumpsList) (+1) (0, 0, jumpsMap)
|
||||
print $ getExitSteps (length jumpsList) (\v -> if v >= 3 then v - 1 else v + 1) (0, 0, jumpsMap)
|
|
@ -15,6 +15,6 @@ getExitSteps f (steps, i, jumps) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
jumpsList <- fmap (fromList . map read . lines) $ readFile "5.txt"
|
||||
jumpsList <- fmap (fromList . map read . lines) $ readFile "../input/5.txt"
|
||||
print $ getExitSteps (+1) (0, 0, jumpsList)
|
||||
print $ getExitSteps (\v -> if v >= 3 then v - 1 else v + 1) (0, 0, jumpsList)
|
|
@ -33,5 +33,5 @@ cycles prevCount (prevBank, banks) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
bank <- fromList . map read . words <$> readFile "06.txt"
|
||||
bank <- fromList . map read . words <$> readFile "../input/06.txt"
|
||||
print $ cycles 0 (bank, empty)
|
|
@ -64,7 +64,7 @@ findBalanced (Node _ forest) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
programsList <- map parseLine . lines <$> readFile "07.txt"
|
||||
programsList <- map parseLine . lines <$> readFile "../input/07.txt"
|
||||
let programsMap = fromList programsList
|
||||
bottomName = getBottom programsMap programsList
|
||||
balanced = findBalanced . cumulate $ mapToTree programsMap bottomName
|
|
@ -38,6 +38,6 @@ executeInstruction m (I r v s f) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
maxima <- map (maximum . elems) . tail . scanl executeInstruction empty . map parseLine . lines <$> readFile "08.txt"
|
||||
maxima <- map (maximum . elems) . tail . scanl executeInstruction empty . map parseLine . lines <$> readFile "../input/08.txt"
|
||||
print $ last maxima
|
||||
print $ maximum maxima
|
|
@ -12,4 +12,4 @@ scoreAndCount str =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
readFile "09.txt" >>= print . scoreAndCount
|
||||
readFile "../input/09.txt" >>= print . scoreAndCount
|
|
@ -20,7 +20,7 @@ hash lengths state = foldl twist state lengths
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- readFile "10.txt"
|
||||
input <- readFile "../input/10.txt"
|
||||
let lengths = map read $ splitOn "," input
|
||||
newLengths = map ord input ++ [17, 31, 73, 47, 23]
|
||||
(hashed, _, _) = hash lengths ([0..255], 0, 0)
|
|
@ -23,6 +23,6 @@ getDistance (Coordinates x y z) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
coordinates <- map getCoordinates . splitOn "," <$> readFile "11.txt"
|
||||
coordinates <- map getCoordinates . splitOn "," <$> readFile "../input/11.txt"
|
||||
print $ getDistance $ fold coordinates
|
||||
print $ maximum . map getDistance . scanl mappend mempty $ coordinates
|
|
@ -9,6 +9,6 @@ parseLine str =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
graph <- array (0, 1999) . map parseLine . lines <$> readFile "12.txt"
|
||||
graph <- array (0, 1999) . map parseLine . lines <$> readFile "../input/12.txt"
|
||||
print $ length $ reachable graph 0
|
||||
print $ length $ scc graph
|
|
@ -24,6 +24,6 @@ anyCaught firewalls delay =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
firewalls <- map parseLine . lines <$> readFile "13.txt"
|
||||
firewalls <- map parseLine . lines <$> readFile "../input/13.txt"
|
||||
print $ severity firewalls
|
||||
print $ findIndex not $ map (anyCaught firewalls) [0..]
|
|
@ -42,7 +42,7 @@ applyDance (s, positions, swaps) str =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
moves <- map parseMove . splitOn "," <$> readFile "16.txt"
|
||||
moves <- map parseMove . splitOn "," <$> readFile "../input/16.txt"
|
||||
let ip = [0..15]; ap = ['a'..'p']
|
||||
state = dance moves (0, fromList $ zip ip ip, fromList $ zip ap ap)
|
||||
dances = iterate (applyDance state) ap
|
|
@ -66,6 +66,6 @@ recover instructions (reg, pos, freq, rec) =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "18.txt"
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "../input/18.txt"
|
||||
let initialState = (V.replicate 5 0, 0, 0, 0)
|
||||
print $ recover instructions initialState
|
|
@ -123,6 +123,6 @@ getCount instructions state =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "18.txt"
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "../input/18.txt"
|
||||
let initialState = (State (Program (V.replicate 5 0) 0 empty) (Program (V.replicate 5 0 // [(4, 1)]) 0 empty) (False, False) 0)
|
||||
print $ getCount instructions initialState
|
|
@ -28,7 +28,7 @@ traverseGrid letters grid state = traverseGrid letters grid $ nextState letters
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- readFile "19.txt"
|
||||
input <- readFile "../input/19.txt"
|
||||
let rows = lines input
|
||||
Just start = (+1) <$> (elemIndex '|' $ head rows)
|
||||
letters = filter (not . (`elem` " +|-\n")) input
|
|
@ -48,7 +48,7 @@ parseLine str =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
particles <- map parseLine . lines <$> readFile "20.txt"
|
||||
particles <- map parseLine . lines <$> readFile "../input/20.txt"
|
||||
let distances = map (norm . position . updateParticle 400) particles
|
||||
print $ elemIndex (minimum distances) distances
|
||||
print $ length $ iterate stepParticles particles !! 40
|
|
@ -55,7 +55,7 @@ parseLine line =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
rules <- foldr parseLine empty . lines <$> readFile "21.txt"
|
||||
rules <- foldr parseLine empty . lines <$> readFile "../input/21.txt"
|
||||
let iterations = map (length . filter (=='#')) $ iterate (enhance rules) ".#...####"
|
||||
print $ iterations !! 5
|
||||
print $ iterations !! 18
|
|
@ -30,6 +30,6 @@ parseRow (y, xs) grid = foldr (\(x, c) currGrid -> insert (x, y) c currGrid) gri
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
grid <- foldr parseRow empty . zip [-12..12] . map (zip [-12..12]) . lines <$> readFile "22.txt"
|
||||
grid <- foldr parseRow empty . zip [-12..12] . map (zip [-12..12]) . lines <$> readFile "../input/22.txt"
|
||||
let (_, _, _, count) = iterate nextState (grid, (0, 0), North, 0) !! 10000
|
||||
print $ count
|
|
@ -38,5 +38,5 @@ parseRow (y, xs) grid = foldr (\(x, c) currGrid -> insert (x, y) (charToEnum c)
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
grid <- foldr parseRow empty . zip [-12..12] . map (zip [-12..12]) . lines <$> readFile "22.txt"
|
||||
grid <- foldr parseRow empty . zip [-12..12] . map (zip [-12..12]) . lines <$> readFile "../input/22.txt"
|
||||
print $ stricterate 10000000 (grid, (0, 0), North, 0)
|
|
@ -65,6 +65,6 @@ count =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "23.txt"
|
||||
instructions <- fromList . map parseLine . lines <$> readFile "../input/23.txt"
|
||||
print $ runInstructions instructions (State (V.replicate 8 0) 0 0)
|
||||
print $ count
|
|
@ -28,6 +28,6 @@ estBridge est port components =
|
|||
|
||||
main :: IO ()
|
||||
main = do
|
||||
components <- fromList . map (\line -> let a : b : [] = splitOn "/" line in (read a, read b)) . lines <$> readFile "24.txt"
|
||||
components <- fromList . map (\line -> let a : b : [] = splitOn "/" line in (read a, read b)) . lines <$> readFile "../input/24.txt"
|
||||
print $ bridgeStrength $ estBridge strongest 0 components
|
||||
print $ bridgeStrength $ estBridge longest 0 components
|
Loading…
Reference in New Issue