finish seven
This commit is contained in:
parent
09cab9fc54
commit
da4ae2a835
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
!*.hs
|
.stack-work/
|
||||||
|
*~
|
30
LICENSE
Normal file
30
LICENSE
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
Copyright Author name here (c) 2022
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following
|
||||||
|
disclaimer in the documentation and/or other materials provided
|
||||||
|
with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of Author name here nor the names of other
|
||||||
|
contributors may be used to endorse or promote products derived
|
||||||
|
from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
48
advent-of-code-stack.cabal
Normal file
48
advent-of-code-stack.cabal
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
cabal-version: 1.12
|
||||||
|
|
||||||
|
-- This file has been generated from package.yaml by hpack version 0.35.0.
|
||||||
|
--
|
||||||
|
-- see: https://github.com/sol/hpack
|
||||||
|
|
||||||
|
name: advent-of-code-stack
|
||||||
|
version: 0.1.0.0
|
||||||
|
description: Please see the README on GitHub at <https://github.com/githubuser/advent-of-code-stack#readme>
|
||||||
|
homepage: https://github.com/githubuser/advent-of-code-stack#readme
|
||||||
|
bug-reports: https://github.com/githubuser/advent-of-code-stack/issues
|
||||||
|
author: Author name here
|
||||||
|
maintainer: example@example.com
|
||||||
|
copyright: 2022 Author name here
|
||||||
|
license: BSD3
|
||||||
|
license-file: LICENSE
|
||||||
|
build-type: Simple
|
||||||
|
extra-source-files:
|
||||||
|
README.md
|
||||||
|
CHANGELOG.md
|
||||||
|
|
||||||
|
source-repository head
|
||||||
|
type: git
|
||||||
|
location: https://github.com/githubuser/advent-of-code-stack
|
||||||
|
|
||||||
|
executable advent-of-code-stack-exe
|
||||||
|
main-is: one.hs
|
||||||
|
other-modules:
|
||||||
|
Main
|
||||||
|
Paths_advent_of_code_stack
|
||||||
|
hs-source-dirs:
|
||||||
|
app
|
||||||
|
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
build-depends:
|
||||||
|
base >=4.7 && <5
|
||||||
|
default-language: Haskell2010
|
||||||
|
|
||||||
|
executable seven
|
||||||
|
main-is: seven.hs
|
||||||
|
other-modules:
|
||||||
|
Main
|
||||||
|
Paths_advent_of_code_stack
|
||||||
|
hs-source-dirs:
|
||||||
|
app
|
||||||
|
ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
|
||||||
|
build-depends:
|
||||||
|
base >=4.7 && <5
|
||||||
|
default-language: Haskell2010
|
|
@ -1,35 +0,0 @@
|
||||||
cabal-version: 2.4
|
|
||||||
name: advent-of-code
|
|
||||||
version: 0.1.0.0
|
|
||||||
|
|
||||||
-- A short (one-line) description of the package.
|
|
||||||
-- synopsis:
|
|
||||||
|
|
||||||
-- A longer description of the package.
|
|
||||||
-- description:
|
|
||||||
|
|
||||||
-- A URL where users can report bugs.
|
|
||||||
-- bug-reports:
|
|
||||||
|
|
||||||
-- The license under which the package is released.
|
|
||||||
-- license:
|
|
||||||
author: qvalentin
|
|
||||||
maintainer: valentin.theodor@web.de
|
|
||||||
|
|
||||||
-- A copyright notice.
|
|
||||||
-- copyright:
|
|
||||||
-- category:
|
|
||||||
extra-source-files: CHANGELOG.md
|
|
||||||
|
|
||||||
executable one
|
|
||||||
main-is: one.hs
|
|
||||||
|
|
||||||
-- Modules included in this executable, other than Main.
|
|
||||||
-- other-modules:
|
|
||||||
|
|
||||||
-- LANGUAGE extensions used by modules in this package.
|
|
||||||
-- other-extensions:
|
|
||||||
build-depends: base ^>=4.14.3.0
|
|
||||||
hs-source-dirs: app
|
|
||||||
default-language: Haskell2010
|
|
||||||
ghc-options: -dynamic -O2
|
|
40
app/seven.hs
40
app/seven.hs
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
||||||
data FS = FS [Inode]
|
|
||||||
data Inode = Dir Name [Inode] | File Name Size deriving(Show)
|
data Inode = Dir Name [Inode] | File Name Size deriving(Show)
|
||||||
type Name = String
|
type Name = String
|
||||||
type Size = Int
|
type Size = Int
|
||||||
|
@ -63,23 +62,42 @@ data InodeSize = DirS Size | FileS Size deriving(Show)
|
||||||
getSize (DirS s )=s
|
getSize (DirS s )=s
|
||||||
getSize (FileS s)=s
|
getSize (FileS s)=s
|
||||||
|
|
||||||
flattenToSmallDirs :: Inode -> [InodeSize]
|
flattenToSmallDirs :: Inode -> (InodeSize,[InodeSize])
|
||||||
flattenToSmallDirs (Dir _ children) =
|
flattenToSmallDirs (Dir _ children) =
|
||||||
let childSizes =join $ map flattenToSmallDirs children
|
let childSizes =map flattenToSmallDirs children
|
||||||
currentSize=(sum $ map getSize $ childSizes) in
|
currentSize =(sum $ map getSize $ map fst childSizes) in
|
||||||
(DirS currentSize):(filter isDir childSizes )
|
(DirS currentSize ,filter isDir $ join $ map combineOwnWithChildSize childSizes )
|
||||||
flattenToSmallDirs (File _ size) = [FileS size]
|
flattenToSmallDirs (File _ size) = (FileS size,[])
|
||||||
|
|
||||||
|
combineOwnWithChildSize :: (InodeSize,[InodeSize]) -> [InodeSize]
|
||||||
|
combineOwnWithChildSize (own,children) = own:children
|
||||||
|
|
||||||
filterSmallDirs :: [InodeSize] -> [Size]
|
filterSmallDirs :: [InodeSize] -> [Size]
|
||||||
filterSmallDirs ((DirS s):rest) = if (s<100000) then s:(filterSmallDirs rest) else filterSmallDirs rest
|
filterSmallDirs ((DirS s):rest) = if (s<100000) then s:(filterSmallDirs rest) else filterSmallDirs rest
|
||||||
filterSmallDirs ((FileS s):rest) = filterSmallDirs rest
|
filterSmallDirs ((FileS _):rest) = filterSmallDirs rest
|
||||||
filterSmallDirs [] = []
|
filterSmallDirs [] = []
|
||||||
|
|
||||||
isDir (DirS s)=True
|
isDir :: InodeSize -> Bool
|
||||||
isDir (FileS s)=False
|
isDir (DirS _)= True
|
||||||
|
isDir (FileS _)=False
|
||||||
|
|
||||||
main = do
|
mainP1 :: IO ()
|
||||||
|
mainP1 = do
|
||||||
content <- readFile "seven-input.txt"
|
content <- readFile "seven-input.txt"
|
||||||
let statements = map parseEither $ drop 1 $ lines content
|
let statements = map parseEither $ drop 1 $ lines content
|
||||||
let a = foldl foldFunction initZipper statements
|
let a = foldl foldFunction initZipper statements
|
||||||
print $ sum $ filterSmallDirs $ flattenToSmallDirs $ fst $ fsUpToRoot a
|
print $ sum $ filterSmallDirs $ combineOwnWithChildSize $ flattenToSmallDirs $ fst $ fsUpToRoot a
|
||||||
|
|
||||||
|
|
||||||
|
mainP2::IO ()
|
||||||
|
mainP2 = do
|
||||||
|
content <- readFile "seven-input.txt"
|
||||||
|
let statements = map parseEither $ drop 1 $ lines content
|
||||||
|
a = foldl foldFunction initZipper statements
|
||||||
|
(rootSize, dirSizes) =flattenToSmallDirs $ fst $ fsUpToRoot a
|
||||||
|
currentlyFree=(70000000- getSize rootSize)
|
||||||
|
requiredCleanup = 30000000-currentlyFree
|
||||||
|
largeEnoughDirs = filter (\s -> s >= requiredCleanup) $ map getSize dirSizes
|
||||||
|
print $ minimum largeEnoughDirs
|
||||||
|
|
||||||
|
main = mainP2
|
||||||
|
|
31
four-easy.hs
31
four-easy.hs
|
@ -1,31 +0,0 @@
|
||||||
import Control.Monad
|
|
||||||
import Data.Char
|
|
||||||
|
|
||||||
parseLine :: String -> [[Int]]
|
|
||||||
parseLine line = [parseAssignment $ takeWhile (/= ',') line,
|
|
||||||
parseAssignment $ drop 1 $ dropWhile (',' /= ) line]
|
|
||||||
|
|
||||||
parseAssignment :: String -> [Int]
|
|
||||||
parseAssignment assignment = do
|
|
||||||
let first = takeWhile ('-' /=) assignment
|
|
||||||
let second = drop 1 $ dropWhile ('-' /=) assignment
|
|
||||||
[(read first).. (read second)]
|
|
||||||
|
|
||||||
isIncludedElseWhere :: [[Int]] -> [Int] -> [[Int]] -> Int -> Int
|
|
||||||
isIncludedElseWhere previous current [] count=count
|
|
||||||
isIncludedElseWhere previous current next count=do
|
|
||||||
let found = (isIncluded current previous && isIncluded current next)
|
|
||||||
(if found then 1 else 0) +
|
|
||||||
(isIncludedElseWhere (current:previous) (head next) (tail next) count)
|
|
||||||
|
|
||||||
isIncluded :: [Int] -> [[Int]] -> Bool
|
|
||||||
isIncluded current list = any includes list
|
|
||||||
where
|
|
||||||
includes :: [Int] -> Bool
|
|
||||||
includes range' = all (`elem` range') current
|
|
||||||
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "four-input2.txt"
|
|
||||||
let lists= ( join $ map (parseLine) $ lines input)
|
|
||||||
print $ isIncludedElseWhere [] (head lists) (tail lists) 0
|
|
1000
four-input.txt
Normal file
1000
four-input.txt
Normal file
File diff suppressed because it is too large
Load diff
6
four-input2.txt
Normal file
6
four-input2.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
2-4,6-8
|
||||||
|
2-3,4-5
|
||||||
|
5-7,7-9
|
||||||
|
2-8,3-7
|
||||||
|
6-6,4-6
|
||||||
|
2-6,4-8
|
28
four.hs
28
four.hs
|
@ -1,28 +0,0 @@
|
||||||
import Control.Monad
|
|
||||||
import Data.Char
|
|
||||||
|
|
||||||
parseLine :: String -> [[Int]]
|
|
||||||
parseLine line = [parseAssignment $ takeWhile (/= ',') line,
|
|
||||||
parseAssignment $ drop 1 $ dropWhile (',' /= ) line]
|
|
||||||
|
|
||||||
parseAssignment :: String -> [Int]
|
|
||||||
parseAssignment assignment = do
|
|
||||||
let first = takeWhile ('-' /=) assignment
|
|
||||||
let second = drop 1 $ dropWhile ('-' /=) assignment
|
|
||||||
[(read first).. (read second)]
|
|
||||||
|
|
||||||
|
|
||||||
isIncluded :: [Int] -> [[Int]] -> Bool
|
|
||||||
isIncluded current list = any includes list
|
|
||||||
where
|
|
||||||
includes :: [Int] -> Bool
|
|
||||||
includes range' = all (`elem` range') current
|
|
||||||
|
|
||||||
coveredByPartner :: [[Int]] -> Bool
|
|
||||||
coveredByPartner [first,second] = isIncluded first [second] || isIncluded second [first]
|
|
||||||
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "four-input.txt"
|
|
||||||
let lists= (map (parseLine) $ lines input)
|
|
||||||
print $ length $ filter id $ map coveredByPartner lists
|
|
25
four2.hs
25
four2.hs
|
@ -1,25 +0,0 @@
|
||||||
import Control.Monad
|
|
||||||
import Data.Char
|
|
||||||
import Data.List
|
|
||||||
|
|
||||||
parseLine :: String -> [[Int]]
|
|
||||||
parseLine line = [parseAssignment $ takeWhile (/= ',') line,
|
|
||||||
parseAssignment $ drop 1 $ dropWhile (',' /= ) line]
|
|
||||||
|
|
||||||
parseAssignment :: String -> [Int]
|
|
||||||
parseAssignment assignment = do
|
|
||||||
let first = takeWhile ('-' /=) assignment
|
|
||||||
let second = drop 1 $ dropWhile ('-' /=) assignment
|
|
||||||
[(read first).. (read second)]
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
coveredByPartner :: [[Int]] -> Bool
|
|
||||||
coveredByPartner [first,second] = 0 /= (length $ intersect first second)
|
|
||||||
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "four-input.txt"
|
|
||||||
let lists= (map (parseLine) $ lines input)
|
|
||||||
print $ length $ filter id $ map coveredByPartner lists
|
|
3
input2.txt
Normal file
3
input2.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
A Y
|
||||||
|
B X
|
||||||
|
C Z
|
14
one.hs
14
one.hs
|
@ -1,14 +0,0 @@
|
||||||
import Text.Read
|
|
||||||
f :: (Int,Int) -> Maybe Int -> (Int,Int)
|
|
||||||
f (max,current) (Just next) = (max,current+next)
|
|
||||||
f (currentMax,current) (Nothing) = (max currentMax current ,0)
|
|
||||||
|
|
||||||
|
|
||||||
result=fst $ foldl f (0,0) (map (readMaybe) $lines "1000\n2000\n3000\n\n4000\n1000\n\n1000")
|
|
||||||
compute input=fst $ foldl f (0,0) $ map (readMaybe) $lines input
|
|
||||||
|
|
||||||
|
|
||||||
main = do
|
|
||||||
content <- readFile "elves.txt"
|
|
||||||
putStrLn $ show $compute content
|
|
||||||
|
|
12
one2.hs
12
one2.hs
|
@ -1,12 +0,0 @@
|
||||||
import Text.Read
|
|
||||||
import Data.List
|
|
||||||
f :: ([Int],Int) -> Maybe Int -> ([Int],Int)
|
|
||||||
f (max,current) (Just next) = (max,current+next)
|
|
||||||
f (currentMax,current) (Nothing) = (take 3 $ reverse $ sort (current:currentMax) ,0)
|
|
||||||
|
|
||||||
compute input=sum $fst $ foldl f ([0],0) $ map (readMaybe) $lines input
|
|
||||||
|
|
||||||
main = do
|
|
||||||
content <- readFile "elves.txt"
|
|
||||||
putStrLn $ show $compute content
|
|
||||||
|
|
50
package.yaml
Normal file
50
package.yaml
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
name: advent-of-code-stack
|
||||||
|
version: 0.1.0.0
|
||||||
|
github: "githubuser/advent-of-code-stack"
|
||||||
|
license: BSD3
|
||||||
|
author: "Author name here"
|
||||||
|
maintainer: "example@example.com"
|
||||||
|
copyright: "2022 Author name here"
|
||||||
|
|
||||||
|
extra-source-files:
|
||||||
|
- README.md
|
||||||
|
- CHANGELOG.md
|
||||||
|
|
||||||
|
# Metadata used when publishing your package
|
||||||
|
# synopsis: Short description of your package
|
||||||
|
# category: Web
|
||||||
|
|
||||||
|
# To avoid duplicated efforts in documentation and dealing with the
|
||||||
|
# complications of embedding Haddock markup inside cabal files, it is
|
||||||
|
# common to point users to the README.md file.
|
||||||
|
description: Please see the README on GitHub at <https://github.com/githubuser/advent-of-code-stack#readme>
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- base >= 4.7 && < 5
|
||||||
|
|
||||||
|
ghc-options:
|
||||||
|
- -Wall
|
||||||
|
- -Wcompat
|
||||||
|
- -Widentities
|
||||||
|
- -Wincomplete-record-updates
|
||||||
|
- -Wincomplete-uni-patterns
|
||||||
|
- -Wmissing-export-lists
|
||||||
|
- -Wmissing-home-modules
|
||||||
|
- -Wpartial-fields
|
||||||
|
- -Wredundant-constraints
|
||||||
|
|
||||||
|
executables:
|
||||||
|
advent-of-code-stack-exe:
|
||||||
|
main: one.hs
|
||||||
|
source-dirs: app
|
||||||
|
ghc-options:
|
||||||
|
- -threaded
|
||||||
|
- -rtsopts
|
||||||
|
- -with-rtsopts=-N
|
||||||
|
seven:
|
||||||
|
main: seven.hs
|
||||||
|
source-dirs: app
|
||||||
|
ghc-options:
|
||||||
|
- -threaded
|
||||||
|
- -rtsopts
|
||||||
|
- -with-rtsopts=-N
|
23
seven-input-test.txt
Normal file
23
seven-input-test.txt
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
$ cd /
|
||||||
|
$ ls
|
||||||
|
dir a
|
||||||
|
14848514 b.txt
|
||||||
|
8504156 c.dat
|
||||||
|
dir d
|
||||||
|
$ cd a
|
||||||
|
$ ls
|
||||||
|
dir e
|
||||||
|
29116 f
|
||||||
|
2557 g
|
||||||
|
62596 h.lst
|
||||||
|
$ cd e
|
||||||
|
$ ls
|
||||||
|
584 i
|
||||||
|
$ cd ..
|
||||||
|
$ cd ..
|
||||||
|
$ cd d
|
||||||
|
$ ls
|
||||||
|
4060174 j
|
||||||
|
8033020 d.log
|
||||||
|
5626152 d.ext
|
||||||
|
7214296 k
|
1041
seven-input.txt
1041
seven-input.txt
File diff suppressed because it is too large
Load diff
1032
seven-input.txtreal
1032
seven-input.txtreal
File diff suppressed because it is too large
Load diff
84
seven.hs
84
seven.hs
|
@ -1,84 +0,0 @@
|
||||||
-- everything stolen from http://learnyouahaskell.com/zippers#a-very-simple-file-system
|
|
||||||
|
|
||||||
import Control.Monad
|
|
||||||
|
|
||||||
data FS = FS [Inode]
|
|
||||||
data Inode = Dir Name [Inode] | File Name Size deriving(Show)
|
|
||||||
type Name = String
|
|
||||||
type Size = Int
|
|
||||||
data Command = Ls | Cd Name | CdUp | CdRoot deriving(Show)
|
|
||||||
data Line = LineC Command | LineI Inode deriving(Show)
|
|
||||||
|
|
||||||
parseCommand :: String -> Command
|
|
||||||
parseCommand "ls" =Ls
|
|
||||||
parseCommand "cd .." =CdUp
|
|
||||||
parseCommand ('c':'d':' ':name) =(Cd name)
|
|
||||||
|
|
||||||
parseInode :: String -> Inode
|
|
||||||
parseInode ('d':'i':'r':' ': name) = Dir name []
|
|
||||||
parseInode input = File (drop 1 $ dropWhile (/= ' ') input) (read $ takeWhile (/= ' ') input)
|
|
||||||
|
|
||||||
|
|
||||||
parseEither :: String -> Line
|
|
||||||
parseEither ('$':' ':command) =LineC $ parseCommand command
|
|
||||||
parseEither input= LineI $ parseInode input
|
|
||||||
|
|
||||||
foldFunction :: FSZipper -> Line -> FSZipper
|
|
||||||
foldFunction zipper (LineC Ls) = zipper
|
|
||||||
foldFunction zipper (LineC (Cd name)) = fsTo name zipper
|
|
||||||
foldFunction zipper (LineC CdUp) = fsUp zipper
|
|
||||||
foldFunction zipper (LineI inode) = fsNewInode inode zipper
|
|
||||||
|
|
||||||
data FSCrumb = FSCrumb Name [Inode] [Inode] deriving (Show)
|
|
||||||
|
|
||||||
type FSZipper = (Inode,[FSCrumb])
|
|
||||||
|
|
||||||
fsUp :: FSZipper -> FSZipper
|
|
||||||
fsUp (item, FSCrumb name ls rs:bs) = (Dir name (ls ++ [item] ++ rs), bs)
|
|
||||||
|
|
||||||
|
|
||||||
fsUpToRoot :: FSZipper -> FSZipper
|
|
||||||
fsUpToRoot ((Dir "/" content),bc) = ((Dir "/" content),bc)
|
|
||||||
fsUpToRoot zipper = fsUp zipper
|
|
||||||
|
|
||||||
fsTo :: Name -> FSZipper -> FSZipper
|
|
||||||
fsTo name (Dir folderName items, bs) =
|
|
||||||
let (ls, item:rs) = break (nameIs name) items
|
|
||||||
in (item, FSCrumb folderName ls rs:bs)
|
|
||||||
|
|
||||||
nameIs :: Name -> Inode -> Bool
|
|
||||||
nameIs name (Dir folderName _) = name == folderName
|
|
||||||
nameIs name (File fileName _) = name == fileName
|
|
||||||
|
|
||||||
|
|
||||||
fsNewInode :: Inode -> FSZipper -> FSZipper
|
|
||||||
fsNewInode newInode ((Dir name content),bc) = (Dir name (newInode:content),bc)
|
|
||||||
|
|
||||||
initZipper :: FSZipper
|
|
||||||
initZipper = (Dir "/" [],[])
|
|
||||||
|
|
||||||
|
|
||||||
data InodeSize = DirS Size | FileS Size deriving(Show)
|
|
||||||
|
|
||||||
getSize (DirS s)= s
|
|
||||||
getSize (FileS s)=s
|
|
||||||
|
|
||||||
flattenToSmallDirs :: Inode -> [InodeSize]
|
|
||||||
flattenToSmallDirs (Dir _ children) =
|
|
||||||
let childSizes =join $ map flattenToSmallDirs children
|
|
||||||
currentSize=(sum $ map getSize $ childSizes) in
|
|
||||||
if (10 < 100000) then (DirS currentSize):childSizes else childSizes
|
|
||||||
flattenToSmallDirs (File _ size) = [FileS size]
|
|
||||||
|
|
||||||
filterSmallDirs :: [InodeSize] -> [Size]
|
|
||||||
filterSmallDirs ((DirS s):rest) = if (s<100000) then s:(filterSmallDirs rest) else filterSmallDirs rest
|
|
||||||
filterSmallDirs ((FileS s):rest) = filterSmallDirs rest
|
|
||||||
filterSmallDirs [] = []
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
main = do
|
|
||||||
content <- readFile "seven-input.txt"
|
|
||||||
let statements = map parseEither $ drop 1 $ lines content
|
|
||||||
let a = foldl foldFunction initZipper statements
|
|
||||||
print $sum$ filterSmallDirs $ flattenToSmallDirs $ fst $ fsUpToRoot a
|
|
66
stack.yaml
Normal file
66
stack.yaml
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# This file was automatically generated by 'stack init'
|
||||||
|
#
|
||||||
|
# Some commonly used options have been documented as comments in this file.
|
||||||
|
# For advanced use and comprehensive documentation of the format, please see:
|
||||||
|
# https://docs.haskellstack.org/en/stable/yaml_configuration/
|
||||||
|
|
||||||
|
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
|
||||||
|
# A snapshot resolver dictates the compiler version and the set of packages
|
||||||
|
# to be used for project dependencies. For example:
|
||||||
|
#
|
||||||
|
# resolver: lts-3.5
|
||||||
|
# resolver: nightly-2015-09-21
|
||||||
|
# resolver: ghc-7.10.2
|
||||||
|
#
|
||||||
|
# The location of a snapshot can be provided as a file or url. Stack assumes
|
||||||
|
# a snapshot provided as a file might change, whereas a url resource does not.
|
||||||
|
#
|
||||||
|
# resolver: ./custom-snapshot.yaml
|
||||||
|
# resolver: https://example.com/snapshots/2018-01-01.yaml
|
||||||
|
resolver: ghc-9.4.2
|
||||||
|
|
||||||
|
# User packages to be built.
|
||||||
|
# Various formats can be used as shown in the example below.
|
||||||
|
#
|
||||||
|
# packages:
|
||||||
|
# - some-directory
|
||||||
|
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
|
||||||
|
# subdirs:
|
||||||
|
# - auto-update
|
||||||
|
# - wai
|
||||||
|
packages:
|
||||||
|
- .
|
||||||
|
# Dependency packages to be pulled from upstream that are not in the resolver.
|
||||||
|
# These entries can reference officially published versions as well as
|
||||||
|
# forks / in-progress versions pinned to a git hash. For example:
|
||||||
|
#
|
||||||
|
# extra-deps:
|
||||||
|
# - acme-missiles-0.3
|
||||||
|
# - git: https://github.com/commercialhaskell/stack.git
|
||||||
|
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||||
|
#
|
||||||
|
# extra-deps: []
|
||||||
|
|
||||||
|
# Override default flag values for local packages and extra-deps
|
||||||
|
# flags: {}
|
||||||
|
|
||||||
|
# Extra package databases containing global packages
|
||||||
|
# extra-package-dbs: []
|
||||||
|
|
||||||
|
# Control whether we use the GHC we find on the path
|
||||||
|
# system-ghc: true
|
||||||
|
#
|
||||||
|
# Require a specific version of stack, using version ranges
|
||||||
|
# require-stack-version: -any # Default
|
||||||
|
# require-stack-version: ">=2.7"
|
||||||
|
#
|
||||||
|
# Override the architecture used by stack, especially useful on Windows
|
||||||
|
# arch: i386
|
||||||
|
# arch: x86_64
|
||||||
|
#
|
||||||
|
# Extra directories used by stack for building
|
||||||
|
# extra-include-dirs: [/path/to/dir]
|
||||||
|
# extra-lib-dirs: [/path/to/dir]
|
||||||
|
#
|
||||||
|
# Allow a newer minor version of GHC than the snapshot specifies
|
||||||
|
# compiler-check: newer-minor
|
7
stack.yaml.lock
Normal file
7
stack.yaml.lock
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file was autogenerated by Stack.
|
||||||
|
# You should not edit this file by hand.
|
||||||
|
# For more information, please see the documentation at:
|
||||||
|
# https://docs.haskellstack.org/en/stable/lock_files
|
||||||
|
|
||||||
|
packages: []
|
||||||
|
snapshots: []
|
300
three-input.txt
Normal file
300
three-input.txt
Normal file
|
@ -0,0 +1,300 @@
|
||||||
|
gtZDjBcmpcDgpZcmmbgtdtqmCGVCGGsvhCFCCqvmCMMM
|
||||||
|
JrhfzfLTNfJhPnhQnfzHfCFFQFSGvMFCGQFsQSMSVs
|
||||||
|
TllTRrfNNlfzwhtZBZgtRDBp
|
||||||
|
vMdwjZdjwjvjdTZZvCcQMGnQMQcbcgLLCL
|
||||||
|
rsVhfmssPWzDVGCLJSbCgPLSQG
|
||||||
|
lfWNDHDgfszFRTFtwwNjdv
|
||||||
|
GLPqVqdVGCLCdczjMjzMfzld
|
||||||
|
JnWQvJDmvWBtlMzhrzfHQgcz
|
||||||
|
tDtJDDDDtWRRmBwJwWtpPRsGCGScLPGSqspNCS
|
||||||
|
ChVzZzfNDzNJmBQfjjJfmH
|
||||||
|
MrTMPMncGMJvPPvPWTbrMWvgmBgQwgdpwmdpdpjwpHQcdw
|
||||||
|
SPvvvbqrFvMvZzJzsFVzVJNV
|
||||||
|
mvBbvMFqbMMVVmtCBHpDdDPTDspdNWPDVP
|
||||||
|
zjSfftcQtwtSfQSpNDppsNsjPNdRPP
|
||||||
|
fgfStJShrgvvCLLv
|
||||||
|
GmFnNNwbFFbhQQGQnGwwwfBgnMMqVDBZVVBMfMVzVz
|
||||||
|
vWzRRHzTHcgfZDVfBgfH
|
||||||
|
SSTvrvRcPpcvjFGwNGbNpbwQwz
|
||||||
|
FFgbZZFZgFmpstLgmbtzqNrwVPlMPlSWWrMPNp
|
||||||
|
QQhTvjhcvjjvTcTcTfCcSRwwWzwzPMrzWNNWVVhwrwWq
|
||||||
|
GRQBfCRnGGTcDvBfGvffCCjnFZtFFgStJLbLHbFLJZdgmd
|
||||||
|
pppdjcrMMRDJLJdRcwRDrwssqHGGDHsZHHsvBVtvmVHV
|
||||||
|
nlCFWzGzzQFlSlhGWnPzFbSsBZmsssmVVmsBvnHqvNVqqm
|
||||||
|
lFTTTCSQSTrdGJJLJG
|
||||||
|
jpsGMgsmghQwQsMmhlQshjtTNTRTnFqRWnnqRfFnnt
|
||||||
|
SLBCHrcvZHbSvSZrSvSWnfvVNvftVlFRTqnRTq
|
||||||
|
JrzdZbBcHBCrrlHrrSsMgmGpJPDPQmpgQgPG
|
||||||
|
cmcZHgwgMgHSLmtjLfWPNNrWBNfffp
|
||||||
|
JTqGTsClHslVVRVCVGVJGnBrjdnnrdBNvjPNBNBrWvnW
|
||||||
|
VVlQlqTFJlzzlsVGsRCZMthHDbwbFhgcbwHchg
|
||||||
|
qgZjgjjbssqgsjlNqjhTtdrfQdTdWLLnDVfHtHWd
|
||||||
|
zcGMBDDzcLnztfQQQz
|
||||||
|
JSppJcBScMmMFFBRCpRCMmGlggvjhbhlNlglwbslCZjhDZ
|
||||||
|
hvhmqcqwwcTBvvwQnRQnRnTRFzFzQz
|
||||||
|
jWLPPtPsgMtpdLMLWllpgLLQFQhFJjnVrzFrVFhnRzJJrJ
|
||||||
|
WPWffgtSdspdhSMdlSdtfBbHmSvqbNBCCmcBmcvcCH
|
||||||
|
frVcrVcggfSZJfbbJvBd
|
||||||
|
hwWQnwhWQmQmThTSsdvvSMBTBzcb
|
||||||
|
wGnFFCGlQwntGtCtwntwDmFwRgLrHqNRqqcNNgRrHHLggCjp
|
||||||
|
wRSwwHDMsRGHvNBNjTgvjgJD
|
||||||
|
mcLcFCclWQWQpPQWVQcQcvvNJjrNBTrvgJgBvTRvCg
|
||||||
|
VFPbQLchQLSRfbMtdHGH
|
||||||
|
lfVrhnlRRqrJZVDJdHSWCvJCJSbj
|
||||||
|
BFsgcgMNNQgSvbfCff
|
||||||
|
ffNPcMtzqPlnmRGh
|
||||||
|
ZJplFmRJmWRJRWmTJCvtTtnLCtndCqtqnr
|
||||||
|
SQsVPQHBQZNSNSLCfSLrcLcrrr
|
||||||
|
VMjPjbNMDsVHmRllmZpZWmjh
|
||||||
|
LcTLRbJhhdhLJbbclfVvfWQVWFRWFFfq
|
||||||
|
rZNttSNvtgsPPFsqBFPWQF
|
||||||
|
HGCSmHrrwNnHGMLpDhbzzpmJJv
|
||||||
|
VlSWzRtWSJqWdfhdqBdF
|
||||||
|
mTDHsmmmcHpgrCgCrTsMMtqfsFNsZqfdMZMNbd
|
||||||
|
TDcpvrpHCprCpHrmcQvTHgTQzSnLJnPPJlLzwJtRVJwLjJ
|
||||||
|
vZSWZJZJFvhZldZHdvvlphZSNGNnmzwCPNHNHGNrrRHGCPmP
|
||||||
|
bjfgcbjTQTFQBnGRRBCBNwBnCz
|
||||||
|
csqscsbssQLsgQcLgLQLQTQpFdlhdvdZdpZWhJplShWWtq
|
||||||
|
QgQvHnfflfBwQCfwlfglnQQccNcRqGGcjmcsGjddwdzsJc
|
||||||
|
DhZbTLZTDMVTsRzsqsRjszTz
|
||||||
|
FSZVtMLMMWbSgqSvPQlnpH
|
||||||
|
MMPllnnBmfSHvBgCLf
|
||||||
|
whZjGRJdjcNjjhRjCvgCfbSvCZLHfpZs
|
||||||
|
RRWGWwNRWwhwclmrgFmngFPMWm
|
||||||
|
VVHQGDGDGsdRrmZBQZRCVHZCNcSTTPMwwvTTwSSNqBqvgMvN
|
||||||
|
nfhdLfjFnJpblLbJjWhtnjWPScNnwSTPTPqTvgngNNvSvS
|
||||||
|
fpWljtpLjflfLfzlhZGQHZQVddHrrQRDRz
|
||||||
|
VCHCjwCwMSZSqQzhhQqcWZJD
|
||||||
|
GGGrFFgNRNNgmfnTdgmWQpczvPvQPWQJGDpzzc
|
||||||
|
lgTttRTgmfNRntrTTngrCbjCwJCHjLBBHlMVMsbB
|
||||||
|
szgPPlCblggVszhLmzvcvNrqpjNqmrqqpGvG
|
||||||
|
wBQDtBfQDtFvLjjctLqTMr
|
||||||
|
ZFWWdDLQFwSfDSBSQQBWnnnQVdbhgRVbsHzsshbClzzCVggb
|
||||||
|
VpVsHVcqcMVMMNHpsspstbMqzBztJZTBBfJfzTvZfvWJWSTv
|
||||||
|
mDDQgCQQQHdrwgSvZSmJJZvWfJJf
|
||||||
|
drCjggDlPdgrlbjNcnhcHsbpsj
|
||||||
|
cNNDRRpDcNcTpppsqHLQGLfRLvHzLH
|
||||||
|
lFntJjtbFFlsmsjvnGqHWLfhfqzzQh
|
||||||
|
sgPbjBJtPgbPJblblJgbgbwdBTwDCwpwrdZZVcCcDppc
|
||||||
|
GGclMjLnnjCMchcChLMLcnnzRFJDZJSRSzzzzDSShszPRS
|
||||||
|
VHgFQgwVwfNNpQVfHzQsPPPJDbmZbJDJbS
|
||||||
|
HfNVWdHVvgHgVWVNppNWVHwTlvBFcClBCjcTLTlBnnLrTL
|
||||||
|
GTLdlJhffQwDRvWLrp
|
||||||
|
HVZVNjjsPqzNjNNmNgDWMrRQpWvWRHrDHBWp
|
||||||
|
VCqVzjPjCpVqCVPCsbctcnblcGlTbGnlbFJf
|
||||||
|
flHdfdBNdZcflBMjqMjBNfZQhvJbGvqvsshJQsJCJDWvvD
|
||||||
|
gFTzRRpzRTwbgbLmtCvsJhWsChrWCrtWCC
|
||||||
|
VzzzFbVRLPznmRBffPNBHNMdlZfl
|
||||||
|
FFFMwCqJFFmrRwgnbLrL
|
||||||
|
GpjGpQHQpfjdjDRnLrbrRQmJzzgg
|
||||||
|
BphfhDcNcHNvPBvSqJMWJS
|
||||||
|
NndbWpDBNbjvWLZqWsWQ
|
||||||
|
JPFFTSPfgcMgftQQGjvTmsGqzssG
|
||||||
|
gPgcfcVFgcHqSqVhbBCHlpbbpDlhDD
|
||||||
|
FSdfWFTTBnjsDCjsmrrT
|
||||||
|
pQzLRVLppLGcQjqbmVDJsChCvCbVsm
|
||||||
|
qHLRGqqZzGjLqBNMFdnHlNlBFN
|
||||||
|
DjqbfBTchDjqqCjjCTWNTbdzSVzGZQGBwZnQnVwpSSnQ
|
||||||
|
ssJlPrtvMsRLrrJQGNZJSpZpGzSG
|
||||||
|
rlFssHsvPRPMvFmtHvtqjhTgjbqhWqNmNqgDNh
|
||||||
|
vcpnRqwwLLbvvcGpDQWDFSCgMrWWQWRR
|
||||||
|
gtNfBfllrFlHrlrl
|
||||||
|
ZPzftBmsNBNBPJBZPmZPNtmPdGLsqbwqpqcndVLLGpVGvqgV
|
||||||
|
vRBfQqqBQPfbrFvPBvPbhLDVDVDQZVVtZtlWLLLt
|
||||||
|
jcJmFFwnhJVZLWVl
|
||||||
|
sHTcmNNHzncmcjmdsBCrBCPCrBBqCFrqzb
|
||||||
|
bbZRnGmNnBGGMNRTgCmWWGGSrvSvFHvzFvFQDF
|
||||||
|
LjwphpdPdLpLJVqfJrQzDzfrvQHSvDcQrQ
|
||||||
|
DJphdwDsnmbZsTZM
|
||||||
|
rdNrZNBSzSztnNzWCcNpHlMwlwHWlM
|
||||||
|
QqLGLJvLjtvQWhgHgchHwHJw
|
||||||
|
GtjTGtDRqvfLRGnrzsmZmfrVFBrV
|
||||||
|
TdMhZrTTNvwphcLL
|
||||||
|
WnnmffmDWnWPsPCJNpNcpNVNQp
|
||||||
|
fsjbWfFFfnmmDsFDnnflSSdczlMdTHTzTTRRBdtT
|
||||||
|
cMcPcMcwgWJMjWWhFWCCQCmqCFdh
|
||||||
|
bSLVLblnNnLbVfnsbSbCChSQdChptpdqZrmCmZ
|
||||||
|
DLGNfnGVDNDHbfzjRcRgqHMRBJPc
|
||||||
|
HVFVlVHjzjjlCJjHjCjnvDrggrgLdqzddMqrzz
|
||||||
|
SSfBTmtNdLqngvrm
|
||||||
|
TwnNfPWWpBSBNtTHZCGlPHCQJHZHPV
|
||||||
|
prvccpFQpMcQBwsvssshdwSTPD
|
||||||
|
qbGHVbNJGqwdPgDrTsDJ
|
||||||
|
fGbGqqlGGHflqLlzZBBrRcrtrZlp
|
||||||
|
fCSPhltMBmPmbdgd
|
||||||
|
DjvJJscvTsHHDbWzBWsWbdwgLB
|
||||||
|
VVHDZvTppRcJVFFppvvRJDJqMSGqCtZdthttrnthSZMGCr
|
||||||
|
ZcSrSdrhDjBDDCmZdZmZjhwVHwqVVsMwgswVVwMfhw
|
||||||
|
PNvzTPNbnzcPbGQNJTvqwsWgVgVMMWpQqwgHpp
|
||||||
|
JTPGPTzNttnbRTPlPtNNRlFrFmBcmDljjmBFSCmLZZBr
|
||||||
|
mNvRRCVMtNRdFNtMtBHHprpHgJgJWwpBnprg
|
||||||
|
LZDDlSLlTslDfbcpJJWndwcscnwr
|
||||||
|
qdZZGSDhMVRCGtmC
|
||||||
|
VGFjjgBShGdGzQczcGRG
|
||||||
|
MppqCDfCMwfLDfvNmrtWstRcMPzRMRsRsPQS
|
||||||
|
NwDCffLppbqqrqvTBngSbnBHglZllH
|
||||||
|
vdllJVDzmVDVqvvWvdqJlcWrCsfCsfSSsSJfCSfQQCCbCQ
|
||||||
|
jnTHZPZHMjZhMjTpHgMpgnbNqBstnfrtSSrBSNssCrfN
|
||||||
|
LHLTFLjTMTTTwjHhpHTcwmDcWVDlvRDmvqwWlW
|
||||||
|
rqQsSStdmsdLqlNNPGlGlV
|
||||||
|
FpFpzJNTcHzRHRHlGwFVLFBLFGVvlw
|
||||||
|
WCCjWRNJTJWhQhbhrbnd
|
||||||
|
jsQjfrRTRwzSsRTgNchlnlhqcnlQmQ
|
||||||
|
dFDtdFBDddHLJpVpHHtVbtHFCWlWlGlNlmGggNqgglmcchqb
|
||||||
|
dLDHMVdLtBBDBFVJBFthtJHRTvsMSvsTrTSRvPPjPzSwRP
|
||||||
|
CSPpSrLlrlPrPchLnSlbDbbRttDVhbGRDDJRtD
|
||||||
|
fzfvmzTMmfsFszsHZsHMHVfwtbjBDDGjtRBjQQGGJb
|
||||||
|
HmvmTFmqmTsHqzzzzdTsMMScndccdLppnLCSPcCLrVgr
|
||||||
|
pfMflRnfrnjrpjnFzDpfDMmMLRTLZVTgLsvdZgLLZHSVWZRd
|
||||||
|
tBGNhwPGcNBBWwZddsSTTPgVLPdT
|
||||||
|
JwthtwbbhNBQhwhbBCrzpnprnWnprlzWlClD
|
||||||
|
PPnZZjnFNDjlJJhtMddfTTdD
|
||||||
|
QGLHFWvQJtzfpvCt
|
||||||
|
swqSmmQWLQwFWLwwRcqNNBnnbgPqbPNbglVZ
|
||||||
|
GCLSjjZGZhpvGtBgjJlnJDhhJMVDPnJlJP
|
||||||
|
mNtQQwNzQRHWdJHnPTsddlln
|
||||||
|
zQrfmbtNbcQcrzmrRBZqBcvpjSGLZGLZBB
|
||||||
|
zGNzgsjDssvNbPlWJfJq
|
||||||
|
RLMVSRMLhCLZSMZHDSJWvpcqfbfhvpJqcWPv
|
||||||
|
dMVHLFHLZMLRLLFRHHHVZMgDTntgstGwznzGGnzjDFwG
|
||||||
|
wCLCHLBwzBtQRLHLbNFFfdqdDqVrVfBN
|
||||||
|
JGvljmgGZvMlfDRRnnnZnfND
|
||||||
|
GppRlgJlSllSgjMsmllpTjcCLczWztPWPwwwzWThtcQh
|
||||||
|
WvHbvvWnFHszDRSltcCctCFD
|
||||||
|
gCmJmCCPTPqpgrZtjdRtDRplcSjS
|
||||||
|
rJJrQPPJQmrmrhGTznCfLMMbfvWfbCWQ
|
||||||
|
TqBWtTbFBNNRRtwQpJJvvvZPpTSQ
|
||||||
|
fRMfsMssrGhSmMwSQvvZJm
|
||||||
|
VggcVlsCgHnVFnndbbnR
|
||||||
|
NdrSSWBNPPSWWHPPlwlLZHLZLMhjlLLH
|
||||||
|
pVptMTgVTzLwZTzlbF
|
||||||
|
qsRmRJtsMvMqgqgRvCdcSrWSPcWrDmmdBN
|
||||||
|
nbJnfqWcmCMnSBSHwzWBsHHz
|
||||||
|
dVpdvdppdptppDlvlHcczSgNcgww
|
||||||
|
VGTdTVtGtRLFPTDbcfCmmcCQJQjcrT
|
||||||
|
VTjrjrjTlTjQMdpGrWMSHvSG
|
||||||
|
wnNJbDmttnwnhNwcJmNGdvWvM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
|
||||||
|
jblbdjZFDMbGllqTGTtVlq
|
||||||
|
gmdMgZMbjpZDcrrDgdmszsPLpQfpBPPnNQNLLz
|
||||||
|
HRsPPGMhLPMrnPchPSwStjbSttSvtHSqQw
|
||||||
|
dfsCfpCJVJCvdFBFwStwjj
|
||||||
|
gTNWmWfTNVZVJzZWpWJgTpfhnDrMnDclgDlDrDRnRcMLDs
|
||||||
|
ZQZQJMqdwmZvqfPmwRjpBBjHjnshnjtt
|
||||||
|
zcTPTLDTFWLGTrTSWPcDSSHjRlhRsDhHslslssBRljjj
|
||||||
|
TrNFLbTWrGNZvmvVQPQV
|
||||||
|
htfLgmtSLcTWNLcT
|
||||||
|
slbHlBBGbqRsblBHvdNJJcjFFNBTVWWWcn
|
||||||
|
bbQsHMMblHrMsGRqvQhwCTQCwtQCzSpfmS
|
||||||
|
zmqdphmFmSpTzhdqhFmwjjGbtcvDbcGGjllGQjSP
|
||||||
|
HJFrMCsVLrHRRMCNrVMVnctvstlGcQlPtGGjQtGlvP
|
||||||
|
RFLHLVWrNgVJzwzwfgffwdfp
|
||||||
|
vdMjSmMMpmMWhRpndRmZnhvHqLpGHcJGGGDLHHLGcfcLfc
|
||||||
|
lPBwwrsCgLFggcqqLW
|
||||||
|
TWszsWNBTNdmSRvjbZZT
|
||||||
|
zFlBGpzzzLLNjBwPcwwmcNPfWNQn
|
||||||
|
VHSHRJTJDSVVnmcVVPpWmpnf
|
||||||
|
DMZHHrDHHrJrrZrShZsHGbMBbFgGjGCgjpFlBzzb
|
||||||
|
FVMpsvTqvqMssVsWZSrqWFvwlGDGwQzwfwQQNLzDlwlZwf
|
||||||
|
hPbgBHhJJcJPwCwDpNllCCHC
|
||||||
|
pnjbBmjgbgmqtSmsTtsF
|
||||||
|
DHZHmfTmCfjDZHMZmzffHHnQwwTBdQwbSdBGBQwhBQTQww
|
||||||
|
cqstRFWNtLrNFwdVShlBSlhBRl
|
||||||
|
StJWpLptNWLtJcpqPrFHDjZzzvnDDHPCZjPvvz
|
||||||
|
hzffhGVGGhzRqTBLTqHL
|
||||||
|
sFFFsMQlwJMsmrBFSNHTHNqrTS
|
||||||
|
pbdsJMdJMJbwbmJJtbTtgnffGgVVChvD
|
||||||
|
FvJnFnCpQTddSSmFdFpPPsVhppDjBzjDVhDV
|
||||||
|
RgZMZbsgzlDPlhjb
|
||||||
|
cHHHRgRZgfHHZGZfHZcLLHrrCrmJCmddrsvdJsmvFFQG
|
||||||
|
dpJDdZwLnvdvFmFMmHjslMLH
|
||||||
|
CGCztgPhWCWhzzzNNPGfrrWfmbbsmmHjFHDMsbHMsjFPjbHm
|
||||||
|
rNQDGzzhCCfNrzrDzChTcZZvQcTRJpTwdvQpVc
|
||||||
|
VpvNGhGHGNhHbPsbVbvfFtLCzSCFSBsCFSFCLB
|
||||||
|
MlqJwTnrRRrRnMlQMHfHzHzWFWtmTzLWFC
|
||||||
|
ljZDDHqqjqRbpNhjNNgcgc
|
||||||
|
qrQtDzcQzbrcfdbqrQrthtscSsvpvnsSHpTpLpspmsSs
|
||||||
|
CVwNNVRNBSHsLSFBTv
|
||||||
|
CVVVNZjlVlGwlGlljNlWJVrrfqbPQQqHqJhhftbfDJqf
|
||||||
|
lpmrPDPDjPlmWrVzPztZwFjtFbBnRtZbbcRL
|
||||||
|
dnqJCCgQdNqbqRbRbBLt
|
||||||
|
QGhGddGCTdMHNTGgshgJhzvSmWWPSsnprpPzWzsWlr
|
||||||
|
hCJHTdJJNvTdSSNssjvfwgntwDgtgwDGCtZwtRRB
|
||||||
|
mbllFmFMFbMVWWLpbpZwwBZTZnnVwnTggtDB
|
||||||
|
MmzLQpFPTmPzHvfJNNzhNs
|
||||||
|
dzgBwzlgrrBrVLLlwLBgBlgRScDMMDDswMsHZRGDsZGZmM
|
||||||
|
HPfPbjCFJjCvfnnsjsDDcccmZsRSMc
|
||||||
|
hCvHfWPPnvJhPWpqNNhqLqzLqLLd
|
22
three.hs
22
three.hs
|
@ -1,22 +0,0 @@
|
||||||
import Data.Char
|
|
||||||
|
|
||||||
splitlist :: [a] -> ([a],[a])
|
|
||||||
splitlist list = (take n list,drop n list)
|
|
||||||
where n = (length list) `div` 2
|
|
||||||
|
|
||||||
inBoth :: (Eq a) => ([a],[a]) -> [a]
|
|
||||||
inBoth (first,second) = do
|
|
||||||
inFirst <- first
|
|
||||||
if (inFirst `elem` second) then return inFirst else []
|
|
||||||
|
|
||||||
toPriority :: Char -> Int
|
|
||||||
toPriority char = ordNum - (substract ordNum)
|
|
||||||
where
|
|
||||||
ordNum = (ord char)
|
|
||||||
substract n
|
|
||||||
| n < 97 = 38
|
|
||||||
| otherwise = 96
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "three-input.txt"
|
|
||||||
print $sum $ map (toPriority . head . inBoth . splitlist ) $ lines input
|
|
22
three2.hs
22
three2.hs
|
@ -1,22 +0,0 @@
|
||||||
import Data.Char
|
|
||||||
import Data.List.Split
|
|
||||||
|
|
||||||
|
|
||||||
inAll :: [String] -> [Char]
|
|
||||||
inAll [first,second,third] = do
|
|
||||||
eachChar <- first
|
|
||||||
if (eachChar `elem` second && eachChar `elem` third) then return eachChar else []
|
|
||||||
|
|
||||||
|
|
||||||
toPriority :: Char -> Int
|
|
||||||
toPriority char = ordNum - (substract ordNum)
|
|
||||||
where
|
|
||||||
ordNum = (ord char)
|
|
||||||
substract n
|
|
||||||
| n < 97 = 38
|
|
||||||
| otherwise = 96
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "three-input.txt"
|
|
||||||
print $sum $ map (toPriority . head . inAll ) $ chunksOf 3 $ lines input
|
|
||||||
--print $map ( inAll ) $ chunksOf 3 $ lines input
|
|
41
two.hs
41
two.hs
|
@ -1,41 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
data Rock
|
|
||||||
data Paper
|
|
||||||
data Scissors
|
|
||||||
|
|
||||||
type X = Rock
|
|
||||||
type Y = Paper
|
|
||||||
type Z = Scissors
|
|
||||||
|
|
||||||
type A = Rock
|
|
||||||
type B = Paper
|
|
||||||
type C = Scissors
|
|
||||||
|
|
||||||
data Action = X | Y | Z deriving (Show,Read, Eq)
|
|
||||||
data Enemy = A | B | C deriving (Show,Read, Eq)
|
|
||||||
|
|
||||||
data Game = Game Enemy Action deriving (Show,Read)
|
|
||||||
|
|
||||||
selectedScore :: Action -> Int
|
|
||||||
selectedScore X = 1
|
|
||||||
selectedScore Y = 2
|
|
||||||
selectedScore Z = 3
|
|
||||||
|
|
||||||
resultScore :: Game -> Int
|
|
||||||
resultScore (Game A X) = 3
|
|
||||||
resultScore (Game A Y) = 6
|
|
||||||
resultScore (Game A Z) = 0
|
|
||||||
resultScore (Game B X) = 0
|
|
||||||
resultScore (Game B Y) = 3
|
|
||||||
resultScore (Game B Z) = 6
|
|
||||||
resultScore (Game C X) = 6
|
|
||||||
resultScore (Game C Y) = 0
|
|
||||||
resultScore (Game C Z) = 3
|
|
||||||
|
|
||||||
gameScore :: Game -> Int
|
|
||||||
gameScore (Game enemy action) = (resultScore (Game enemy action)) + selectedScore action
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "input.txt"
|
|
||||||
putStrLn $ show$ sum $ map (gameScore . read . ("Game "<> )) $ lines input
|
|
44
two2.hs
44
two2.hs
|
@ -1,44 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
data Rock
|
|
||||||
data Paper
|
|
||||||
data Scissors
|
|
||||||
|
|
||||||
type X = Rock
|
|
||||||
type Y = Paper
|
|
||||||
type Z = Scissors
|
|
||||||
|
|
||||||
type A = Rock
|
|
||||||
type B = Paper
|
|
||||||
type C = Scissors
|
|
||||||
|
|
||||||
data Action = X | Y | Z deriving (Show,Read, Eq)
|
|
||||||
data Enemy = A | B | C deriving (Show,Read, Eq)
|
|
||||||
|
|
||||||
data Game = Game Enemy Action deriving (Show,Read)
|
|
||||||
|
|
||||||
selectedScore :: Action -> Int
|
|
||||||
--selectedScore X = 1
|
|
||||||
--selectedScore Y = 2
|
|
||||||
--selectedScore Z = 3
|
|
||||||
selectedScore X = 0
|
|
||||||
selectedScore Y = 3
|
|
||||||
selectedScore Z = 6
|
|
||||||
|
|
||||||
resultScore :: Game -> Int
|
|
||||||
resultScore (Game A X) = 3
|
|
||||||
resultScore (Game A Y) = 1
|
|
||||||
resultScore (Game A Z) = 2
|
|
||||||
resultScore (Game B X) = 1
|
|
||||||
resultScore (Game B Y) = 2
|
|
||||||
resultScore (Game B Z) = 3
|
|
||||||
resultScore (Game C X) = 2
|
|
||||||
resultScore (Game C Y) = 3
|
|
||||||
resultScore (Game C Z) = 1
|
|
||||||
|
|
||||||
gameScore :: Game -> Int
|
|
||||||
gameScore (Game enemy action) = (resultScore (Game enemy action)) + selectedScore action
|
|
||||||
|
|
||||||
main = do
|
|
||||||
input <- readFile "input.txt"
|
|
||||||
putStrLn $ show$ sum $ map (gameScore . read . ("Game "<> )) $ lines input
|
|
Loading…
Reference in a new issue