4
Day1/1.hs
Normal file
4
Day1/1.hs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import Lib (calories)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = print . maximum . calories =<< readFile "input"
|
6
Day1/2.hs
Normal file
6
Day1/2.hs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import Data.List (sortOn)
|
||||||
|
import Data.Ord (Down (Down))
|
||||||
|
import Lib (calories)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = print . sum . take 3 . sortOn Down . calories =<< readFile "input"
|
16
Day1/Lib.hs
Normal file
16
Day1/Lib.hs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module Lib (calories) where
|
||||||
|
|
||||||
|
calories :: String -> [Integer]
|
||||||
|
calories input =
|
||||||
|
map (sum . map read) $
|
||||||
|
filter (not . null) $ split "" $ split '\n' input
|
||||||
|
|
||||||
|
split :: Eq a => a -> [a] -> [[a]]
|
||||||
|
split del =
|
||||||
|
foldr
|
||||||
|
( \c (x : xs) ->
|
||||||
|
if c == del
|
||||||
|
then [] : x : xs
|
||||||
|
else (c : x) : xs
|
||||||
|
)
|
||||||
|
[[]]
|
2237
Day1/input
Normal file
2237
Day1/input
Normal file
File diff suppressed because it is too large
Load Diff
43
flake.lock
generated
Normal file
43
flake.lock
generated
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1669926181,
|
||||||
|
"narHash": "sha256-9UvqeOzNeVj1k3SmsRThcArP/IDos4OA4V38utDx7m8=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "60d042d7e30f35b598d244e2009d4bfc15052e04",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "release-22.05",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"utils": "utils"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1667395993,
|
||||||
|
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
31
flake.nix
Normal file
31
flake.nix
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
description = "AoC 2022 in Haskell";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = github:nixos/nixpkgs/release-22.05;
|
||||||
|
utils.url = github:numtide/flake-utils;
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, utils }:
|
||||||
|
utils.lib.eachDefaultSystem
|
||||||
|
(system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells = with pkgs; rec {
|
||||||
|
default = mkShell {
|
||||||
|
buildInputs = [ ghc ];
|
||||||
|
};
|
||||||
|
withLsp = mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
ghc
|
||||||
|
haskell-language-server
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user